Remove GOTOFF in ld-i386/nogot1.s.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elfweak / elfweak.exp
CommitLineData
16a57284 1# Expect script for ld-weak tests
aa820537 2# Copyright 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
16a57284 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
16a57284 7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
16a57284 9# (at your option) any later version.
f96b4a7b 10#
16a57284
L
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.
f96b4a7b 15#
16a57284
L
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
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
16a57284
L
20#
21# Written by H.J. Lu (hjl@gnu.org)
22# Eric Youngdale (eric@andante.jic.com)
23#
24
25# This test can only be run if ld generates native executables.
26if ![isnative] then {return}
27
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.
5c449c3f 31if { ![istarget alpha*-*-linux*] \
59758b1c 32 && ![istarget arm*-*-linux*] \
5c449c3f 33 && ![istarget hppa*64*-*-hpux*] \
19c7c582
AM
34 && ![istarget hppa*-*-linux*] \
35 && ![istarget i?86-*-sysv4*] \
16a57284
L
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*] \
59758b1c 43 && ![istarget mips*-*-linux*] \
16a57284
L
44 && ![istarget powerpc-*-elf*] \
45 && ![istarget powerpc-*-linux*] \
46 && ![istarget powerpc-*-sysv4*] \
59758b1c 47 && ![istarget sh\[34\]*-*-linux*] \
16a57284
L
48 && ![istarget sparc*-*-elf] \
49 && ![istarget sparc*-*-solaris2*] \
59758b1c 50 && ![istarget sparc*-*-linux*] } {
16a57284
L
51 return
52}
53
54if { [istarget i?86-*-linux*aout*] \
55 || [istarget i?86-*-linux*oldld*] \
56 || [istarget m68k-*-linux*aout*] } {
57 return
58}
59
60if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
61 return
62}
63
64set diff diff
65set tmpdir tmpdir
66set DOBJDUMP_FLAGS --dynamic-syms
67set SOBJDUMP_FLAGS --syms
68set shared --shared
69
70#
71# objdump_symstuff
72# Dump non-dynamic symbol stuff and make sure that it is sane.
73#
74proc objdump_symstuff { objdump object expectfile } {
75 global SOBJDUMP_FLAGS
76 global version_output
77 global diff
78 global tmpdir
79
80 if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
81
82 verbose -log "$objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
83
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 {
87
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
92# numbers.
93
94 if [file exists $expectfile] then {
95 set file_a [open $expectfile r]
96 } else {
97 perror "$expectfile doesn't exist"
98 return 0
99 }
100
101 if [file exists $tmpdir/objdump.out] then {
102 set file_b [open $tmpdir/objdump.out r]
103 } else {
104 perror "$tmpdir/objdump.out doesn't exist"
105 return 0
106 }
107
108 verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
109
110 set eof -1
111 set differences 0
112
113 while { [gets $file_a line] != $eof } {
114 if [regexp "^#.*$" $line] then {
115 continue
116 } else {
117 lappend list_a $line
118 }
119 }
120 close $file_a
121
122 while { [gets $file_b line] != $eof } {
123 if [regexp "^#.*$" $line] then {
124 continue
125 } else {
126 lappend list_b $line
127 }
128 }
129 close $file_b
130
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]
134
135
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 {
139 continue
140 } else {
141 verbose -log "\t$expectfile: $i: $line_a"
142 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
143
144 return 0
145 }
146 }
147
148 if { [llength $list_a] != [llength $list_b] } {
149 verbose -log "Line count"
150 return 0
151 }
152
153 if $differences<1 then {
154 return 1
155 }
156
157 return 0
158 } else {
159 verbose -log "$exec_output"
160 return 0
161 }
162
163}
164
165#
166# objdump_dymsymstuff
167# Dump dynamic symbol stuff and make sure that it is sane.
168#
169proc objdump_dynsymstuff { objdump object expectfile } {
170 global DOBJDUMP_FLAGS
171 global version_output
172 global diff
173 global tmpdir
174
175 if ![info exists DOBJDUMP_FLAGS] { set DOBJDUMP_FLAGS "" }
176
177 verbose -log "$objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
178
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 {
182
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
187# numbers.
188
189 if [file exists $expectfile] then {
190 set file_a [open $expectfile r]
191 } else {
192 warning "$expectfile doesn't exist"
193 return 0
194 }
195
196 if [file exists $tmpdir/objdump.out] then {
197 set file_b [open $tmpdir/objdump.out r]
198 } else {
199 fail "$tmpdir/objdump.out doesn't exist"
200 return 0
201 }
202
203 verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
204
205 set eof -1
206 set differences 0
207
208 while { [gets $file_a line] != $eof } {
209 if [regexp "^#.*$" $line] then {
210 continue
211 } else {
212 lappend list_a $line
213 }
214 }
215 close $file_a
216
217 while { [gets $file_b line] != $eof } {
218 if [regexp "^#.*$" $line] then {
219 continue
220 } else {
221 lappend list_b $line
222 }
223 }
224 close $file_b
225
226 for { set i 0 } { $i < [llength $list_b] } { incr i } {
227 set line_b [lindex $list_b $i]
228
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"
233
234 return 0
235 }
236
237 verbose "\t$expectfile: $i: $line_b" 3
238
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]
244
245 if [regexp $line_a $line_b] then {
246 lreplace $list_a $j $j "CAN NOT MATCH"
247 break
248 }
249 }
250
251 if { $j >= [llength $list_a] } {
252 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
253
254 return 0
255 }
256 }
257
258 if { [llength $list_a] != [llength $list_b] } {
259 verbose -log "Line count"
260 return 0
261 }
262
263 if $differences<1 then {
264 return 1
265 }
266
267 return 0
268 } else {
269 verbose -log "$exec_output"
270 return 0
271 }
272
273}
274
bd7c9df6 275proc build_lib {test libname objs dynsymexp} {
b765d4e3 276 global CC
16a57284
L
277 global objdump
278 global tmpdir
279 global shared
280 global srcdir
281 global subdir
282
bd7c9df6
L
283 set files ""
284 foreach obj $objs {
285 set files "$files $tmpdir/$obj"
286 }
287
b765d4e3 288 if {![ld_simple_link $CC $tmpdir/$libname.so "$shared $files"]} {
16a57284
L
289 fail $test
290 return
291 }
292
a664545d
L
293 if {![string match "" $dynsymexp] \
294 && ![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$dynsymexp]} {
16a57284
L
295 fail $test
296 return
297 }
298 pass $test
299}
300
bd7c9df6 301proc build_exec { test execname objs flags dat dynsymexp symexp} {
b765d4e3 302 global CC
16a57284
L
303 global objdump
304 global tmpdir
305 global shared
306 global srcdir
307 global subdir
308 global exec_output
309
bd7c9df6
L
310 set files ""
311 foreach obj $objs {
312 set files "$files $tmpdir/$obj"
313 }
314
b765d4e3 315 if {![ld_simple_link $CC $tmpdir/$execname "$flags $files"]} {
16a57284
L
316 fail "$test"
317 return
318 }
319
320 if {![string match "" $dynsymexp]} then {
321 if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$dynsymexp]} {
322 fail $test
323 return
324 }
325 }
326
327 if {![string match "" $symexp]} then {
328 if {![objdump_symstuff $objdump $tmpdir/$execname $srcdir/$subdir/$symexp]} {
329 fail $test
330 return
331 }
332 }
333
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"
341 fail $test
342 return
343 }
344
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]
349
350 if {![string match "" $exec_output]} then {
351 send_log "$exec_output\n"
352 verbose "$exec_output"
353 fail $test
354 return
355 }
356
357 pass $test
358}
359
360if [istarget mips*-*-*] {
361 set picflag ""
362} else {
363 # Unfortunately, the gcc argument is -fpic and the cc argument is
364 # -KPIC. We have to try both.
365 set picflag "-fpic"
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*] {
376 set picflag "-pic"
377 } else {
378 set picflag "-KPIC"
379 }
380 }
381}
382verbose "Using $picflag to compile PIC code"
383
384if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o] {
385 unresolved "ELF weak"
386 return
387}
388
389if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar.c $tmpdir/bar.o] {
390 unresolved "ELF weak"
391 return
392}
393
394if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c $tmpdir/main.o] {
395 unresolved "ELF weak"
396 return
397}
398
b765d4e3 399if {![ld_simple_link $CC $tmpdir/libbar.so "$shared $tmpdir/bar.o"]} {
bd7c9df6
L
400 fail "ELF weak"
401 return
402}
403
404if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo1a.c $tmpdir/foo1a.o] {
405 unresolved "ELF weak"
406 return
407}
408
409if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo1b.c $tmpdir/foo1b.o] {
410 unresolved "ELF weak"
411 return
412}
413
b765d4e3 414if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o] {
bd7c9df6
L
415 unresolved "ELF weak"
416 return
417}
418
b765d4e3 419if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o] {
bd7c9df6
L
420 unresolved "ELF weak"
421 return
422}
423
b765d4e3 424if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o] {
bd7c9df6
L
425 unresolved "ELF weak"
426 return
427}
428
429if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main1.c $tmpdir/main1.o] {
430 unresolved "ELF weak"
431 return
432}
433
b765d4e3 434if {![ld_simple_link $CC $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]} {
bd7c9df6
L
435 fail "ELF weak"
436 return
437}
438
b765d4e3 439if {![ld_simple_link $CC $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]} {
16a57284
L
440 fail "ELF weak"
441 return
442}
443
b765d4e3 444if {![ld_simple_link $CC $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} {
0c52a746
L
445 fail "ELF weak"
446 return
447}
448
bd7c9df6
L
449build_lib "ELF DSO weak func first" libfoo "foo.o bar.o" dso.dsym
450build_lib "ELF DSO weak func last" libfoo "bar.o foo.o" dso.dsym
bd7c9df6 451build_lib "ELF DSO weak func first DSO" libfoo "foo.o libbar.so" dsow.dsym
bd7c9df6
L
452build_lib "ELF DSO weak func last DSO" libfoo "libbar.so foo.o" dsow.dsym
453build_exec "ELF weak func first" foo "main.o bar.o" "" strong "" strong.sym
454build_exec "ELF weak func last" foo "bar.o main.o" "" strong "" strong.sym
b765d4e3
L
455build_exec "ELF weak func first DSO" foo "main.o libbar.so" "-Wl,-rpath,." weak weak.dsym ""
456build_exec "ELF weak func last DSO" foo "libbar.so main.o" "-Wl,-rpath,." weak weak.dsym ""
bd7c9df6
L
457
458build_lib "ELF DSO weak data first" libfoo "bar1a.o foo1a.o" dsodata.dsym
459build_lib "ELF DSO weak data last" libfoo "foo1a.o bar1a.o" dsodata.dsym
0c52a746 460build_lib "ELF DSO weak data first DSO" libfoo "main1.o libfoo1a.so" dsowdata.dsym
0c52a746 461build_lib "ELF DSO weak data last DSO" libfoo "libfoo1a.so main1.o" dsowdata.dsym
0c52a746 462build_lib "ELF DSO weak data first DSO common" libfoo "main1.o libfoo1b.so" dsowdata.dsym
0c52a746 463build_lib "ELF DSO weak data last DSO common" libfoo "libfoo1b.so main1.o" dsowdata.dsym
bd7c9df6
L
464build_exec "ELF weak data first" foo "main1.o bar1a.o foo1a.o" "" strongdata "" strongdata.sym
465build_exec "ELF weak data last" foo "foo1a.o main1.o bar1a.o" "" strongdata "" strongdata.sym
466build_exec "ELF weak data first common" foo "main1.o bar1a.o foo1b.o" "" strongdata "" strongcomm.sym
467build_exec "ELF weak data last common" foo "foo1b.o main1.o bar1a.o" "" strongdata "" strongcomm.sym
b765d4e3
L
468build_exec "ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
469build_exec "ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
470build_exec "ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
471build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
a664545d
L
472
473if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_foo.o] {
474 unresolved "ELF weak (size)"
475 return
476}
477
478if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o] {
479 unresolved "ELF weak (size)"
480 return
481}
482
483build_lib "ELF DSO small bar (size)" libsize_bar "size_bar.o" ""
484build_lib "ELF DSO foo with small bar (size)" libsize_foo "size_foo.o libsize_bar.so" ""
485
486if ![ld_compile "$CC $CFLAGS $picflag -DSIZE_BIG" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o] {
487 unresolved "ELF weak (size)"
488 return
489}
490
491build_lib "ELF DSO big bar (size)" libsize_bar "size_bar.o" ""
492
493if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/size_main.c $tmpdir/size_main.o] {
494 unresolved "ELF weak (size)"
495 return
496}
497
498build_exec "ELF weak size" size_main "size_main.o libsize_foo.so libsize_bar.so" "-Wl,-rpath,." size "" ""
5cfd5a0c
PB
499
500verbose "size2"
501run_dump_test $srcdir/$subdir/size2
This page took 0.424157 seconds and 4 git commands to generate.