]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/testsuite/gas/elf/elf.exp
gas: copy st_size only if unset
[thirdparty/binutils-gdb.git] / gas / testsuite / gas / elf / elf.exp
1 # Copyright (C) 2012-2022 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
16
17 #
18 # elf tests
19 #
20
21 proc run_elf_list_test { name suffix opts readelf_opts readelf_pipe } {
22 global READELF
23 global srcdir subdir
24 set testname "elf $name list"
25 set file $srcdir/$subdir/$name
26 gas_run ${name}.s "$opts -o dump.o" ">&dump.out"
27 if { ![string match "" $opts]
28 && [regexp_diff "dump.out" "${file}.l"] } then {
29 fail $testname
30 verbose "output is [file_contents "dump.out"]" 2
31 return
32 }
33 send_log "$READELF $readelf_opts dump.o $readelf_pipe > dump.out\n"
34 set status [gas_host_run "$READELF $readelf_opts dump.o" ">readelf.out"]
35 if { [lindex $status 0] != 0 || ![string match "" [lindex $status 1]] } then {
36 send_log "[lindex $status 1]\n"
37 fail $testname
38 return
39 }
40 catch "exec cat readelf.out $readelf_pipe > dump.out\n" comp_output
41 if ![string match "" $comp_output] then {
42 send_log "$comp_output\n"
43 fail $testname
44 return
45 }
46 verbose_eval {[file_contents "dump.out"]} 3
47 if { [regexp_diff "dump.out" "${file}.e${suffix}"] } then {
48 fail $testname
49 verbose "output is [file_contents "dump.out"]" 2
50 return
51 }
52 pass $testname
53 }
54
55 # We're testing bits in obj-elf -- don't run on anything else.
56 if { [is_elf_format] } then {
57 if { [is_elf_unused_section_symbols ] } {
58 set target_machine -unused
59 } else {
60 set target_machine ""
61 }
62 set dump_opts ""
63 if {[istarget "arc*-*-*"]} {
64 set target_machine -arc
65 }
66 if {[istarget "arm*-*-*"]} {
67 set target_machine -arm
68 }
69 if {[istarget "avr*-*-*"]} {
70 set dump_opts {{as -mno-link-relax}}
71 }
72 if {[istarget "csky*-*-*"]} {
73 set target_machine -csky
74 }
75 if {[istarget "m32r*-*-*"]} then {
76 set target_machine -m32r
77 }
78 if {[istarget "mips*-*-*"]} then {
79 set target_machine -mips
80 }
81 if {[istarget "msp430-*-*"]} then {
82 set target_machine -msp430
83 }
84 if {[istarget "pru-*-*"]} {
85 set dump_opts {{as -mno-link-relax}}
86 }
87 if {[istarget "riscv*-*-*"]} then {
88 set target_machine -riscv
89 set dump_opts {{as -mno-relax}}
90 }
91 if {[istarget "rl78-*-*"]} then {
92 set target_machine -rl78
93 }
94 if {[istarget "rx-*-*"]} then {
95 set target_machine -rx
96 }
97 if {[istarget "score-*-*"]} then {
98 set target_machine -score
99 }
100 if {[istarget "tic6x-*-*"]} then {
101 set target_machine -tic6x
102 }
103 if {[istarget "v850*-*-*"]} then {
104 set target_machine -v850
105 }
106 if {[istarget "xtensa*-*-*"]} then {
107 set target_machine -xtensa
108 set dump_opts {{as --no-link-relax}}
109 }
110
111 # The MN10300 and Xtensa ports disable the assembler's call frame
112 # optimization because it interfers with link-time relaxation of
113 # function prologues.
114 if {![istarget "mn10300-*-*"]
115 && ![istarget "am3*-*-*"]
116 && ![istarget "xtensa*-*-*"]
117 && ![istarget "msp430*-*-*"]
118 && ![istarget "nds32*-*-*"]
119 && ![istarget "am3*-*-*"]} then {
120 run_dump_test "ehopt0"
121 }
122 switch -glob $target_triplet {
123 m68k-*-* -
124 m68[03]??-*-* {
125 run_dump_test "file" { { as "--defsym m68k=1" } }
126 }
127 mmix-*-* {
128 run_dump_test "file" { { as "--defsym mmix=1" } }
129 }
130 xtensa*-*-* {
131 run_dump_test "file" { { as "--rename-section file.s=file.c" } }
132 }
133 default {
134 run_dump_test "file"
135 }
136 }
137 run_dump_test "file-2"
138 setup_xfail "nds32*-*-*"
139 run_dump_test "group0a"
140 run_dump_test "group0b"
141 run_dump_test "group0c"
142 run_dump_test "group1a"
143 run_dump_test "group1b"
144 run_dump_test "group2"
145 run_dump_test "group3"
146
147 run_dump_test "attach-1"
148 run_dump_test "attach-err"
149
150 switch -glob $target_triplet {
151 hppa64*-*-hpux* { }
152 riscv*-*-* { }
153 default {
154 run_dump_test "groupautoa"
155 }
156 }
157 switch -glob $target_triplet {
158 hppa64*-*-hpux* { }
159 riscv*-*-* { }
160 xtensa*-*-* { }
161 default {
162 run_dump_test "groupautob"
163 }
164 }
165 switch -glob $target_triplet {
166 alpha*-*-* { }
167 am3*-*-* { }
168 *c54x*-*-* { }
169 cr16*-*-* { }
170 crx*-*-* { }
171 h8300-*-* { }
172 hppa*-*-* { }
173 iq2000*-*-* { }
174 mips*-*-* { }
175 mn10200-*-* { }
176 mn10300-*-* { }
177 msp43*-*-* { }
178 rl78-*-* { }
179 riscv*-*-* { }
180 rx-*-* { }
181 loongarch*-*-* { }
182 default {
183 # The next test can fail if the target does not convert fixups
184 # against ordinary symbols into relocations against section symbols.
185 # This is usually revealed by the error message:
186 # symbol `sym' required but not present
187 setup_xfail "m681*-*-*" "m68hc*-*-*" "xgate-*-*" "vax-*-*" "avr-*-*"
188 run_dump_test redef
189 run_dump_test equ-reloc
190 }
191 }
192 run_dump_test "pseudo"
193 run_dump_test "section0"
194 run_dump_test "section1"
195 # The h8300 port issues a warning message for
196 # new sections created without atrributes.
197 if {! [istarget "h8300-*-*"]} then {
198 set as_flags "-al --generate-missing-build-notes=no"
199 switch -glob $target_triplet {
200 i*86-*-* -
201 x86_64-*-* {
202 set as_flags "$as_flags -mx86-used-note=no"
203 }
204 riscv*-*-* {
205 set as_flags "$as_flags -march-attr"
206 }
207 }
208 run_elf_list_test "section2" "$target_machine" "$as_flags" "-s" ""
209 }
210 run_dump_test "section3"
211 run_dump_test "section4"
212 if {! [istarget "h8300-*-*"] && ! [istarget "rx-*-*"]} then {
213 # The h8300 port issues a warning message for
214 # new sections created without atrributes.
215 # The RX port does not complain about changing the attributes of the
216 # .data and .bss sections since it does not use those names.
217 run_elf_list_test "section5" "" "-al -Z" "-SW" "| grep \" \\\\.test\\\[0-9\\\]\""
218 }
219 run_dump_test "struct"
220 if { ![istarget "alpha*-*-*"] } then {
221 # The alpha port uses .set for state, e.g. nomacro.
222 run_dump_test "symtab"
223 }
224 run_dump_test "symver"
225 run_dump_test "pr21661"
226 run_dump_test "pr14891"
227
228 # No indirect functions on non-GNU targets.
229 # The Visium and MSP set the ELF header's OSABI field to ELFOSABI_STANDALONE.
230 # The non-eabi ARM ports sets it to ELFOSABI_ARM.
231 # So for these targets we cannot include an IFUNC symbol type
232 # in the symbol type test.
233 # We also need to exclude targets that do not support unique objects.
234 if { [istarget "*-*-hpux*"]
235 || [istarget "arm*-*-*"]
236 || [istarget "mips*-*-*"]
237 || [istarget "msp*-*-*"]
238 || [istarget "visium-*-*"]
239 || ![supports_gnu_unique]
240 } then {
241 # hppa64 has a non-standard common directive
242 if { ![istarget "hppa64*-*-hpux*"] } then {
243 run_elf_list_test "type-noifunc" "" "" "-s" "| grep \"1 *\\\[FONTC\\\]\""
244 }
245 } else {
246 run_dump_test ifunc-1
247 run_elf_list_test "type" "" "" "-s" "| grep \"1 *\\\[FIONTCU\\\]\""
248 run_elf_list_test "type-2" "" "--warn" "-s" "| grep \"0 *\\\[FIONT\\\]\""
249 }
250
251 run_dump_test "section6"
252 run_dump_test "section7"
253 run_dump_test "section8"
254 run_dump_test "section9"
255 run_dump_test "section10"
256 run_dump_test "section11"
257 run_dump_test "section12a"
258 run_dump_test "section12b"
259 run_dump_test "section13"
260 run_dump_test "section14"
261 run_dump_test "section15"
262 run_dump_test "section16a"
263 run_dump_test "section16b"
264 run_dump_test "section17"
265 run_dump_test "section18"
266 run_dump_test "section19"
267 run_dump_test "section20"
268 run_dump_test "section21"
269 run_dump_test "section22"
270 run_dump_test "section23a"
271 run_dump_test "section23b"
272 run_dump_test "section24a"
273 run_dump_test "section24b"
274 run_dump_test "section25"
275 run_dump_test "section26"
276 run_dump_test "section27"
277 run_dump_test "section28"
278 run_dump_test "section29"
279 run_dump_test "sh-link-zero"
280 run_dump_test "size"
281 run_dump_test "dwarf2-1" $dump_opts
282 run_dump_test "dwarf2-2" $dump_opts
283 run_dump_test "dwarf2-3" $dump_opts
284 run_dump_test "dwarf2-4" $dump_opts
285 run_dump_test "dwarf2-5" $dump_opts
286 run_dump_test "dwarf2-6" $dump_opts
287 run_dump_test "dwarf2-7" $dump_opts
288 run_dump_test "dwarf2-8" $dump_opts
289 run_dump_test "dwarf2-9" $dump_opts
290 run_dump_test "dwarf2-10" $dump_opts
291 run_dump_test "dwarf2-11" $dump_opts
292 run_dump_test "dwarf2-12" $dump_opts
293 run_dump_test "dwarf2-13" $dump_opts
294 run_dump_test "dwarf2-14" $dump_opts
295 run_dump_test "dwarf2-15" $dump_opts
296 run_dump_test "dwarf2-16" $dump_opts
297 run_dump_test "dwarf2-17" $dump_opts
298 run_dump_test "dwarf2-18" $dump_opts
299 run_dump_test "dwarf2-19" $dump_opts
300 run_dump_test "dwarf2-20" $dump_opts
301 run_dump_test "dwarf2-21" $dump_opts
302 run_dump_test "dwarf-5-file0" $dump_opts
303 run_dump_test "dwarf-5-file0-2" $dump_opts
304 run_dump_test "dwarf-5-file0-3" $dump_opts
305 run_dump_test "dwarf-5-dir0" $dump_opts
306 run_dump_test "dwarf-5-loc0" $dump_opts
307 run_dump_test "dwarf-4-cu" $dump_opts
308 run_dump_test "dwarf-5-cu" $dump_opts
309 run_dump_test "dwarf-5-nop-for-line-table" $dump_opts
310 run_dump_test "dwarf-5-irp" $dump_opts
311 run_dump_test "pr25917"
312 run_dump_test "bss"
313 run_dump_test "bad-bss"
314 run_dump_test "bad-section-flag"
315 run_dump_test "bad-size"
316 run_dump_test "bad-group"
317 run_dump_test "pr27355"
318
319 run_dump_test "syms"
320 run_dump_test "startof"
321
322 run_dump_test "missing-build-notes"
323
324 run_dump_test "common1"
325 run_dump_test "common2"
326
327 # hpux has a non-standard common directive.
328 if { ![istarget "*-*-hpux*"] } then {
329 run_dump_test "common3a"
330 run_dump_test "common3b"
331 run_dump_test "common4a"
332 run_dump_test "common4b"
333 run_dump_test "common5a"
334 run_dump_test "common5b"
335 run_dump_test "common5c"
336 run_dump_test "common5d"
337 }
338
339 run_dump_test "strtab"
340
341 run_dump_test "bignums"
342 run_dump_test "section-symbol-redef"
343 run_dump_test "pr27228"
344 }