* ld-elf/elf.exp: Renamed from sec64k.exp. Add test_list loop.
[binutils.git] / ld / testsuite / ld-elf / elf.exp
blob0914695e5753d70a38bbc9b248573c9c921170f4
1 # Expect script for various ELF tests.
2 # Copyright 2002 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 Hans-Peter Nilsson (hp@axis.com)
21 # Exclude non-ELF targets.
23 if { ![istarget *-*-linux*] \
24 && ![istarget *-*-gnu] \
25 && ![istarget hppa*64*-*-hpux*] \
26 && ![istarget *-*-elf] } {
27 return
30 if { [istarget *-*-linux*aout*] \
31 || [istarget *-*-linux*oldld*] } {
32 return
35 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
36 foreach t $test_list {
37 # We need to strip the ".d", but can leave the dirname.
38 verbose [file rootname $t]
39 run_dump_test [file rootname $t]
43 # Test >64k sections, with and without -r.
45 # Per-port excludes, since this test takes an overwhelmingly long time
46 # currently.
47 if { ![istarget cris-*-*] } {
48 return
51 # First, create the assembly files. Have a relocation to another
52 # section and one within the local section.
54 set test1 "64ksec-r"
55 set test2 "64ksec"
57 if { ![runtest_file_p $runtests $test1] \
58 && ![runtest_file_p $runtests $test2] } {
59 return
62 set sfiles {}
63 set max_sec 66000
64 set secs_per_file 1000
65 set secn 0
66 for { set i 0 } { $i < $max_sec / $secs_per_file } { incr i } {
67 set sfile "$objdir/tmpdir/sec64-$i.s"
68 lappend sfiles $sfile
69 if [catch { set ofd [open $sfile w] } x] {
70 perror "$x"
71 unresolved $test1
72 unresolved $test2
73 return
76 if { $secn == 0 } {
77 puts $ofd " .global _start"
78 puts $ofd "_start:"
79 puts $ofd " .global foo_0"
80 puts $ofd "foo_0: .long 0"
83 # Make sure the used section is not covered by common linker scripts.
84 # They should get separate section entries even without -r.
85 for { set j 0 } { $j < $secs_per_file } { incr j } {
86 incr secn
87 puts $ofd " .section .foo.$secn,\"ax\""
88 puts $ofd " .global foo_$secn"
89 puts $ofd "foo_$secn:"
90 puts $ofd " .long foo_[expr $secn - 1]"
91 puts $ofd "bar_$secn:"
92 puts $ofd " .long bar_$secn"
95 close $ofd
98 if [catch { set ofd [open "tmpdir/$test1.d" w] } x] {
99 perror "$x"
100 unresolved $test1
101 unresolved $test2
102 return
105 # The ld-r linked file will contain relocation-sections too, so make it
106 # half the size in order to try and keep the test-time down.
107 foreach sfile [lrange $sfiles 0 [expr [llength $sfiles] / 2]] {
108 puts $ofd "#source: $sfile"
110 puts $ofd "#ld: -r"
111 puts $ofd "#readelf: -W -Ss"
112 puts $ofd "There are 680.. section headers.*:"
113 puts $ofd "#..."
114 puts $ofd " \\\[ 0\\\] .* 682\[0-9\]\[0-9\]\[ \]+0\[ \]+0"
115 puts $ofd "#..."
116 puts $ofd " \\\[ \[0-9\]\\\] \.foo\.1\[ \]+PROGBITS\[ \]+.*"
117 puts $ofd "#..."
118 puts $ofd " \\\[65279\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
119 puts $ofd " \\\[65536\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
120 puts $ofd "#..."
121 puts $ofd " 680..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... "
122 puts $ofd "#..."
123 puts $ofd " 680..: 0+4\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+2 bar_1"
124 puts $ofd "#..."
125 puts $ofd ".* bar_34000"
126 puts $ofd "#..."
127 # Global symbols are not in "alphanumeric" order, so we just check
128 # that the first and the last are present in any order (assuming no
129 # duplicates).
130 puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)"
131 puts $ofd "#..."
132 puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)"
133 puts $ofd "#pass"
134 close $ofd
135 run_dump_test "tmpdir/$test1"
137 if [catch { set ofd [open "tmpdir/$test2.d" w] } x] {
138 perror "$x"
139 unresolved $test2
140 return
142 foreach sfile $sfiles { puts $ofd "#source: $sfile" }
143 puts $ofd "#ld:"
144 puts $ofd "#readelf: -W -Ss"
145 puts $ofd "There are 660.. section headers.*:"
146 puts $ofd "#..."
147 puts $ofd " \\\[ 0\\\] .* 662..\[ \]+0\[ \]+0"
148 puts $ofd "#..."
149 puts $ofd " \\\[65279\\\] \\.foo\\.\[0-9\]+ .*"
150 puts $ofd " \\\[65536\\\] \\.foo\\.\[0-9\]+ .*"
151 puts $ofd "#..."
152 puts $ofd " 660..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+662.. "
153 puts $ofd "#..."
154 puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[0-9\] bar_1"
155 puts $ofd "#..."
156 puts $ofd ".* bar_66000"
157 puts $ofd "#..."
158 # Global symbols are not in "alphanumeric" order, so we just check
159 # that the first and the last are present in any order (assuming no
160 # duplicates).
161 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)"
162 puts $ofd "#..."
163 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)"
164 puts $ofd "#pass"
165 close $ofd
166 run_dump_test "tmpdir/$test2"