cbf6e4667a127549af8736933d91ecd36cfd45b1
[external/binutils.git] / ld / testsuite / ld-elf / sec64k.exp
1 # Expect script for tests for >64k sections
2 #   Copyright 2002, 2003, 2006 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # Written by Hans-Peter Nilsson (hp@axis.com)
19 #
20
21 # Exclude non-ELF targets.
22
23 if ![is_elf_format] {
24     return
25 }
26
27 # Test >64k sections, with and without -r.  First, create the assembly
28 # files.  Have a relocation to another section and one within the local
29 # section.
30
31 set test1 "64ksec-r"
32 set test2 "64ksec"
33
34 if { ![runtest_file_p $runtests $test1] \
35         && ![runtest_file_p $runtests $test2] } {
36     return
37 }
38
39 set sfiles {}
40 set max_sec 66000
41 set secs_per_file 1000
42 for { set i 0 } { $i < $max_sec / $secs_per_file } { incr i } {
43     set sfile "$objdir/tmpdir/sec64-$i.s"
44     lappend sfiles $sfile
45     if [catch { set ofd [open $sfile w] } x] {
46         perror "$x"
47         unresolved $test1
48         unresolved $test2
49         return
50     }
51
52     if { $i == 0 } {
53         puts $ofd " .global start"
54         puts $ofd "start:"
55         puts $ofd " .global _start"
56         puts $ofd "_start:"
57         puts $ofd " .global __start"
58         puts $ofd "__start:"
59         puts $ofd " .global main"
60         puts $ofd "main:"
61         puts $ofd " .global foo_0"
62         puts $ofd "foo_0: .dc.a 0"
63     }
64
65     # Make sure the used section is not covered by common linker scripts.
66     # They should get separate section entries even without -r.
67     puts $ofd " .altmacro"
68     puts $ofd " .macro sec secn, secp"
69     puts $ofd "  .section .foo.\\secn,\"ax\""
70     puts $ofd "  .global foo_\\secn"
71     puts $ofd "foo_\\secn:"
72     puts $ofd "  .dc.a foo_\\secp"
73     puts $ofd "bar_\\secn:"
74     puts $ofd "  .dc.a bar_\\secn"
75     puts $ofd " .endm"
76     puts $ofd " secn = [expr $i * $secs_per_file]"
77     puts $ofd " .rept $secs_per_file"
78     puts $ofd "  secn = secn + 1"
79     puts $ofd "  sec %(secn), %(secn-1)"
80     puts $ofd " .endr"
81
82     close $ofd
83 }
84
85 if [catch { set ofd [open "tmpdir/$test1.d" w] } x] {
86     perror "$x"
87     unresolved $test1
88     unresolved $test2
89     return
90 }
91
92 # The ld-r linked file will contain relocation-sections too, so make it
93 # half the size in order to try and keep the test-time down.
94
95 # The m32r target generates both REL and RELA relocs (for historical
96 # reasons) so the expected number of sections will be much more than
97 # 68000, which throws this particular test right off.
98 if {![istarget "m32r-*-*"]} then {
99     foreach sfile [lrange $sfiles 0 [expr [llength $sfiles] / 2]] {
100         puts $ofd "#source: $sfile"
101     }
102     puts $ofd "#ld: -r"
103     puts $ofd "#readelf: -W -Ss"
104     puts $ofd "There are 680.. section headers.*:"
105     puts $ofd "#..."
106     puts $ofd "  \\\[ 0\\\] .* 682\[0-9\]\[0-9\]\[ \]+0\[ \]+0"
107     puts $ofd "#..."
108     puts $ofd "  \\\[ \[0-9\]\\\] \.foo\.1\[ \]+PROGBITS\[ \]+.*"
109     puts $ofd "#..."
110     puts $ofd "  \\\[65279\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
111     puts $ofd "  \\\[65536\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
112     puts $ofd "#..."
113     puts $ofd " 340..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... "
114     puts $ofd "#..."
115     puts $ofd " 340..: 0+(2|4|8)\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[23\] bar_1$"
116     puts $ofd "#..."
117     puts $ofd ".* bar_34000$"
118     puts $ofd "#..."
119     # Global symbols are not in "alphanumeric" order, so we just check
120     # that the first and the last are present in any order (assuming no
121     # duplicates).
122     puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)$"
123     puts $ofd "#..."
124     puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)$"
125     puts $ofd "#pass"
126     close $ofd
127     run_dump_test "tmpdir/$test1"
128 }
129
130 if [catch { set ofd [open "tmpdir/$test2.d" w] } x] {
131     perror "$x"
132     unresolved $test2
133     return
134 }
135 foreach sfile $sfiles { puts $ofd "#source: $sfile" }
136 if { [istarget spu*-*-*] } {
137     puts $ofd "#ld: --local-store 0:0"
138 } else {
139     puts $ofd "#ld:"
140 }
141 puts $ofd "#readelf: -W -Ss"
142 puts $ofd "There are 660.. section headers.*:"
143 puts $ofd "#..."
144 puts $ofd "  \\\[ 0\\\] .* 662..\[ \]+0\[ \]+0"
145 puts $ofd "#..."
146 puts $ofd "  \\\[65279\\\] \\.foo\\.\[0-9\]+ .*"
147 puts $ofd "  \\\[65536\\\] \\.foo\\.\[0-9\]+ .*"
148 puts $ofd "#..."
149 puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+662.. "
150 puts $ofd "#..."
151 puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[0-9\] bar_1$"
152 puts $ofd "#..."
153 puts $ofd ".* bar_66000$"
154 puts $ofd "#..."
155 # Global symbols are not in "alphanumeric" order, so we just check
156 # that the first and the last are present in any order (assuming no
157 # duplicates).
158 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)$"
159 puts $ofd "#..."
160 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)$"
161 puts $ofd "#pass"
162 close $ofd
163 run_dump_test "tmpdir/$test2"
164
165 for { set i 1 } { $i < $max_sec / $secs_per_file } { incr i } {
166     catch "exec rm -f tmpdir/dump$i.o" status
167 }