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