1 # Expect script for ld-weak tests
2 # Copyright 2001 Free Software Foundation, Inc.
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 H.J. Lu (hjl@gnu.org)
19 # 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 ia64-*-elf*] \
33 && ![istarget ia64-*-linux*] \
34 && ![istarget m68k-*-linux*] \
35 && ![istarget mips*-*-irix5*] \
36 && ![istarget powerpc-*-elf*] \
37 && ![istarget powerpc-*-linux*] \
38 && ![istarget powerpc-*-sysv4*] \
39 && ![istarget sparc*-*-elf] \
40 && ![istarget sparc*-*-solaris2*] \
41 && ![istarget sparc*-*-linux*] \
42 && ![istarget arm*-*-linux*] \
43 && ![istarget mips*-*-linux*] \
44 && ![istarget alpha*-*-linux*] } {
48 if { [istarget i?86-*-linux*aout*] \
49 || [istarget i?86-*-linux*oldld*] \
50 || [istarget m68k-*-linux*aout*] } {
54 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
60 set DOBJDUMP_FLAGS --dynamic-syms
61 set SOBJDUMP_FLAGS --syms
66 # Dump non-dynamic symbol stuff and make sure that it is sane.
68 proc objdump_symstuff { objdump object expectfile } {
74 if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
76 verbose -log "$objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
78 catch "exec $objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
79 set exec_output [prune_warnings $exec_output]
80 if [string match "" $exec_output] then {
82 # Now do a line-by-line comparison to effectively diff the darned things
83 # The stuff coming from the expectfile is actually a regex, so we can
84 # skip over the actual addresses and so forth. This is currently very
85 # simpleminded - it expects a one-to-one correspondence in terms of line
88 if [file exists $expectfile] then {
89 set file_a [open $expectfile r]
91 perror "$expectfile doesn't exist"
95 if [file exists $tmpdir/objdump.out] then {
96 set file_b [open $tmpdir/objdump.out r]
98 perror "$tmpdir/objdump.out doesn't exist"
102 verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
107 while { [gets $file_a line] != $eof } {
108 if [regexp "^#.*$" $line] then {
116 while { [gets $file_b line] != $eof } {
117 if [regexp "^#.*$" $line] then {
125 for { set i 0 } { $i < [llength $list_a] } { incr i } {
126 set line_a [lindex $list_a $i]
127 set line_b [lindex $list_b $i]
130 verbose "\t$expectfile: $i: $line_a" 3
131 verbose "\t/tmp/objdump.out: $i: $line_b" 3
132 if [regexp $line_a $line_b] then {
135 verbose -log "\t$expectfile: $i: $line_a"
136 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
142 if { [llength $list_a] != [llength $list_b] } {
143 verbose -log "Line count"
147 if $differences<1 then {
153 verbose -log "$exec_output"
160 # objdump_dymsymstuff
161 # Dump dynamic symbol stuff and make sure that it is sane.
163 proc objdump_dynsymstuff { objdump object expectfile } {
164 global DOBJDUMP_FLAGS
165 global version_output
169 if ![info exists DOBJDUMP_FLAGS] { set DOBJDUMP_FLAGS "" }
171 verbose -log "$objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
173 catch "exec $objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
174 set exec_output [prune_warnings $exec_output]
175 if [string match "" $exec_output] then {
177 # Now do a line-by-line comparison to effectively diff the darned things
178 # The stuff coming from the expectfile is actually a regex, so we can
179 # skip over the actual addresses and so forth. This is currently very
180 # simpleminded - it expects a one-to-one correspondence in terms of line
183 if [file exists $expectfile] then {
184 set file_a [open $expectfile r]
186 warning "$expectfile doesn't exist"
190 if [file exists $tmpdir/objdump.out] then {
191 set file_b [open $tmpdir/objdump.out r]
193 fail "$tmpdir/objdump.out doesn't exist"
197 verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
202 while { [gets $file_a line] != $eof } {
203 if [regexp "^#.*$" $line] then {
211 while { [gets $file_b line] != $eof } {
212 if [regexp "^#.*$" $line] then {
220 for { set i 0 } { $i < [llength $list_b] } { incr i } {
221 set line_b [lindex $list_b $i]
223 # The tests are rigged so that we should never export a symbol with the
224 # word 'hide' in it. Thus we just search for it, and bail if we find it.
225 if [regexp "hide" $line_b] then {
226 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
231 verbose "\t$expectfile: $i: $line_b" 3
233 # We can't assume that the sort is consistent across
234 # systems, so we must check each regexp. When we find a
235 # regexp, we null it out, so we don't match it twice.
236 for { set j 0 } { $j < [llength $list_a] } { incr j } {
237 set line_a [lindex $list_a $j]
239 if [regexp $line_a $line_b] then {
240 lreplace $list_a $j $j "CAN NOT MATCH"
245 if { $j >= [llength $list_a] } {
246 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
252 if { [llength $list_a] != [llength $list_b] } {
253 verbose -log "Line count"
257 if $differences<1 then {
263 verbose -log "$exec_output"
269 proc build_lib {test libname obj1 obj2 dynsymexp} {
277 if {![ld_simple_link $ld $tmpdir/$libname.so "$shared $tmpdir/$obj1 $tmpdir/$obj2"]} {
282 if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$dynsymexp]} {
289 proc build_exec { test execname obj1 obj2 flags dat dynsymexp symexp} {
298 if {![ld_link $ld $tmpdir/$execname "$flags $tmpdir/$obj1 $tmpdir/$obj2"]} {
303 if {![string match "" $dynsymexp]} then {
304 if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$dynsymexp]} {
310 if {![string match "" $symexp]} then {
311 if {![objdump_symstuff $objdump $tmpdir/$execname $srcdir/$subdir/$symexp]} {
317 # Run the resulting program
318 send_log "$tmpdir/$execname >$tmpdir/$execname.out\n"
319 verbose "$tmpdir/$execname >$tmpdir/$execname.out"
320 catch "exec $tmpdir/$execname >$tmpdir/$execname.out" exec_output
321 if ![string match "" $exec_output] then {
322 send_log "$exec_output\n"
323 verbose "$exec_output"
328 send_log "diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat\n"
329 verbose "diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat"
330 catch "exec diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat" exec_output
331 set exec_output [prune_warnings $exec_output]
333 if {![string match "" $exec_output]} then {
334 send_log "$exec_output\n"
335 verbose "$exec_output"
343 if [istarget mips*-*-*] {
346 # Unfortunately, the gcc argument is -fpic and the cc argument is
347 # -KPIC. We have to try both.
349 send_log "$CC $picflag\n"
350 verbose "$CC $picflag"
351 catch "exec $CC $picflag" exec_output
352 send_log "$exec_output\n"
353 verbose "--" "$exec_output"
354 if { [string match "*illegal option*" $exec_output] \
355 || [string match "*option ignored*" $exec_output] \
356 || [string match "*unrecognized option*" $exec_output] \
357 || [string match "*passed to ld*" $exec_output] } {
358 if [istarget *-*-sunos4*] {
365 verbose "Using $picflag to compile PIC code"
367 if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o] {
368 unresolved "ELF weak"
372 if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar.c $tmpdir/bar.o] {
373 unresolved "ELF weak"
377 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c $tmpdir/main.o] {
378 unresolved "ELF weak"
382 if {![ld_simple_link $ld $tmpdir/libbar.so "$shared $tmpdir/bar.o"]} {
387 build_lib "ELF DSO weak first" libfoo foo.o bar.o dso.dsym
388 build_lib "ELF DSO weak last" libfoo bar.o foo.o dso.dsym
389 build_lib "ELF DSO weak first DSO" libfoo foo.o libbar.so dsow.dsym
390 build_lib "ELF DSO weak last DSO" libfoo libbar.so foo.o dsow.dsym
391 build_exec "ELF weak first" foo main.o bar.o "" strong "" strong.sym
392 build_exec "ELF weak last" foo bar.o main.o "" strong "" strong.sym
393 build_exec "ELF weak first DSO" foo main.o libbar.so "-rpath ." weak weak.dsym ""
394 build_exec "ELF weak last DSO" foo libbar.so main.o "-rpath ." weak weak.dsym ""