1 # Expect script
for ld-weak tests
2 # Copyright
2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation
, Inc.
4 # This file is part of the GNU Binutils.
6 # This
program is free software
; you can redistribute it and
/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation
; either version
3 of the License
, or
9 #
(at your option
) any later version.
11 # This
program is distributed in the hope that it will be useful
,
12 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License
for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this
program; if not
, write to the Free Software
18 # Foundation
, Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
,
21 # Written by H.J. Lu
(hjl@gnu.org
)
22 # Eric Youngdale
(eric@andante.jic.com
)
25 # This test can only be run
if ld generates native executables.
26 if ![isnative
] then {return}
28 # This test can only be run
on a couple of ELF platforms.
29 # Square bracket expressions seem to confuse istarget.
30 # This is similar to the test that is used in
ld-shared
, BTW.
31 if { ![istarget alpha
*-*-linux
*] \
32 && ![istarget arm
*-*-linux
*] \
33 && ![istarget hppa
*64*-*-hpux
*] \
34 && ![istarget hppa
*-*-linux
*] \
35 && ![istarget i?
86-*-sysv4
*] \
36 && ![istarget i?
86-*-unixware
] \
37 && ![istarget i?
86-*-elf
*] \
38 && ![istarget i?
86-*-linux
*] \
39 && ![istarget ia64
-*-elf
*] \
40 && ![istarget ia64
-*-linux
*] \
41 && ![istarget m68k
-*-linux
*] \
42 && ![istarget mips
*-*-irix5
*] \
43 && ![istarget mips
*-*-linux
*] \
44 && ![istarget powerpc
-*-elf
*] \
45 && ![istarget powerpc
-*-linux
*] \
46 && ![istarget powerpc
-*-sysv4
*] \
47 && ![istarget sh\
[34\
]*-*-linux
*] \
48 && ![istarget sparc
*-*-elf
] \
49 && ![istarget sparc
*-*-solaris2
*] \
50 && ![istarget sparc
*-*-linux
*] } {
54 if { [istarget i?
86-*-linux
*aout
*] \
55 ||
[istarget i?
86-*-linux
*oldld
*] \
56 ||
[istarget m68k
-*-linux
*aout
*] } {
60 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
66 set DOBJDUMP_FLAGS
--dynamic
-syms
67 set SOBJDUMP_FLAGS
--syms
72 # Dump non
-dynamic symbol stuff and make sure that it is sane.
74 proc objdump_symstuff
{ objdump object expectfile
} {
80 if ![info exists SOBJDUMP_FLAGS
] { set SOBJDUMP_FLAGS
"" }
82 verbose
-log "$objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
84 catch
"exec $objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
85 set exec_output
[prune_warnings $exec_output
]
86 if [string match
"" $exec_output] then {
88 # Now
do a line
-by
-line comparison to effectively diff the darned things
89 # The stuff coming from the expectfile is actually a regex
, so we can
90 # skip over the actual addresses and so forth. This is currently very
91 # simpleminded
- it expects a one
-to
-one correspondence in terms of line
94 if [file
exists $expectfile
] then {
95 set file_a
[open $expectfile r
]
97 perror
"$expectfile doesn't exist"
101 if [file
exists $tmpdir
/objdump.out
] then {
102 set file_b
[open $tmpdir
/objdump.out r
]
104 perror
"$tmpdir/objdump.out doesn't exist"
108 verbose
"# Diff'ing: $expectfile $tmpdir/objdump.out" 2
113 while { [gets $file_a line
] != $eof
} {
114 if [regexp
"^#.*$" $line] then {
122 while { [gets $file_b line
] != $eof
} {
123 if [regexp
"^#.*$" $line] then {
131 for { set i
0 } { $i
< [llength $list_a
] } { incr i
} {
132 set line_a
[lindex $list_a $i
]
133 set line_b
[lindex $list_b $i
]
136 verbose
"\t$expectfile: $i: $line_a" 3
137 verbose
"\t/tmp/objdump.out: $i: $line_b" 3
138 if [regexp $line_a $line_b
] then {
141 verbose
-log "\t$expectfile: $i: $line_a"
142 verbose
-log "\t$tmpdir/objdump.out: $i: $line_b"
148 if { [llength $list_a
] != [llength $list_b
] } {
149 verbose
-log "Line count"
153 if $differences
<1 then {
159 verbose
-log "$exec_output"
166 # objdump_dymsymstuff
167 # Dump dynamic symbol stuff and make sure that it is sane.
169 proc objdump_dynsymstuff
{ objdump object expectfile
} {
170 global DOBJDUMP_FLAGS
171 global version_output
175 if ![info exists DOBJDUMP_FLAGS
] { set DOBJDUMP_FLAGS
"" }
177 verbose
-log "$objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
179 catch
"exec $objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
180 set exec_output
[prune_warnings $exec_output
]
181 if [string match
"" $exec_output] then {
183 # Now
do a line
-by
-line comparison to effectively diff the darned things
184 # The stuff coming from the expectfile is actually a regex
, so we can
185 # skip over the actual addresses and so forth. This is currently very
186 # simpleminded
- it expects a one
-to
-one correspondence in terms of line
189 if [file
exists $expectfile
] then {
190 set file_a
[open $expectfile r
]
192 warning
"$expectfile doesn't exist"
196 if [file
exists $tmpdir
/objdump.out
] then {
197 set file_b
[open $tmpdir
/objdump.out r
]
199 fail
"$tmpdir/objdump.out doesn't exist"
203 verbose
"# Diff'ing: $expectfile $tmpdir/objdump.out" 2
208 while { [gets $file_a line
] != $eof
} {
209 if [regexp
"^#.*$" $line] then {
217 while { [gets $file_b line
] != $eof
} {
218 if [regexp
"^#.*$" $line] then {
226 for { set i
0 } { $i
< [llength $list_b
] } { incr i
} {
227 set line_b
[lindex $list_b $i
]
229 # The tests are rigged so that we should never
export a symbol with the
230 # word
'hide' in it. Thus we just search
for it
, and bail
if we find it.
231 if [regexp
"hide" $line_b] then {
232 verbose
-log "\t$tmpdir/objdump.out: $i: $line_b"
237 verbose
"\t$expectfile: $i: $line_b" 3
239 # We can
't assume that the sort is consistent across
240 # systems, so we must check each regexp. When we find a
241 # regexp, we null it out, so we don't match it twice.
242 for { set j
0 } { $j
< [llength $list_a
] } { incr j
} {
243 set line_a
[lindex $list_a $j
]
245 if [regexp $line_a $line_b
] then {
246 lreplace $list_a $j $j
"CAN NOT MATCH"
251 if { $j
>= [llength $list_a
] } {
252 verbose
-log "\t$tmpdir/objdump.out: $i: $line_b"
258 if { [llength $list_a
] != [llength $list_b
] } {
259 verbose
-log "Line count"
263 if $differences
<1 then {
269 verbose
-log "$exec_output"
275 proc build_lib
{test libname objs dynsymexp
} {
285 set files
"$files $tmpdir/$obj"
288 if {![ld_simple_link $CC $tmpdir
/$libname.so
"$shared $files"]} {
293 if {![string match
"" $dynsymexp] \
294 && ![objdump_dynsymstuff $objdump $tmpdir
/$libname.so $srcdir
/$subdir
/$dynsymexp
]} {
301 proc build_exec
{ test execname objs flags dat dynsymexp symexp
} {
312 set files
"$files $tmpdir/$obj"
315 if {![ld_simple_link $CC $tmpdir
/$execname
"$flags $files"]} {
320 if {![string match
"" $dynsymexp]} then {
321 if {![objdump_dynsymstuff $objdump $tmpdir
/$execname $srcdir
/$subdir
/$dynsymexp
]} {
327 if {![string match
"" $symexp]} then {
328 if {![objdump_symstuff $objdump $tmpdir
/$execname $srcdir
/$subdir
/$symexp
]} {
334 # Run the resulting
program
335 send_log
"$tmpdir/$execname >$tmpdir/$execname.out\n"
336 verbose
"$tmpdir/$execname >$tmpdir/$execname.out"
337 catch
"exec $tmpdir/$execname >$tmpdir/$execname.out" exec_output
338 if ![string match
"" $exec_output] then {
339 send_log
"$exec_output\n"
340 verbose
"$exec_output"
345 send_log
"diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat\n"
346 verbose
"diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat"
347 catch
"exec diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat" exec_output
348 set exec_output
[prune_warnings $exec_output
]
350 if {![string match
"" $exec_output]} then {
351 send_log
"$exec_output\n"
352 verbose
"$exec_output"
360 if [istarget mips
*-*-*] {
363 # Unfortunately
, the gcc
argument is
-fpic and the cc
argument is
364 #
-KPIC. We have to try both.
366 send_log
"$CC $picflag\n"
367 verbose
"$CC $picflag"
368 catch
"exec $CC $picflag" exec_output
369 send_log
"$exec_output\n"
370 verbose
"--" "$exec_output"
371 if { [string match
"*illegal option*" $exec_output] \
372 ||
[string match
"*option ignored*" $exec_output] \
373 ||
[string match
"*unrecognized option*" $exec_output] \
374 ||
[string match
"*passed to ld*" $exec_output] } {
375 if [istarget
*-*-sunos4
*] {
382 verbose
"Using $picflag to compile PIC code"
384 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o] {
385 unresolved
"ELF weak"
389 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/bar.c $tmpdir/bar.o] {
390 unresolved
"ELF weak"
394 if ![ld_compile
"$CC $CFLAGS" $srcdir/$subdir/main.c $tmpdir/main.o] {
395 unresolved
"ELF weak"
399 if {![ld_simple_link $CC $tmpdir
/libbar.so
"$shared $tmpdir/bar.o"]} {
404 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/foo1a.c $tmpdir/foo1a.o] {
405 unresolved
"ELF weak"
409 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/foo1b.c $tmpdir/foo1b.o] {
410 unresolved
"ELF weak"
414 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o] {
415 unresolved
"ELF weak"
419 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o] {
420 unresolved
"ELF weak"
424 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o] {
425 unresolved
"ELF weak"
429 if ![ld_compile
"$CC $CFLAGS" $srcdir/$subdir/main1.c $tmpdir/main1.o] {
430 unresolved
"ELF weak"
434 if {![ld_simple_link $CC $tmpdir
/libfoo1a.so
"$shared $tmpdir/foo1a.o"]} {
439 if {![ld_simple_link $CC $tmpdir
/libfoo1b.so
"$shared $tmpdir/foo1b.o"]} {
444 if {![ld_simple_link $CC $tmpdir
/libbar1a.so
"$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} {
449 build_lib
"ELF DSO weak func first" libfoo "foo.o bar.o" dso.dsym
450 build_lib
"ELF DSO weak func last" libfoo "bar.o foo.o" dso.dsym
451 build_lib
"ELF DSO weak func first DSO" libfoo "foo.o libbar.so" dsow.dsym
452 build_lib
"ELF DSO weak func last DSO" libfoo "libbar.so foo.o" dsow.dsym
453 build_exec
"ELF weak func first" foo "main.o bar.o" "" strong "" strong.sym
454 build_exec
"ELF weak func last" foo "bar.o main.o" "" strong "" strong.sym
455 build_exec
"ELF weak func first DSO" foo "main.o libbar.so" "-Wl,-rpath,." weak weak.dsym ""
456 build_exec
"ELF weak func last DSO" foo "libbar.so main.o" "-Wl,-rpath,." weak weak.dsym ""
458 build_lib
"ELF DSO weak data first" libfoo "bar1a.o foo1a.o" dsodata.dsym
459 build_lib
"ELF DSO weak data last" libfoo "foo1a.o bar1a.o" dsodata.dsym
460 build_lib
"ELF DSO weak data first DSO" libfoo "main1.o libfoo1a.so" dsowdata.dsym
461 build_lib
"ELF DSO weak data last DSO" libfoo "libfoo1a.so main1.o" dsowdata.dsym
462 build_lib
"ELF DSO weak data first DSO common" libfoo "main1.o libfoo1b.so" dsowdata.dsym
463 build_lib
"ELF DSO weak data last DSO common" libfoo "libfoo1b.so main1.o" dsowdata.dsym
464 build_exec
"ELF weak data first" foo "main1.o bar1a.o foo1a.o" "" strongdata "" strongdata.sym
465 build_exec
"ELF weak data last" foo "foo1a.o main1.o bar1a.o" "" strongdata "" strongdata.sym
466 build_exec
"ELF weak data first common" foo "main1.o bar1a.o foo1b.o" "" strongdata "" strongcomm.sym
467 build_exec
"ELF weak data last common" foo "foo1b.o main1.o bar1a.o" "" strongdata "" strongcomm.sym
468 build_exec
"ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
469 build_exec
"ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
470 build_exec
"ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
471 build_exec
"ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
473 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_foo.o] {
474 unresolved
"ELF weak (size)"
478 if ![ld_compile
"$CC $CFLAGS $picflag" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o] {
479 unresolved
"ELF weak (size)"
483 build_lib
"ELF DSO small bar (size)" libsize_bar "size_bar.o" ""
484 build_lib
"ELF DSO foo with small bar (size)" libsize_foo "size_foo.o libsize_bar.so" ""
486 if ![ld_compile
"$CC $CFLAGS $picflag -DSIZE_BIG" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o] {
487 unresolved
"ELF weak (size)"
491 build_lib
"ELF DSO big bar (size)" libsize_bar "size_bar.o" ""
493 if ![ld_compile
"$CC $CFLAGS" $srcdir/$subdir/size_main.c $tmpdir/size_main.o] {
494 unresolved
"ELF weak (size)"
498 build_exec
"ELF weak size" size_main "size_main.o libsize_foo.so libsize_bar.so" "-Wl,-rpath,." size "" ""
501 run_dump_test $srcdir
/$subdir
/size2