1 # Expect script
for ld-version tests
2 # Copyright
(C
) 1997, 1998, 1999 Free Software Foundation
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.
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.
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.
18 # Written by Eric Youngdale
(eric@andante.jic.com
)
22 # This test can only be run
if ld generates native executables.
23 if ![isnative
] then {return}
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 sparc
*-*-linux
*] \
40 && ![istarget alpha
*-*-linux
*] } {
44 if { [istarget i?
86-*-linuxaout
*] \
45 ||
[istarget i?
86-*-linuxoldld
*] \
46 ||
[istarget m68k
-*-linuxaout
*] } {
50 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
56 set VOBJDUMP_FLAGS
--private
-headers
57 set DOBJDUMP_FLAGS
--dynamic
-syms
58 set SOBJDUMP_FLAGS
--syms
60 set script
--version
-script
62 proc test_ar
{ test lib object expect
} {
70 verbose
-log "$ar -cr $tmpdir/$lib $tmpdir/$object"
71 catch
"exec $ar -cr $tmpdir/$lib $tmpdir/$object" exec_output
72 set exec_output
[prune_warnings $exec_output
]
73 if ![string match
"" $exec_output] {
74 verbose
-log "$exec_output"
79 verbose
-log "$nm --print-armap $tmpdir/$lib | grep \" in \" | egrep \"VERS\\|bar\\|foo\" | sort > $tmpdir/nm.out"
81 catch
"exec $nm --print-armap $tmpdir/$lib | grep \\\ in\\\ | egrep VERS\\\|bar\\\|foo | sort > $tmpdir/nm.out" exec_output
82 if [string match
"" $exec_output] then {
83 catch
"exec $diff -q $tmpdir/nm.out $srcdir/$subdir/$expect" exec_output
84 set exec_output
[prune_warnings $exec_output
]
85 if [string match
"" $exec_output] then {
89 verbose
-log "$exec_output"
94 verbose
-log "$exec_output"
100 # objdump_emptysymstuff
101 # Check non
-dynamic symbols and make sure there are
none with
'@'.
103 proc objdump_emptysymstuff
{ objdump object
} {
104 global SOBJDUMP_FLAGS
105 global version_output
108 if ![info exists SOBJDUMP_FLAGS
] { set SOBJDUMP_FLAGS
"" }
110 verbose
-log "$objdump $SOBJDUMP_FLAGS $object | sed -n /\@/p"
112 catch
"exec $objdump $SOBJDUMP_FLAGS $object | sed -n /\@/p" exec_output
113 set exec_output
[prune_warnings $exec_output
]
114 if [string match
"" $exec_output] then {
115 # We shouldn
't get anything here.
118 # it is not normal to come here - we have no output to compare.
119 verbose -log "$exec_output"
120 verbose -log "objdump_emptysymstuff: did not expect any output from objdump"
127 # objdump_emptydynsymstuff
128 # Check dynamic symbols and make sure there are none with '@
'.
130 proc objdump_emptydynsymstuff { objdump object } {
131 global DOBJDUMP_FLAGS
132 global version_output
135 if ![info exists VOBJDUMP_FLAGS] { set VOBJDUMP_FLAGS "" }
137 verbose -log "$objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p"
139 catch "exec $objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p" exec_output
140 set exec_output [prune_warnings $exec_output]
141 if [string match "" $exec_output] then {
142 # We shouldn't
get anything here.
144 } else { if [string match
"*objdump: *: not a dynamic object" $exec_output] then {
147 # it is not
normal to come here
- we have no output to compare.
148 verbose
-log "$exec_output"
149 verbose
-log "objdump_emptydynsymstuff: did not expect any output from objdump"
155 # objdump_emptyverstuff
156 # Make sure there is no version information
158 proc objdump_emptyverstuff
{ objdump object
} {
159 global VOBJDUMP_FLAGS
160 global version_output
164 if {[which $objdump
] == 0} then {
165 perror
"$objdump does not exist"
169 if ![info exists VOBJDUMP_FLAGS
] { set VOBJDUMP_FLAGS
"" }
171 verbose
-log "$objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out"
173 catch
"exec $objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p" exec_output
174 set exec_output
[prune_warnings $exec_output
]
175 if [string match
"" $exec_output] then {
176 # it is
normal to fail here
- we have no output to compare.
178 } else { if { [string match
"*libc*" $exec_output] } then {
179 # this probably means that there is version information in libc
, so we
180 # can
't really perform this test.
183 verbose -log "$exec_output"
184 verbose -log "objdump_emptyverstuff: did not expect any output from objdump"
192 # Dump non-dynamic symbol stuff and make sure that it is sane.
194 proc objdump_symstuff { objdump object expectfile } {
195 global SOBJDUMP_FLAGS
196 global version_output
200 if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
202 verbose -log "$objdump $SOBJDUMP_FLAGS $object | grep \@ | sort > $tmpdir/objdump.out"
204 catch "exec $objdump $SOBJDUMP_FLAGS $object | grep \@ | sort > $tmpdir/objdump.out" exec_output
205 set exec_output [prune_warnings $exec_output]
206 if [string match "" $exec_output] then {
208 # Now do a line-by-line comparison to effectively diff the darned things
209 # The stuff coming from the expectfile is actually a regex, so we can
210 # skip over the actual addresses and so forth. This is currently very
211 # simpleminded - it expects a one-to-one correspondence in terms of line
214 if [file exists $expectfile] then {
215 set file_a [open $expectfile r]
217 perror "$expectfile doesn't exist
"
221 if [file
exists $tmpdir
/objdump.out
] then {
222 set file_b
[open $tmpdir
/objdump.out r
]
224 perror
"$tmpdir/objdump.out doesn't exist"
228 verbose
"# Diff'ing: $expectfile $tmpdir/objdump.out" 2
233 while { [gets $file_a line
] != $eof
} {
234 if [regexp
"^#.*$" $line] then {
242 while { [gets $file_b line
] != $eof
} {
243 if [regexp
"^#.*$" $line] then {
251 for { set i
0 } { $i
< [llength $list_a
] } { incr i
} {
252 set line_a
[lindex $list_a $i
]
253 set line_b
[lindex $list_b $i
]
256 verbose
"\t$expectfile: $i: $line_a" 3
257 verbose
"\t/tmp/objdump.out: $i: $line_b" 3
258 if [regexp $line_a $line_b
] then {
261 verbose
-log "\t$expectfile: $i: $line_a"
262 verbose
-log "\t$tmpdir/objdump.out: $i: $line_b"
268 if { [llength $list_a
] != [llength $list_b
] } {
269 verbose
-log "Line count"
273 if $differences
<1 then {
279 verbose
-log "$exec_output"
286 # objdump_dymsymstuff
287 # Dump dynamic symbol stuff and make sure that it is sane.
289 proc objdump_dynsymstuff
{ objdump object expectfile
} {
290 global DOBJDUMP_FLAGS
291 global version_output
295 if ![info exists DOBJDUMP_FLAGS
] { set DOBJDUMP_FLAGS
"" }
297 verbose
-log "$objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p | sort | uniq > $tmpdir/objdump.out"
299 catch
"exec $objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p | sort | uniq > $tmpdir/objdump.out" exec_output
300 set exec_output
[prune_warnings $exec_output
]
301 if [string match
"" $exec_output] then {
303 # Now
do a line
-by
-line comparison to effectively diff the darned things
304 # The stuff coming from the expectfile is actually a regex
, so we can
305 # skip over the actual addresses and so forth. This is currently very
306 # simpleminded
- it expects a one
-to
-one correspondence in terms of line
309 if [file
exists $expectfile
] then {
310 set file_a
[open $expectfile r
]
312 warning
"$expectfile doesn't exist"
316 if [file
exists $tmpdir
/objdump.out
] then {
317 set file_b
[open $tmpdir
/objdump.out r
]
319 fail
"$tmpdir/objdump.out doesn't exist"
323 verbose
"# Diff'ing: $expectfile $tmpdir/objdump.out" 2
328 while { [gets $file_a line
] != $eof
} {
329 if [regexp
"^#.*$" $line] then {
337 while { [gets $file_b line
] != $eof
} {
338 if [regexp
"^#.*$" $line] then {
346 for { set i
0 } { $i
< [llength $list_b
] } { incr i
} {
347 set line_b
[lindex $list_b $i
]
349 # The tests are rigged so that we should never
export a symbol with the
350 # word
'hide' in it. Thus we just search
for it
, and bail
if we find it.
351 if [regexp
"hide" $line_b] then {
352 verbose
-log "\t$tmpdir/objdump.out: $i: $line_b"
357 verbose
"\t$expectfile: $i: $line_b" 3
359 # We can
't assume that the sort is consistent across
360 # systems, so we must check each regexp. When we find a
361 # regexp, we null it out, so we don't match it twice.
362 for { set j
0 } { $j
< [llength $list_a
] } { incr j
} {
363 set line_a
[lindex $list_a $j
]
365 if [regexp $line_a $line_b
] then {
366 lreplace $list_a $j $j
"CAN NOT MATCH"
371 if { $j
>= [llength $list_a
] } {
372 verbose
-log "\t$tmpdir/objdump.out: $i: $line_b"
378 if { [llength $list_a
] != [llength $list_b
] } {
379 verbose
-log "Line count"
383 if $differences
<1 then {
389 verbose
-log "$exec_output"
396 # objdump_versionstuff
397 # Dump version definitions
/references and make sure that it is sane.
399 proc objdump_versionstuff
{ objdump object expectfile
} {
400 global VOBJDUMP_FLAGS
401 global version_output
405 if {[which $objdump
] == 0} then {
406 perror
"$objdump does not exist"
410 if ![info exists VOBJDUMP_FLAGS
] { set VOBJDUMP_FLAGS
"" }
412 verbose
-log "$objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out"
414 catch
"exec $objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out" exec_output
415 set exec_output
[prune_warnings $exec_output
]
416 if [string match
"" $exec_output] then {
418 # It
's OK if there are extra lines in the actual output; they
419 # may come from version information in libc. We require that
420 # every line in EXPECTFILE appear in the output in order.
422 set f1 [open $tmpdir/objdump.out r]
423 set f2 [open $expectfile r]
425 while { [gets $f1 l1] != -1 } {
426 if { [string match $l2 $l1] } then {
427 if { [gets $f2 l2] == -1 } then {
435 # We reached the end of the output without seeing the line we
436 # expected. This is a test failure.
441 verbose -log "Did not find \"$l2\""
442 set f1 [open $tmpdir/objdump.out r]
443 while { [gets $f1 l1] != -1 } {
447 verbose -log "$exec_output"
450 verbose -log "$exec_output"
455 proc build_vers_lib { test source libname other mapfile verexp versymexp symexp } {
469 if ![ld_compile "$CC -S $CFLAGS" $srcdir/$subdir/$source $tmpdir/$libname.s] {
474 if ![ld_assemble $as $tmpdir/$libname.s $tmpdir/$libname.o ] {
479 if [string match "" $other] then {
482 set other_lib $tmpdir/$other
485 if [string match "" $mapfile] then {
488 set script_arg "$script $srcdir/$subdir/$mapfile"
491 if {![ld_simple_link $ld $tmpdir/$libname.so "$shared $tmpdir/$libname.o $other_lib $script_arg"]} {
496 if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]} {
501 if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]} {
506 if [string match "" $symexp] then {
507 if {![objdump_emptysymstuff $objdump $tmpdir/$libname.o ]} {
512 if {![objdump_symstuff $objdump $tmpdir/$libname.o $srcdir/$subdir/$symexp ]} {
522 proc test_ldfail { test flag source execname other mapfile whyfail } {
535 if [string match "" $other] then {
538 set other_lib $tmpdir/$other
541 if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s] {
546 if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ] {
551 verbose -log "This link should fail because of $whyfail"
553 if [string match "" $mapfile] then {
556 set script_arg "$script $srcdir/$subdir/$mapfile"
559 if {![ld_link $ld $tmpdir/$execname "$tmpdir/$execname.o $other_lib $script_arg"]} {
566 proc test_asfail { test flag source execname whyfail } {
574 if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s] {
579 verbose -log "This assemble should fail because of $whyfail"
580 catch "exec $as -o $tmpdir/$execname.o $tmpdir/$execname.s" exec_output
581 set exec_output [prune_warnings $exec_output]
582 if [string match "" $exec_output] then {
586 verbose -log "$exec_output"
590 proc test_strip_vers_lib { test srclib libname verexp versymexp } {
599 verbose -log "cp $tmpdir/$srclib $tmpdir/$libname.so"
600 exec cp $tmpdir/$srclib $tmpdir/$libname.so
602 verbose -log "$strip $tmpdir/$libname.so"
603 catch "exec $strip $tmpdir/$libname.so" exec_output
604 if [string match "" $exec_output] then {
606 # If strip went OK, then run the usual tests on the thing to make sure that
608 if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]} {
613 if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]} {
619 verbose -log "$exec_output"
627 proc build_exec { test source execname flags solibname verexp versymexp symexp } {
640 set script --version-script
641 if ![ld_compile "$CC -S $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s] {
646 if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ] {
651 if [string match "" $solibname] then {
654 set solibname_lib $tmpdir/$solibname
657 if {![ld_link $ld $tmpdir/$execname "$flags $tmpdir/$execname.o $solibname_lib"]} {
662 if [string match "" $verexp] then {
664 # Make sure we get nothing back.
666 if {![objdump_emptyverstuff $objdump $tmpdir/$execname ]} {
671 if {![objdump_versionstuff $objdump $tmpdir/$execname $srcdir/$subdir/$verexp ]} {
677 if [string match "" $versymexp] then {
678 if {![objdump_emptydynsymstuff $objdump $tmpdir/$execname ]} {
683 if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$versymexp ]} {
689 if [string match "" $symexp] then {
690 if {![objdump_emptysymstuff $objdump $tmpdir/$execname.o ]} {
695 if {![objdump_symstuff $objdump $tmpdir/$execname.o $srcdir/$subdir/$symexp ]} {
706 # Basic test - build a library with versioned symbols.
708 build_vers_lib "vers1" vers1.c vers1 "" vers1.map vers1.ver vers1.dsym vers1.sym
712 # Test #2 - build a library, and link it against the library we built in step
715 build_vers_lib "vers2" vers2.c vers2 vers1.so vers2.map vers2.ver vers2.dsym ""
718 # Test #3 - build an executable, and link it against vers1.so.
720 build_exec "vers3" vers3.c vers3 "" vers1.so vers3.ver vers3.dsym ""
723 # Test #4 - Make sure a version implicitly defined in an executable
724 # causes a version node to be created. Verify this both with and without
728 # This test fails on MIPS. On the MIPS we must put foo in the dynamic
729 # symbol table, which the test does not expect.
730 setup_xfail "mips*-*-*"
731 build_exec "vers4" vers4.c vers4 "" "" "" "" vers4.sym
733 build_exec "vers4a" vers4.c vers4a "-export-dynamic" "" vers4a.ver vers4a.dsym vers4a.sym
737 # Try multiple definitions foo@BAR and foo@@BAR and make sure the linker
740 test_ldfail "vers5" "" vers5.c vers5 "" "" "multiple definition of foo@VERS_1.2"
744 # Now build a test that should reference a bunch of versioned symbols.
745 # All of them should be correctly referenced.
747 build_exec "vers6" vers6.c vers6 "" vers1.so vers6.ver vers6.dsym vers6.sym
750 # Another test to verify that something made local via 'local
' is truly not
753 build_vers_lib "vers7a" vers7a.c vers7a "" vers7.map vers7a.ver vers7a.dsym vers7a.sym
755 test_ldfail "vers7" "" vers7.c vers7 vers7a.so "" "undefined reference to hide_a"
759 # This test is designed to verify that we can pass a linker script on the
760 # command line as if it were a normal .o file.
762 catch "exec cp $srcdir/$subdir/vers8.map $tmpdir/" ignore_output
763 build_vers_lib "vers8" vers1.c vers8 vers8.map "" vers8.ver vers1.dsym vers1.sym
766 # This test tries to make sure that version references to versioned symbols
767 # don't collide with default definitions with the same symbol.
769 build_exec
"vers9" vers9.c vers9 "-export-dynamic" "" vers9.ver vers9.dsym vers9.sym
773 # Try and use a non
-existant version node. The linker should fail with
776 test_ldfail
"vers10" "-DDO_TEST10" vers1.c vers10 "" "vers1.map --shared" "invalid version"
779 # Try and some things the assembler should complain about.
781 test_asfail
"vers11" "-DDO_TEST11" vers1.c vers11 "no @ in symver"
783 test_asfail
"vers12" "-DDO_TEST12" vers1.c vers12 "extern version definition"
786 # Put a shared library in an archive library
, and make sure the global
787 # archive symbol table is sane.
789 test_ar
"ar with versioned solib" vers13.a vers1.so vers13.asym
792 #
Strip a shared library
, and make sure we didn
't screw something up in there.
794 test_strip_vers_lib "vers14" vers1.so vers14 vers1.ver vers1.dsym
798 # Build another test with some versioned symbols. Here we are going to
799 # try and override something from the library, and we shouldn't
get
802 build_exec
"vers15" vers15.c vers15 "" vers1.so vers15.ver vers15.dsym vers15.sym
805 # Test that when we override a versioned symbol from the library this
806 # symbol appears in the dynamic symbol table of the executable.
808 build_vers_lib
"vers16a" vers16a.c vers16a "" vers16.map vers16a.ver vers16a.dsym ""
809 build_exec
"vers16" vers16.c vers16 "" vers16a.so "" vers16.dsym ""
811 # Test a weak versioned symbol.
812 build_vers_lib
"vers17" vers17.c vers17 "" vers17.map vers17.ver vers17.dsym ""
813 build_vers_lib
"vers18" vers18.c vers18 vers17.so vers18.map vers18.ver vers18.dsym vers18.sym
814 build_exec
"vers19" vers19.c vers19 "-rpath ." vers18.so vers19.ver vers19.dsym ""