Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for ld-version tests |
fcd06cfe | 2 | # Copyright 1997, 1998, 1999, 2001, 2003 Free Software Foundation, Inc. |
252b5132 RH |
3 | # |
4 | # This file is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | # | |
18 | # Written by Eric Youngdale (eric@andante.jic.com) | |
19 | ||
20 | # | |
21 | ||
22 | # This test can only be run if ld generates native executables. | |
23 | if ![isnative] then {return} | |
24 | ||
25 | # This test can only be run on a couple of ELF platforms. | |
26 | # Square bracket expressions seem to confuse istarget. | |
27 | # This is similar to the test that is used in ld-shared, BTW. | |
19c7c582 AM |
28 | if { ![istarget hppa*64*-*-hpux*] \ |
29 | && ![istarget hppa*-*-linux*] \ | |
30 | && ![istarget i?86-*-sysv4*] \ | |
252b5132 RH |
31 | && ![istarget i?86-*-unixware] \ |
32 | && ![istarget i?86-*-elf*] \ | |
33 | && ![istarget i?86-*-linux*] \ | |
ad995491 L |
34 | && ![istarget ia64-*-elf*] \ |
35 | && ![istarget ia64-*-linux*] \ | |
252b5132 RH |
36 | && ![istarget m68k-*-linux*] \ |
37 | && ![istarget mips*-*-irix5*] \ | |
38 | && ![istarget powerpc-*-elf*] \ | |
39 | && ![istarget powerpc-*-linux*] \ | |
40 | && ![istarget powerpc-*-sysv4*] \ | |
41 | && ![istarget sparc*-*-elf] \ | |
b33b6e45 ILT |
42 | && ![istarget sparc*-*-solaris2*] \ |
43 | && ![istarget sparc*-*-linux*] \ | |
4f38fc1c | 44 | && ![istarget arm*-*-linux*] \ |
66517a2f | 45 | && ![istarget mips*-*-linux*] \ |
9147e853 JJ |
46 | && ![istarget alpha*-*-linux*] \ |
47 | && ![istarget s390*-*-linux*] \ | |
48 | && ![istarget x86_64-*-linux*] } { | |
252b5132 RH |
49 | return |
50 | } | |
51 | ||
c709b096 AM |
52 | if { [istarget i?86-*-linux*aout*] \ |
53 | || [istarget i?86-*-linux*oldld*] \ | |
54 | || [istarget m68k-*-linux*aout*] } { | |
252b5132 RH |
55 | return |
56 | } | |
57 | ||
58 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
59 | return | |
60 | } | |
61 | ||
62 | set diff diff | |
63 | set tmpdir tmpdir | |
64 | set VOBJDUMP_FLAGS --private-headers | |
65 | set DOBJDUMP_FLAGS --dynamic-syms | |
66 | set SOBJDUMP_FLAGS --syms | |
31941635 | 67 | set shared "--shared --no-undefined-version" |
252b5132 RH |
68 | set script --version-script |
69 | ||
f006af20 L |
70 | if [istarget mips*-*-*] { |
71 | set picflag "" | |
72 | } else { | |
73 | # Unfortunately, the gcc argument is -fpic and the cc argument is | |
74 | # -KPIC. We have to try both. | |
75 | set picflag "-fpic" | |
76 | send_log "$CC $picflag\n" | |
77 | verbose "$CC $picflag" | |
78 | catch "exec $CC $picflag" exec_output | |
79 | send_log "$exec_output\n" | |
80 | verbose "--" "$exec_output" | |
81 | if { [string match "*illegal option*" $exec_output] \ | |
82 | || [string match "*option ignored*" $exec_output] \ | |
83 | || [string match "*unrecognized option*" $exec_output] \ | |
84 | || [string match "*passed to ld*" $exec_output] } { | |
85 | if [istarget *-*-sunos4*] { | |
86 | set picflag "-pic" | |
87 | } else { | |
88 | set picflag "-KPIC" | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
252b5132 RH |
93 | proc test_ar { test lib object expect } { |
94 | global ar | |
95 | global nm | |
96 | global tmpdir | |
97 | global srcdir | |
98 | global subdir | |
99 | global diff | |
100 | ||
101 | verbose -log "$ar -cr $tmpdir/$lib $tmpdir/$object" | |
102 | catch "exec $ar -cr $tmpdir/$lib $tmpdir/$object" exec_output | |
103 | set exec_output [prune_warnings $exec_output] | |
104 | if ![string match "" $exec_output] { | |
105 | verbose -log "$exec_output" | |
106 | unresolved "$test" | |
107 | return | |
108 | } | |
109 | ||
110 | verbose -log "$nm --print-armap $tmpdir/$lib | grep \" in \" | egrep \"VERS\\|bar\\|foo\" | sort > $tmpdir/nm.out" | |
111 | ||
112 | catch "exec $nm --print-armap $tmpdir/$lib | grep \\\ in\\\ | egrep VERS\\\|bar\\\|foo | sort > $tmpdir/nm.out" exec_output | |
113 | if [string match "" $exec_output] then { | |
3b0f0b37 | 114 | catch "exec $diff $tmpdir/nm.out $srcdir/$subdir/$expect" exec_output |
252b5132 RH |
115 | set exec_output [prune_warnings $exec_output] |
116 | if [string match "" $exec_output] then { | |
117 | pass $test | |
118 | return | |
119 | } else { | |
120 | verbose -log "$exec_output" | |
121 | fail "$test" | |
122 | return | |
123 | } | |
124 | } else { | |
125 | verbose -log "$exec_output" | |
126 | fail "$test" | |
127 | } | |
128 | } | |
129 | ||
130 | # | |
131 | # objdump_emptysymstuff | |
132 | # Check non-dynamic symbols and make sure there are none with '@'. | |
133 | # | |
134 | proc objdump_emptysymstuff { objdump object } { | |
135 | global SOBJDUMP_FLAGS | |
136 | global version_output | |
137 | global diff | |
138 | ||
139 | if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" } | |
140 | ||
141 | verbose -log "$objdump $SOBJDUMP_FLAGS $object | sed -n /\@/p" | |
142 | ||
143 | catch "exec $objdump $SOBJDUMP_FLAGS $object | sed -n /\@/p" exec_output | |
144 | set exec_output [prune_warnings $exec_output] | |
145 | if [string match "" $exec_output] then { | |
146 | # We shouldn't get anything here. | |
147 | return 1 | |
148 | } else { | |
149 | # it is not normal to come here - we have no output to compare. | |
150 | verbose -log "$exec_output" | |
151 | verbose -log "objdump_emptysymstuff: did not expect any output from objdump" | |
152 | return 0 | |
153 | } | |
154 | ||
155 | } | |
156 | ||
157 | # | |
158 | # objdump_emptydynsymstuff | |
159 | # Check dynamic symbols and make sure there are none with '@'. | |
160 | # | |
161 | proc objdump_emptydynsymstuff { objdump object } { | |
162 | global DOBJDUMP_FLAGS | |
163 | global version_output | |
164 | global diff | |
165 | ||
166 | if ![info exists VOBJDUMP_FLAGS] { set VOBJDUMP_FLAGS "" } | |
167 | ||
168 | verbose -log "$objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p" | |
169 | ||
170 | catch "exec $objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p" exec_output | |
171 | set exec_output [prune_warnings $exec_output] | |
172 | if [string match "" $exec_output] then { | |
173 | # We shouldn't get anything here. | |
174 | return 1 | |
175 | } else { if [string match "*objdump: *: not a dynamic object" $exec_output] then { | |
176 | return 1 | |
177 | } else { | |
178 | # it is not normal to come here - we have no output to compare. | |
179 | verbose -log "$exec_output" | |
180 | verbose -log "objdump_emptydynsymstuff: did not expect any output from objdump" | |
181 | return 0 | |
182 | } } | |
183 | } | |
184 | ||
185 | # | |
186 | # objdump_emptyverstuff | |
187 | # Make sure there is no version information | |
188 | # | |
189 | proc objdump_emptyverstuff { objdump object } { | |
190 | global VOBJDUMP_FLAGS | |
191 | global version_output | |
192 | global diff | |
193 | global tmpdir | |
194 | ||
195 | if {[which $objdump] == 0} then { | |
196 | perror "$objdump does not exist" | |
197 | return 0 | |
198 | } | |
199 | ||
200 | if ![info exists VOBJDUMP_FLAGS] { set VOBJDUMP_FLAGS "" } | |
201 | ||
202 | verbose -log "$objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out" | |
203 | ||
204 | catch "exec $objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p" exec_output | |
205 | set exec_output [prune_warnings $exec_output] | |
206 | if [string match "" $exec_output] then { | |
207 | # it is normal to fail here - we have no output to compare. | |
208 | return 1 | |
209 | } else { if { [string match "*libc*" $exec_output] } then { | |
210 | # this probably means that there is version information in libc, so we | |
211 | # can't really perform this test. | |
212 | return 1 | |
213 | } else { | |
214 | verbose -log "$exec_output" | |
215 | verbose -log "objdump_emptyverstuff: did not expect any output from objdump" | |
216 | return 0 | |
217 | } } | |
218 | ||
219 | } | |
220 | ||
221 | # | |
222 | # objdump_symstuff | |
223 | # Dump non-dynamic symbol stuff and make sure that it is sane. | |
224 | # | |
225 | proc objdump_symstuff { objdump object expectfile } { | |
226 | global SOBJDUMP_FLAGS | |
227 | global version_output | |
228 | global diff | |
229 | global tmpdir | |
230 | ||
231 | if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" } | |
232 | ||
233 | verbose -log "$objdump $SOBJDUMP_FLAGS $object | grep \@ | sort > $tmpdir/objdump.out" | |
234 | ||
235 | catch "exec $objdump $SOBJDUMP_FLAGS $object | grep \@ | sort > $tmpdir/objdump.out" exec_output | |
236 | set exec_output [prune_warnings $exec_output] | |
237 | if [string match "" $exec_output] then { | |
238 | ||
239 | # Now do a line-by-line comparison to effectively diff the darned things | |
240 | # The stuff coming from the expectfile is actually a regex, so we can | |
241 | # skip over the actual addresses and so forth. This is currently very | |
242 | # simpleminded - it expects a one-to-one correspondence in terms of line | |
243 | # numbers. | |
244 | ||
245 | if [file exists $expectfile] then { | |
246 | set file_a [open $expectfile r] | |
247 | } else { | |
248 | perror "$expectfile doesn't exist" | |
249 | return 0 | |
250 | } | |
251 | ||
252 | if [file exists $tmpdir/objdump.out] then { | |
253 | set file_b [open $tmpdir/objdump.out r] | |
254 | } else { | |
255 | perror "$tmpdir/objdump.out doesn't exist" | |
256 | return 0 | |
257 | } | |
258 | ||
259 | verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2 | |
260 | ||
261 | set eof -1 | |
262 | set differences 0 | |
263 | ||
264 | while { [gets $file_a line] != $eof } { | |
265 | if [regexp "^#.*$" $line] then { | |
266 | continue | |
267 | } else { | |
268 | lappend list_a $line | |
269 | } | |
270 | } | |
271 | close $file_a | |
272 | ||
273 | while { [gets $file_b line] != $eof } { | |
274 | if [regexp "^#.*$" $line] then { | |
275 | continue | |
276 | } else { | |
277 | lappend list_b $line | |
278 | } | |
279 | } | |
280 | close $file_b | |
281 | ||
282 | for { set i 0 } { $i < [llength $list_a] } { incr i } { | |
283 | set line_a [lindex $list_a $i] | |
284 | set line_b [lindex $list_b $i] | |
285 | ||
286 | ||
287 | verbose "\t$expectfile: $i: $line_a" 3 | |
288 | verbose "\t/tmp/objdump.out: $i: $line_b" 3 | |
289 | if [regexp $line_a $line_b] then { | |
290 | continue | |
291 | } else { | |
292 | verbose -log "\t$expectfile: $i: $line_a" | |
293 | verbose -log "\t$tmpdir/objdump.out: $i: $line_b" | |
294 | ||
295 | return 0 | |
296 | } | |
297 | } | |
298 | ||
299 | if { [llength $list_a] != [llength $list_b] } { | |
300 | verbose -log "Line count" | |
301 | return 0 | |
302 | } | |
303 | ||
304 | if $differences<1 then { | |
305 | return 1 | |
306 | } | |
307 | ||
308 | return 0 | |
309 | } else { | |
310 | verbose -log "$exec_output" | |
311 | return 0 | |
312 | } | |
313 | ||
314 | } | |
315 | ||
316 | # | |
317 | # objdump_dymsymstuff | |
318 | # Dump dynamic symbol stuff and make sure that it is sane. | |
319 | # | |
320 | proc objdump_dynsymstuff { objdump object expectfile } { | |
321 | global DOBJDUMP_FLAGS | |
322 | global version_output | |
323 | global diff | |
324 | global tmpdir | |
325 | ||
326 | if ![info exists DOBJDUMP_FLAGS] { set DOBJDUMP_FLAGS "" } | |
327 | ||
328 | verbose -log "$objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p | sort | uniq > $tmpdir/objdump.out" | |
329 | ||
330 | catch "exec $objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p | sort | uniq > $tmpdir/objdump.out" exec_output | |
331 | set exec_output [prune_warnings $exec_output] | |
332 | if [string match "" $exec_output] then { | |
333 | ||
334 | # Now do a line-by-line comparison to effectively diff the darned things | |
335 | # The stuff coming from the expectfile is actually a regex, so we can | |
336 | # skip over the actual addresses and so forth. This is currently very | |
337 | # simpleminded - it expects a one-to-one correspondence in terms of line | |
338 | # numbers. | |
339 | ||
340 | if [file exists $expectfile] then { | |
341 | set file_a [open $expectfile r] | |
342 | } else { | |
343 | warning "$expectfile doesn't exist" | |
344 | return 0 | |
345 | } | |
346 | ||
347 | if [file exists $tmpdir/objdump.out] then { | |
348 | set file_b [open $tmpdir/objdump.out r] | |
349 | } else { | |
350 | fail "$tmpdir/objdump.out doesn't exist" | |
351 | return 0 | |
352 | } | |
353 | ||
354 | verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2 | |
355 | ||
356 | set eof -1 | |
357 | set differences 0 | |
358 | ||
359 | while { [gets $file_a line] != $eof } { | |
360 | if [regexp "^#.*$" $line] then { | |
361 | continue | |
362 | } else { | |
363 | lappend list_a $line | |
364 | } | |
365 | } | |
366 | close $file_a | |
367 | ||
368 | while { [gets $file_b line] != $eof } { | |
369 | if [regexp "^#.*$" $line] then { | |
370 | continue | |
371 | } else { | |
372 | lappend list_b $line | |
373 | } | |
374 | } | |
375 | close $file_b | |
376 | ||
365f9131 L |
377 | # Support empty files. |
378 | if { ![info exists list_a] && ![info exists list_b] } then { | |
379 | return 1 | |
380 | } | |
381 | ||
252b5132 RH |
382 | for { set i 0 } { $i < [llength $list_b] } { incr i } { |
383 | set line_b [lindex $list_b $i] | |
384 | ||
385 | # The tests are rigged so that we should never export a symbol with the | |
386 | # word 'hide' in it. Thus we just search for it, and bail if we find it. | |
387 | if [regexp "hide" $line_b] then { | |
388 | verbose -log "\t$tmpdir/objdump.out: $i: $line_b" | |
389 | ||
390 | return 0 | |
391 | } | |
392 | ||
393 | verbose "\t$expectfile: $i: $line_b" 3 | |
394 | ||
395 | # We can't assume that the sort is consistent across | |
396 | # systems, so we must check each regexp. When we find a | |
397 | # regexp, we null it out, so we don't match it twice. | |
398 | for { set j 0 } { $j < [llength $list_a] } { incr j } { | |
399 | set line_a [lindex $list_a $j] | |
400 | ||
401 | if [regexp $line_a $line_b] then { | |
402 | lreplace $list_a $j $j "CAN NOT MATCH" | |
403 | break | |
404 | } | |
405 | } | |
406 | ||
407 | if { $j >= [llength $list_a] } { | |
408 | verbose -log "\t$tmpdir/objdump.out: $i: $line_b" | |
409 | ||
410 | return 0 | |
411 | } | |
412 | } | |
413 | ||
414 | if { [llength $list_a] != [llength $list_b] } { | |
415 | verbose -log "Line count" | |
416 | return 0 | |
417 | } | |
418 | ||
419 | if $differences<1 then { | |
420 | return 1 | |
421 | } | |
422 | ||
423 | return 0 | |
424 | } else { | |
425 | verbose -log "$exec_output" | |
426 | return 0 | |
427 | } | |
428 | ||
429 | } | |
430 | ||
431 | # | |
432 | # objdump_versionstuff | |
433 | # Dump version definitions/references and make sure that it is sane. | |
434 | # | |
435 | proc objdump_versionstuff { objdump object expectfile } { | |
436 | global VOBJDUMP_FLAGS | |
437 | global version_output | |
438 | global diff | |
439 | global tmpdir | |
440 | ||
441 | if {[which $objdump] == 0} then { | |
442 | perror "$objdump does not exist" | |
443 | return 0 | |
444 | } | |
445 | ||
446 | if ![info exists VOBJDUMP_FLAGS] { set VOBJDUMP_FLAGS "" } | |
447 | ||
448 | verbose -log "$objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out" | |
449 | ||
450 | catch "exec $objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out" exec_output | |
451 | set exec_output [prune_warnings $exec_output] | |
452 | if [string match "" $exec_output] then { | |
453 | ||
454 | # It's OK if there are extra lines in the actual output; they | |
455 | # may come from version information in libc. We require that | |
456 | # every line in EXPECTFILE appear in the output in order. | |
457 | ||
458 | set f1 [open $tmpdir/objdump.out r] | |
459 | set f2 [open $expectfile r] | |
460 | gets $f2 l2 | |
461 | while { [gets $f1 l1] != -1 } { | |
462 | if { [string match $l2 $l1] } then { | |
463 | if { [gets $f2 l2] == -1 } then { | |
464 | close $f1 | |
465 | close $f2 | |
466 | return 1 | |
467 | } | |
468 | } | |
469 | } | |
470 | ||
471 | # We reached the end of the output without seeing the line we | |
472 | # expected. This is a test failure. | |
473 | ||
474 | close $f1 | |
475 | close $f2 | |
476 | ||
365f9131 L |
477 | # Support empty expected file. |
478 | if [string match "" $l2] then { | |
479 | return 1 | |
480 | } | |
481 | ||
252b5132 RH |
482 | verbose -log "Did not find \"$l2\"" |
483 | set f1 [open $tmpdir/objdump.out r] | |
484 | while { [gets $f1 l1] != -1 } { | |
485 | verbose -log $l1 | |
486 | } | |
487 | ||
488 | verbose -log "$exec_output" | |
489 | return 0 | |
490 | } else { | |
491 | verbose -log "$exec_output" | |
492 | return 0 | |
493 | } | |
494 | } | |
495 | ||
f006af20 | 496 | proc build_vers_lib { pic test source libname other mapfile verexp versymexp symexp } { |
252b5132 RH |
497 | global ld |
498 | global srcdir | |
499 | global subdir | |
500 | global exec_output | |
501 | global host_triplet | |
502 | global tmpdir | |
503 | global as | |
504 | global objdump | |
505 | global CC | |
506 | global CFLAGS | |
507 | global shared | |
508 | global script | |
509 | ||
f006af20 | 510 | if ![ld_compile "$CC -S $pic $CFLAGS" $srcdir/$subdir/$source $tmpdir/$libname.s] { |
252b5132 RH |
511 | unresolved "$test" |
512 | return | |
513 | } | |
514 | ||
515 | if ![ld_assemble $as $tmpdir/$libname.s $tmpdir/$libname.o ] { | |
516 | unresolved "$test" | |
517 | return | |
518 | } | |
519 | ||
67954772 L |
520 | set other_lib "" |
521 | if ![string match "" $other] then { | |
522 | foreach o $other { | |
82e03011 | 523 | set other_lib "$other_lib $tmpdir/$o" |
67954772 | 524 | } |
252b5132 RH |
525 | } |
526 | ||
527 | if [string match "" $mapfile] then { | |
528 | set script_arg "" | |
529 | } else { | |
530 | set script_arg "$script $srcdir/$subdir/$mapfile" | |
531 | } | |
532 | ||
533 | if {![ld_simple_link $ld $tmpdir/$libname.so "$shared $tmpdir/$libname.o $other_lib $script_arg"]} { | |
534 | fail "$test" | |
535 | return | |
536 | } | |
537 | ||
538 | if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]} { | |
539 | fail "$test" | |
540 | return | |
541 | } | |
542 | ||
543 | if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]} { | |
544 | fail "$test" | |
545 | return | |
546 | } | |
547 | ||
548 | if [string match "" $symexp] then { | |
549 | if {![objdump_emptysymstuff $objdump $tmpdir/$libname.o ]} { | |
550 | fail "$test" | |
551 | return | |
552 | } | |
553 | } else { | |
554 | if {![objdump_symstuff $objdump $tmpdir/$libname.o $srcdir/$subdir/$symexp ]} { | |
555 | fail "$test" | |
556 | return | |
557 | } | |
558 | } | |
559 | ||
560 | pass $test | |
561 | ||
562 | } | |
563 | ||
f006af20 L |
564 | proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp symexp } { |
565 | build_vers_lib "" $test $source $libname $other $mapfile $verexp $versymexp $symexp | |
566 | } | |
567 | ||
568 | proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } { | |
569 | global picflag | |
570 | build_vers_lib $picflag $test $source $libname $other $mapfile $verexp $versymexp $symexp | |
571 | } | |
572 | ||
252b5132 RH |
573 | proc test_ldfail { test flag source execname other mapfile whyfail } { |
574 | global ld | |
575 | global srcdir | |
576 | global subdir | |
577 | global exec_output | |
578 | global host_triplet | |
579 | global tmpdir | |
580 | global as | |
581 | global objdump | |
582 | global CC | |
583 | global CFLAGS | |
584 | global script | |
585 | ||
586 | if [string match "" $other] then { | |
587 | set other_lib "" | |
588 | } else { | |
589 | set other_lib $tmpdir/$other | |
590 | } | |
591 | ||
592 | if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s] { | |
593 | unresolved "$test" | |
594 | return | |
595 | } | |
596 | ||
597 | if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ] { | |
598 | unresolved "$test" | |
599 | return | |
600 | } | |
601 | ||
602 | verbose -log "This link should fail because of $whyfail" | |
603 | ||
604 | if [string match "" $mapfile] then { | |
605 | set script_arg "" | |
606 | } else { | |
607 | set script_arg "$script $srcdir/$subdir/$mapfile" | |
608 | } | |
609 | ||
610 | if {![ld_link $ld $tmpdir/$execname "$tmpdir/$execname.o $other_lib $script_arg"]} { | |
611 | pass "$test" | |
612 | return | |
613 | } | |
614 | fail "$test" | |
615 | } | |
616 | ||
617 | proc test_asfail { test flag source execname whyfail } { | |
618 | global srcdir | |
619 | global subdir | |
620 | global tmpdir | |
621 | global as | |
622 | global CC | |
623 | global CFLAGS | |
624 | ||
625 | if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s] { | |
626 | unresolved "$test" | |
627 | return | |
628 | } | |
629 | ||
630 | verbose -log "This assemble should fail because of $whyfail" | |
631 | catch "exec $as -o $tmpdir/$execname.o $tmpdir/$execname.s" exec_output | |
632 | set exec_output [prune_warnings $exec_output] | |
633 | if [string match "" $exec_output] then { | |
634 | fail "$test" | |
635 | return | |
636 | } | |
637 | verbose -log "$exec_output" | |
638 | pass "$test" | |
639 | } | |
640 | ||
641 | proc test_strip_vers_lib { test srclib libname verexp versymexp } { | |
642 | global strip | |
643 | global srcdir | |
644 | global subdir | |
645 | global exec_output | |
646 | global host_triplet | |
647 | global tmpdir | |
648 | global objdump | |
649 | ||
650 | verbose -log "cp $tmpdir/$srclib $tmpdir/$libname.so" | |
651 | exec cp $tmpdir/$srclib $tmpdir/$libname.so | |
652 | ||
653 | verbose -log "$strip $tmpdir/$libname.so" | |
654 | catch "exec $strip $tmpdir/$libname.so" exec_output | |
655 | if [string match "" $exec_output] then { | |
656 | ||
657 | # If strip went OK, then run the usual tests on the thing to make sure that | |
658 | # it is sane. | |
659 | if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]} { | |
660 | fail "$test" | |
661 | return | |
662 | } | |
663 | ||
664 | if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]} { | |
665 | fail "$test" | |
666 | return | |
667 | } | |
668 | ||
669 | } else { | |
670 | verbose -log "$exec_output" | |
671 | fail "$test" | |
672 | return | |
673 | } | |
674 | pass $test | |
675 | } | |
676 | ||
677 | ||
678 | proc build_exec { test source execname flags solibname verexp versymexp symexp } { | |
679 | global ld | |
680 | global srcdir | |
681 | global subdir | |
682 | global exec_output | |
683 | global host_triplet | |
684 | global tmpdir | |
685 | global as | |
686 | global objdump | |
687 | global CC | |
688 | global CFLAGS | |
689 | ||
31941635 | 690 | set shared "--shared --no-undefined-version" |
252b5132 RH |
691 | set script --version-script |
692 | if ![ld_compile "$CC -S $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s] { | |
693 | unresolved "$test" | |
694 | return | |
695 | } | |
696 | ||
697 | if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ] { | |
698 | unresolved "$test" | |
699 | return | |
700 | } | |
701 | ||
702 | if [string match "" $solibname] then { | |
703 | set solibname_lib "" | |
704 | } else { | |
705 | set solibname_lib $tmpdir/$solibname | |
706 | } | |
707 | ||
708 | if {![ld_link $ld $tmpdir/$execname "$flags $tmpdir/$execname.o $solibname_lib"]} { | |
709 | fail "$test" | |
710 | return | |
711 | } | |
712 | ||
713 | if [string match "" $verexp] then { | |
714 | # | |
715 | # Make sure we get nothing back. | |
716 | # | |
717 | if {![objdump_emptyverstuff $objdump $tmpdir/$execname ]} { | |
718 | fail "$test" | |
719 | return | |
720 | } | |
721 | } else { | |
722 | if {![objdump_versionstuff $objdump $tmpdir/$execname $srcdir/$subdir/$verexp ]} { | |
723 | fail "$test" | |
724 | return | |
725 | } | |
726 | } | |
727 | ||
728 | if [string match "" $versymexp] then { | |
729 | if {![objdump_emptydynsymstuff $objdump $tmpdir/$execname ]} { | |
730 | fail "$test" | |
731 | return | |
732 | } | |
733 | } else { | |
734 | if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$versymexp ]} { | |
735 | fail "$test" | |
736 | return | |
737 | } | |
738 | } | |
739 | ||
740 | if [string match "" $symexp] then { | |
741 | if {![objdump_emptysymstuff $objdump $tmpdir/$execname.o ]} { | |
742 | fail "$test" | |
743 | return | |
744 | } | |
745 | } else { | |
746 | if {![objdump_symstuff $objdump $tmpdir/$execname.o $srcdir/$subdir/$symexp ]} { | |
747 | fail "$test" | |
748 | return | |
749 | } | |
750 | } | |
751 | ||
752 | pass $test | |
753 | } | |
754 | ||
755 | ||
756 | # | |
757 | # Basic test - build a library with versioned symbols. | |
758 | # | |
f006af20 | 759 | build_vers_lib_no_pic "vers1" vers1.c vers1 "" vers1.map vers1.ver vers1.dsym vers1.sym |
252b5132 RH |
760 | |
761 | ||
762 | # | |
763 | # Test #2 - build a library, and link it against the library we built in step | |
764 | # 1. | |
765 | # | |
9147e853 JJ |
766 | if [istarget x86_64-*-linux*] { |
767 | # x86_64 doesn't like non-pic shared libraries | |
768 | xfail "vers2" | |
769 | } else { | |
f006af20 | 770 | build_vers_lib_no_pic "vers2" vers2.c vers2 vers1.so vers2.map vers2.ver vers2.dsym "" |
9147e853 | 771 | } |
252b5132 RH |
772 | |
773 | # | |
774 | # Test #3 - build an executable, and link it against vers1.so. | |
775 | # | |
776 | build_exec "vers3" vers3.c vers3 "" vers1.so vers3.ver vers3.dsym "" | |
777 | ||
778 | # | |
779 | # Test #4 - Make sure a version implicitly defined in an executable | |
780 | # causes a version node to be created. Verify this both with and without | |
781 | # --export-dynamic. | |
782 | # | |
783 | ||
784 | # This test fails on MIPS. On the MIPS we must put foo in the dynamic | |
785 | # symbol table, which the test does not expect. | |
786 | setup_xfail "mips*-*-*" | |
787 | build_exec "vers4" vers4.c vers4 "" "" "" "" vers4.sym | |
788 | ||
789 | build_exec "vers4a" vers4.c vers4a "-export-dynamic" "" vers4a.ver vers4a.dsym vers4a.sym | |
790 | ||
791 | ||
792 | # | |
793 | # Try multiple definitions foo@BAR and foo@@BAR and make sure the linker | |
794 | # complains. | |
795 | # | |
796 | test_ldfail "vers5" "" vers5.c vers5 "" "" "multiple definition of foo@VERS_1.2" | |
797 | ||
798 | # | |
799 | # | |
800 | # Now build a test that should reference a bunch of versioned symbols. | |
801 | # All of them should be correctly referenced. | |
802 | # | |
803 | build_exec "vers6" vers6.c vers6 "" vers1.so vers6.ver vers6.dsym vers6.sym | |
804 | ||
805 | # | |
806 | # Another test to verify that something made local via 'local' is truly not | |
807 | # accessible. | |
808 | # | |
f006af20 | 809 | build_vers_lib_no_pic "vers7a" vers7a.c vers7a "" vers7.map vers7a.ver vers7a.dsym vers7a.sym |
252b5132 RH |
810 | |
811 | test_ldfail "vers7" "" vers7.c vers7 vers7a.so "" "undefined reference to hide_a" | |
812 | ||
813 | ||
814 | # | |
815 | # This test is designed to verify that we can pass a linker script on the | |
816 | # command line as if it were a normal .o file. | |
817 | # | |
818 | catch "exec cp $srcdir/$subdir/vers8.map $tmpdir/" ignore_output | |
f006af20 | 819 | build_vers_lib_no_pic "vers8" vers1.c vers8 vers8.map "" vers8.ver vers1.dsym vers1.sym |
252b5132 RH |
820 | |
821 | # | |
822 | # This test tries to make sure that version references to versioned symbols | |
823 | # don't collide with default definitions with the same symbol. | |
824 | # | |
825 | build_exec "vers9" vers9.c vers9 "-export-dynamic" "" vers9.ver vers9.dsym vers9.sym | |
826 | ||
827 | ||
828 | # | |
829 | # Try and use a non-existant version node. The linker should fail with | |
830 | # an error message. | |
831 | # | |
832 | test_ldfail "vers10" "-DDO_TEST10" vers1.c vers10 "" "vers1.map --shared" "invalid version" | |
833 | ||
834 | # | |
835 | # Try and some things the assembler should complain about. | |
836 | # | |
837 | test_asfail "vers11" "-DDO_TEST11" vers1.c vers11 "no @ in symver" | |
838 | ||
839 | test_asfail "vers12" "-DDO_TEST12" vers1.c vers12 "extern version definition" | |
840 | ||
841 | # | |
842 | # Put a shared library in an archive library, and make sure the global | |
843 | # archive symbol table is sane. | |
844 | # | |
845 | test_ar "ar with versioned solib" vers13.a vers1.so vers13.asym | |
846 | ||
847 | # | |
848 | # Strip a shared library, and make sure we didn't screw something up in there. | |
849 | # | |
850 | test_strip_vers_lib "vers14" vers1.so vers14 vers1.ver vers1.dsym | |
851 | ||
852 | ||
853 | # | |
854 | # Build another test with some versioned symbols. Here we are going to | |
855 | # try and override something from the library, and we shouldn't get | |
856 | # any errors. | |
857 | # | |
858 | build_exec "vers15" vers15.c vers15 "" vers1.so vers15.ver vers15.dsym vers15.sym | |
859 | ||
860 | # | |
861 | # Test that when we override a versioned symbol from the library this | |
862 | # symbol appears in the dynamic symbol table of the executable. | |
863 | # | |
f006af20 | 864 | build_vers_lib_no_pic "vers16a" vers16a.c vers16a "" vers16.map vers16a.ver vers16a.dsym "" |
252b5132 | 865 | build_exec "vers16" vers16.c vers16 "" vers16a.so "" vers16.dsym "" |
f0489494 ILT |
866 | |
867 | # Test a weak versioned symbol. | |
f006af20 L |
868 | build_vers_lib_no_pic "vers17" vers17.c vers17 "" vers17.map vers17.ver vers17.dsym "" |
869 | build_vers_lib_no_pic "vers18" vers18.c vers18 vers17.so vers18.map vers18.ver vers18.dsym vers18.sym | |
9d8b3bf4 | 870 | build_exec "vers19" vers19.c vers19 "-rpath ." vers18.so vers19.ver vers19.dsym "" |
67954772 | 871 | |
f006af20 | 872 | build_vers_lib_no_pic "vers20a" vers20.c vers20a "" vers20.map vers20a.ver vers20.dsym "" |
67954772 | 873 | exec cp $tmpdir/vers20a.so $tmpdir/vers20b.so |
f006af20 | 874 | build_vers_lib_no_pic "vers20" vers20.c vers20 "vers20a.so vers20b.so" vers20.map vers20.ver vers20.dsym "" |
b42d8061 L |
875 | |
876 | # Test .symver override. | |
f006af20 | 877 | build_vers_lib_no_pic "vers21" vers21.c vers21 "" vers21.map vers21.ver vers21.dsym vers21.sym |
b16100ad L |
878 | |
879 | # Test moving default definition from one DSO to another. | |
f006af20 L |
880 | build_vers_lib_no_pic "vers22a" vers22a.c vers22a "" vers22.map vers22a.ver vers22a.dsym vers22a.sym |
881 | build_vers_lib_no_pic "vers22b" vers22b.c vers22b "" vers22.map vers22b.ver vers22b.dsym "" | |
882 | build_vers_lib_no_pic "vers22" vers22.c vers22 "vers22a.so vers22b.so" "" vers22.ver vers22.dsym "" | |
9c092167 L |
883 | |
884 | # Test versioned definitions in different files. | |
f006af20 L |
885 | build_vers_lib_no_pic "vers23a" vers23a.c vers23a "" vers23a.map vers23a.ver vers23a.dsym vers23a.sym |
886 | build_vers_lib_no_pic "vers23b" vers23b.c vers23b "" vers23b.map vers23b.ver vers23b.dsym "" | |
887 | build_vers_lib_no_pic "vers23c" vers23b.c vers23c "vers23a.so" vers23b.map vers23c.ver vers23b.dsym "" | |
80425074 | 888 | build_exec "vers23d" vers23.c vers23d "tmpdir/vers23a.so tmpdir/vers23c.so" "" vers23.ver vers23d.dsym "" |
9c092167 | 889 | build_exec "vers23" vers23.c vers23 "tmpdir/vers23a.so tmpdir/vers23b.o tmpdir/vers23b.so" "" vers23.ver vers23.dsym "" |
9147e853 JJ |
890 | |
891 | # Test .symver x,x@VERS.0 | |
892 | set as_pic_flags "" | |
893 | if [istarget sparc*-*-*] { | |
894 | set as_pic_flags "-K PIC" | |
895 | } | |
896 | run_ld_link_tests [list "\"vers24a\" | |
897 | \"-shared --version-script $srcdir/$subdir/vers24.map\" | |
898 | \"$as_pic_flags\" {vers24a.c vers24b.c} { { readelf -Wrs vers24.rd } } | |
899 | \"libvers24a.so\" \"-fpic\""] | |
900 | run_ld_link_tests [list "\"vers24b\" | |
901 | \"-shared --version-script $srcdir/$subdir/vers24.map\" | |
902 | \"$as_pic_flags\" {vers24b.c vers24a.c} { { readelf -Wrs vers24.rd } } | |
903 | \"libvers24b.so\" \"-fpic\""] | |
904 | run_ld_link_tests [list "\"vers24c\" | |
905 | \"-shared --version-script $srcdir/$subdir/vers24.map\" | |
906 | \"$as_pic_flags\" {vers24c.c} { { readelf -Wrs vers24.rd } } | |
907 | \"libvers24c.so\" \"-fpic\""] | |
365f9131 L |
908 | |
909 | # Test versioned definition vs. normal definition in different files. | |
f006af20 L |
910 | build_vers_lib_no_pic "vers25a" vers25a.c vers25a "" vers25a.map vers25a.ver vers25a.dsym "" |
911 | build_vers_lib_no_pic "vers25b1" vers25b.c vers25b1 "vers25a.o vers25a.so" "" vers25b.ver vers25b.dsym "" | |
912 | build_vers_lib_no_pic "vers25b2" vers25b.c vers25b2 "vers25a.so vers25a.o" "" vers25b.ver vers25b.dsym "" | |
913 | build_vers_lib_pic "vers26a" vers26a.c vers26a "" vers26a.map vers26a.ver vers26a.dsym "" | |
914 | build_vers_lib_pic "vers26b1" vers26b.c vers26b1 "" "" vers26b.ver vers26b.dsym "" | |
915 | build_vers_lib_pic "vers26b2" vers26b.c vers26b2 "vers26a.so vers26b1.so vers26a.o" "" vers26b.ver vers26b.dsym "" | |
fcd06cfe AJ |
916 | if [istarget x86_64-*-linux*] { |
917 | # x86_64 doesn't like non-pic shared libraries | |
918 | xfail "vers26b3" | |
919 | } else { | |
920 | build_vers_lib_no_pic "vers26b3" vers26b.c vers26b3 "vers26a.so vers26b1.so vers26a.o" "" vers26b.ver vers26b.dsym "" | |
921 | } |