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