* ld-scripts/weak.exp: New test.
[external/binutils.git] / ld / testsuite / ld-scripts / weak.exp
1 # Test weak symbols.
2 # By Ian Lance Taylor, Cygnus Solutions.
3
4 set testname "weak symbols"
5
6 # This test only works for ELF targets.  It ought to work for some
7 # a.out targets, but it doesn't.
8
9 if { ![istarget *-*-sysv4*] \
10      && ![istarget *-*-unixware*] \
11      && ![istarget *-*-elf*] \
12      && ![istarget *-*-linux*] \
13      && ![istarget *-*-irix5*] \
14      && ![istarget *-*-irix6*] \
15      && ![istarget *-*-solaris2*] } then {
16     return
17 }
18
19 if { [istarget *-*-linuxaout*] \
20      || [istarget *-*-linuxoldld*] } {
21     return
22 }
23
24 if {! [ld_assemble $as $srcdir/$subdir/weak1.s tmpdir/weak1.o]
25     || ! [ld_assemble $as $srcdir/$subdir/weak2.s tmpdir/weak2.o]} then {
26     # It's OK if .weak doesn't work on this target.
27     unresolved $testname
28     return
29 }
30
31 set weak_regexp_big \
32 ".*Contents of section .text:.*1000 00001008 0000200c 12121212 34343434.*Contents of section .data:.*2000 00001008 0000200c 56565656 78787878.*"
33
34 set weak_regexp_little \
35 ".*Contents of section .text:.*1000 08100000 0c200000 12121212 34343434.*Contents of section .data:.*2000 08100000 0c200000 56565656 78787878.*"
36
37 if {! [ld_simple_link $ld tmpdir/weak "-T $srcdir/$subdir/weak.t tmpdir/weak1.o tmpdir/weak2.o"] } then {
38     fail $testname
39 } else {
40     if {[which $objdump] == 0} then {
41         unresolved $testname
42         return
43     }
44
45     verbose -log "$objdump -s tmpdir/weak"
46     catch "exec $objdump -s tmpdir/weak" exec_output
47     set exec_output [prune_warnings $exec_output]
48     verbose -log $exec_output
49
50     if {[regexp $weak_regexp_big $exec_output] \
51         || [regexp $weak_regexp_little $exec_output] } then {
52         pass $testname
53     } else {
54         fail $testname
55     }
56 }