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