* elf32-am33lin.c (elf32_am33lin_grok_prstatus): Add case
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elfweak / elfweak.exp
CommitLineData
16a57284 1# Expect script for ld-weak tests
5940a93c
TS
2# Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2010
3# Free Software Foundation, Inc.
16a57284 4#
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
16a57284 8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
16a57284 10# (at your option) any later version.
f96b4a7b 11#
16a57284
L
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
f96b4a7b 16#
16a57284
L
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
16a57284
L
21#
22# Written by H.J. Lu (hjl@gnu.org)
23# Eric Youngdale (eric@andante.jic.com)
24#
25
26# This test can only be run if ld generates native executables.
27if ![isnative] then {return}
28
29# This test can only be run on a couple of ELF platforms.
30# Square bracket expressions seem to confuse istarget.
31# This is similar to the test that is used in ld-shared, BTW.
99753d9d
AM
32if { ![istarget alpha*-*-linux*]
33 && ![istarget arm*-*-linux*]
34 && ![istarget hppa*64*-*-hpux*]
35 && ![istarget hppa*-*-linux*]
36 && ![istarget i?86-*-sysv4*]
37 && ![istarget i?86-*-unixware]
38 && ![istarget i?86-*-elf*]
39 && ![istarget i?86-*-linux*]
40 && ![istarget i?86-*-gnu*]
41 && ![istarget ia64-*-elf*]
42 && ![istarget ia64-*-linux*]
43 && ![istarget m68k-*-linux*]
44 && ![istarget mips*-*-irix5*]
45 && ![istarget mips*-*-linux*]
46 && ![istarget powerpc*-*-elf*]
47 && ![istarget powerpc*-*-linux*]
48 && ![istarget powerpc*-*-sysv4*]
49 && ![istarget sh\[34\]*-*-linux*]
50 && ![istarget sparc*-*-elf]
51 && ![istarget sparc*-*-solaris2*]
59758b1c 52 && ![istarget sparc*-*-linux*] } {
16a57284
L
53 return
54}
55
99753d9d
AM
56if { [istarget *-*-linux*aout*]
57 || [istarget *-*-linux*oldld*] } {
16a57284
L
58 return
59}
60
61if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
62 return
63}
64
65set diff diff
66set tmpdir tmpdir
67set DOBJDUMP_FLAGS --dynamic-syms
68set SOBJDUMP_FLAGS --syms
69set shared --shared
70
5940a93c 71
43fbacde 72# <http://www.gnu.org/software/hurd/open_issues/binutils.html#weak>
5940a93c
TS
73proc setup_xfail_gnu_hurd {} {
74 global target_triplet
75 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
76 switch -regexp $target_triplet {
77 ^\[^-\]*-\[^-\]*-gnu.*$ {
78 setup_xfail "*-*-*"
79 }
80 }
81}
82
16a57284
L
83#
84# objdump_symstuff
85# Dump non-dynamic symbol stuff and make sure that it is sane.
86#
87proc objdump_symstuff { objdump object expectfile } {
88 global SOBJDUMP_FLAGS
89 global version_output
90 global diff
91 global tmpdir
92
93 if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
94
95 verbose -log "$objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
96
97 catch "exec $objdump $SOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
98 set exec_output [prune_warnings $exec_output]
99 if [string match "" $exec_output] then {
100
101# Now do a line-by-line comparison to effectively diff the darned things
102# The stuff coming from the expectfile is actually a regex, so we can
103# skip over the actual addresses and so forth. This is currently very
104# simpleminded - it expects a one-to-one correspondence in terms of line
105# numbers.
106
107 if [file exists $expectfile] then {
108 set file_a [open $expectfile r]
109 } else {
110 perror "$expectfile doesn't exist"
111 return 0
112 }
113
114 if [file exists $tmpdir/objdump.out] then {
115 set file_b [open $tmpdir/objdump.out r]
116 } else {
117 perror "$tmpdir/objdump.out doesn't exist"
118 return 0
119 }
120
121 verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
122
123 set eof -1
124 set differences 0
125
126 while { [gets $file_a line] != $eof } {
127 if [regexp "^#.*$" $line] then {
128 continue
129 } else {
130 lappend list_a $line
131 }
132 }
133 close $file_a
134
135 while { [gets $file_b line] != $eof } {
136 if [regexp "^#.*$" $line] then {
137 continue
138 } else {
139 lappend list_b $line
140 }
141 }
142 close $file_b
143
144 for { set i 0 } { $i < [llength $list_a] } { incr i } {
145 set line_a [lindex $list_a $i]
146 set line_b [lindex $list_b $i]
147
148
149 verbose "\t$expectfile: $i: $line_a" 3
150 verbose "\t/tmp/objdump.out: $i: $line_b" 3
151 if [regexp $line_a $line_b] then {
152 continue
153 } else {
154 verbose -log "\t$expectfile: $i: $line_a"
155 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
156
157 return 0
158 }
159 }
160
161 if { [llength $list_a] != [llength $list_b] } {
162 verbose -log "Line count"
163 return 0
164 }
165
166 if $differences<1 then {
167 return 1
168 }
169
170 return 0
171 } else {
172 verbose -log "$exec_output"
173 return 0
174 }
175
176}
177
178#
179# objdump_dymsymstuff
180# Dump dynamic symbol stuff and make sure that it is sane.
181#
182proc objdump_dynsymstuff { objdump object expectfile } {
183 global DOBJDUMP_FLAGS
184 global version_output
185 global diff
186 global tmpdir
187
188 if ![info exists DOBJDUMP_FLAGS] { set DOBJDUMP_FLAGS "" }
189
190 verbose -log "$objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
191
192 catch "exec $objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out" exec_output
193 set exec_output [prune_warnings $exec_output]
194 if [string match "" $exec_output] then {
195
196# Now do a line-by-line comparison to effectively diff the darned things
197# The stuff coming from the expectfile is actually a regex, so we can
198# skip over the actual addresses and so forth. This is currently very
199# simpleminded - it expects a one-to-one correspondence in terms of line
200# numbers.
201
202 if [file exists $expectfile] then {
203 set file_a [open $expectfile r]
204 } else {
205 warning "$expectfile doesn't exist"
206 return 0
207 }
208
209 if [file exists $tmpdir/objdump.out] then {
210 set file_b [open $tmpdir/objdump.out r]
211 } else {
212 fail "$tmpdir/objdump.out doesn't exist"
213 return 0
214 }
215
216 verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
217
218 set eof -1
219 set differences 0
220
221 while { [gets $file_a line] != $eof } {
222 if [regexp "^#.*$" $line] then {
223 continue
224 } else {
225 lappend list_a $line
226 }
227 }
228 close $file_a
229
230 while { [gets $file_b line] != $eof } {
231 if [regexp "^#.*$" $line] then {
232 continue
233 } else {
234 lappend list_b $line
235 }
236 }
237 close $file_b
238
239 for { set i 0 } { $i < [llength $list_b] } { incr i } {
240 set line_b [lindex $list_b $i]
241
242# The tests are rigged so that we should never export a symbol with the
243# word 'hide' in it. Thus we just search for it, and bail if we find it.
244 if [regexp "hide" $line_b] then {
245 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
246
247 return 0
248 }
249
250 verbose "\t$expectfile: $i: $line_b" 3
251
252 # We can't assume that the sort is consistent across
253 # systems, so we must check each regexp. When we find a
254 # regexp, we null it out, so we don't match it twice.
255 for { set j 0 } { $j < [llength $list_a] } { incr j } {
256 set line_a [lindex $list_a $j]
257
258 if [regexp $line_a $line_b] then {
259 lreplace $list_a $j $j "CAN NOT MATCH"
260 break
261 }
262 }
263
264 if { $j >= [llength $list_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
bd7c9df6 288proc build_lib {test libname objs dynsymexp} {
b765d4e3 289 global CC
16a57284
L
290 global objdump
291 global tmpdir
292 global shared
293 global srcdir
294 global subdir
295
bd7c9df6
L
296 set files ""
297 foreach obj $objs {
298 set files "$files $tmpdir/$obj"
299 }
300
b765d4e3 301 if {![ld_simple_link $CC $tmpdir/$libname.so "$shared $files"]} {
16a57284
L
302 fail $test
303 return
304 }
305
99753d9d 306 if {![string match "" $dynsymexp]
a664545d 307 && ![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$dynsymexp]} {
16a57284
L
308 fail $test
309 return
310 }
311 pass $test
312}
313
bd7c9df6 314proc build_exec { test execname objs flags dat dynsymexp symexp} {
b765d4e3 315 global CC
16a57284
L
316 global objdump
317 global tmpdir
318 global shared
319 global srcdir
320 global subdir
321 global exec_output
322
bd7c9df6
L
323 set files ""
324 foreach obj $objs {
325 set files "$files $tmpdir/$obj"
326 }
327
b765d4e3 328 if {![ld_simple_link $CC $tmpdir/$execname "$flags $files"]} {
16a57284
L
329 fail "$test"
330 return
331 }
332
333 if {![string match "" $dynsymexp]} then {
334 if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$dynsymexp]} {
335 fail $test
336 return
337 }
338 }
339
340 if {![string match "" $symexp]} then {
341 if {![objdump_symstuff $objdump $tmpdir/$execname $srcdir/$subdir/$symexp]} {
342 fail $test
343 return
344 }
345 }
346
347 # Run the resulting program
348 send_log "$tmpdir/$execname >$tmpdir/$execname.out\n"
349 verbose "$tmpdir/$execname >$tmpdir/$execname.out"
350 catch "exec $tmpdir/$execname >$tmpdir/$execname.out" exec_output
351 if ![string match "" $exec_output] then {
352 send_log "$exec_output\n"
353 verbose "$exec_output"
354 fail $test
355 return
356 }
357
358 send_log "diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat\n"
359 verbose "diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat"
360 catch "exec diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat" exec_output
361 set exec_output [prune_warnings $exec_output]
362
363 if {![string match "" $exec_output]} then {
364 send_log "$exec_output\n"
365 verbose "$exec_output"
366 fail $test
367 return
368 }
369
370 pass $test
371}
372
373if [istarget mips*-*-*] {
374 set picflag ""
375} else {
376 # Unfortunately, the gcc argument is -fpic and the cc argument is
377 # -KPIC. We have to try both.
378 set picflag "-fpic"
379 send_log "$CC $picflag\n"
380 verbose "$CC $picflag"
381 catch "exec $CC $picflag" exec_output
382 send_log "$exec_output\n"
383 verbose "--" "$exec_output"
99753d9d
AM
384 if { [string match "*illegal option*" $exec_output]
385 || [string match "*option ignored*" $exec_output]
386 || [string match "*unrecognized option*" $exec_output]
16a57284
L
387 || [string match "*passed to ld*" $exec_output] } {
388 if [istarget *-*-sunos4*] {
389 set picflag "-pic"
390 } else {
391 set picflag "-KPIC"
392 }
393 }
394}
395verbose "Using $picflag to compile PIC code"
396
397if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o] {
398 unresolved "ELF weak"
399 return
400}
401
402if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar.c $tmpdir/bar.o] {
403 unresolved "ELF weak"
404 return
405}
406
407if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main.c $tmpdir/main.o] {
408 unresolved "ELF weak"
409 return
410}
411
b765d4e3 412if {![ld_simple_link $CC $tmpdir/libbar.so "$shared $tmpdir/bar.o"]} {
bd7c9df6
L
413 fail "ELF weak"
414 return
415}
416
417if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo1a.c $tmpdir/foo1a.o] {
418 unresolved "ELF weak"
419 return
420}
421
422if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/foo1b.c $tmpdir/foo1b.o] {
423 unresolved "ELF weak"
424 return
425}
426
b765d4e3 427if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o] {
bd7c9df6
L
428 unresolved "ELF weak"
429 return
430}
431
b765d4e3 432if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o] {
bd7c9df6
L
433 unresolved "ELF weak"
434 return
435}
436
b765d4e3 437if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o] {
bd7c9df6
L
438 unresolved "ELF weak"
439 return
440}
441
442if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/main1.c $tmpdir/main1.o] {
443 unresolved "ELF weak"
444 return
445}
446
b765d4e3 447if {![ld_simple_link $CC $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]} {
bd7c9df6
L
448 fail "ELF weak"
449 return
450}
451
b765d4e3 452if {![ld_simple_link $CC $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]} {
16a57284
L
453 fail "ELF weak"
454 return
455}
456
b765d4e3 457if {![ld_simple_link $CC $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} {
0c52a746
L
458 fail "ELF weak"
459 return
460}
461
bd7c9df6
L
462build_lib "ELF DSO weak func first" libfoo "foo.o bar.o" dso.dsym
463build_lib "ELF DSO weak func last" libfoo "bar.o foo.o" dso.dsym
bd7c9df6 464build_lib "ELF DSO weak func first DSO" libfoo "foo.o libbar.so" dsow.dsym
bd7c9df6
L
465build_lib "ELF DSO weak func last DSO" libfoo "libbar.so foo.o" dsow.dsym
466build_exec "ELF weak func first" foo "main.o bar.o" "" strong "" strong.sym
467build_exec "ELF weak func last" foo "bar.o main.o" "" strong "" strong.sym
5940a93c 468setup_xfail_gnu_hurd
b765d4e3 469build_exec "ELF weak func first DSO" foo "main.o libbar.so" "-Wl,-rpath,." weak weak.dsym ""
5940a93c 470setup_xfail_gnu_hurd
b765d4e3 471build_exec "ELF weak func last DSO" foo "libbar.so main.o" "-Wl,-rpath,." weak weak.dsym ""
bd7c9df6
L
472
473build_lib "ELF DSO weak data first" libfoo "bar1a.o foo1a.o" dsodata.dsym
474build_lib "ELF DSO weak data last" libfoo "foo1a.o bar1a.o" dsodata.dsym
0c52a746 475build_lib "ELF DSO weak data first DSO" libfoo "main1.o libfoo1a.so" dsowdata.dsym
0c52a746 476build_lib "ELF DSO weak data last DSO" libfoo "libfoo1a.so main1.o" dsowdata.dsym
0c52a746 477build_lib "ELF DSO weak data first DSO common" libfoo "main1.o libfoo1b.so" dsowdata.dsym
0c52a746 478build_lib "ELF DSO weak data last DSO common" libfoo "libfoo1b.so main1.o" dsowdata.dsym
bd7c9df6
L
479build_exec "ELF weak data first" foo "main1.o bar1a.o foo1a.o" "" strongdata "" strongdata.sym
480build_exec "ELF weak data last" foo "foo1a.o main1.o bar1a.o" "" strongdata "" strongdata.sym
481build_exec "ELF weak data first common" foo "main1.o bar1a.o foo1b.o" "" strongdata "" strongcomm.sym
482build_exec "ELF weak data last common" foo "foo1b.o main1.o bar1a.o" "" strongdata "" strongcomm.sym
5940a93c 483setup_xfail_gnu_hurd
b765d4e3 484build_exec "ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
5940a93c 485setup_xfail_gnu_hurd
b765d4e3 486build_exec "ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
5940a93c 487setup_xfail_gnu_hurd
b765d4e3 488build_exec "ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
5940a93c 489setup_xfail_gnu_hurd
b765d4e3 490build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,-rpath,." weakdata weakdata.dsym ""
a664545d
L
491
492if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_foo.o] {
493 unresolved "ELF weak (size)"
494 return
495}
496
497if ![ld_compile "$CC $CFLAGS $picflag" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o] {
498 unresolved "ELF weak (size)"
499 return
500}
501
502build_lib "ELF DSO small bar (size)" libsize_bar "size_bar.o" ""
503build_lib "ELF DSO foo with small bar (size)" libsize_foo "size_foo.o libsize_bar.so" ""
504
505if ![ld_compile "$CC $CFLAGS $picflag -DSIZE_BIG" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o] {
506 unresolved "ELF weak (size)"
507 return
508}
509
510build_lib "ELF DSO big bar (size)" libsize_bar "size_bar.o" ""
511
512if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/size_main.c $tmpdir/size_main.o] {
513 unresolved "ELF weak (size)"
514 return
515}
516
517build_exec "ELF weak size" size_main "size_main.o libsize_foo.so libsize_bar.so" "-Wl,-rpath,." size "" ""
5cfd5a0c
PB
518
519verbose "size2"
520run_dump_test $srcdir/$subdir/size2
This page took 0.454997 seconds and 4 git commands to generate.