]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/testsuite/gas/elf/elf.exp
c42cef8160e3063bff74f526d9c166881843b9f7
[thirdparty/binutils-gdb.git] / gas / testsuite / gas / elf / elf.exp
1 # Copyright (C) 2012-2023 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 "loongarch*-*-*"]} then {
76 set dump_opts {{as -mno-relax}}
77 }
78 if {[istarget "m32r*-*-*"]} then {
79 set target_machine -m32r
80 }
81 if {[istarget "mips*-*-*"]} then {
82 set target_machine -mips
83 }
84 if {[istarget "msp430-*-*"]} then {
85 set target_machine -msp430
86 }
87 if {[istarget "pru-*-*"]} {
88 set dump_opts {{as -mno-link-relax}}
89 }
90 if {[istarget "riscv*-*-*"]} then {
91 set target_machine -riscv
92 set dump_opts {{as -mno-relax}}
93 }
94 if {[istarget "rl78-*-*"]} then {
95 set target_machine -rl78
96 }
97 if {[istarget "rx-*-*"]} then {
98 set target_machine -rx
99 set dump_opts {{as -muse-conventional-section-names}}
100 }
101 if {[istarget "score-*-*"]} then {
102 set target_machine -score
103 }
104 if {[istarget "tic6x-*-*"]} then {
105 set target_machine -tic6x
106 }
107 if {[istarget "v850*-*-*"]} then {
108 set target_machine -v850
109 }
110 if {[istarget "xtensa*-*-*"]} then {
111 set target_machine -xtensa
112 set dump_opts {{as --no-link-relax}}
113 }
114
115 # The MN10300 and Xtensa ports disable the assembler's call frame
116 # optimization because it interfers with link-time relaxation of
117 # function prologues.
118 if {![istarget "mn10300-*-*"]
119 && ![istarget "am3*-*-*"]
120 && ![istarget "xtensa*-*-*"]
121 && ![istarget "msp430*-*-*"]
122 && ![istarget "nds32*-*-*"]
123 && ![istarget "am3*-*-*"]} then {
124 run_dump_test "ehopt0"
125 }
126 switch -glob $target_triplet {
127 m68k-*-* -
128 m68[03]??-*-* {
129 run_dump_test "file" { { as "--defsym m68k=1" } }
130 }
131 mmix-*-* {
132 run_dump_test "file" { { as "--defsym mmix=1" } }
133 }
134 xtensa*-*-* {
135 run_dump_test "file" { { as "--rename-section file.s=file.c" } }
136 }
137 default {
138 run_dump_test "file"
139 }
140 }
141 run_dump_test "file-2"
142 setup_xfail "nds32*-*-*"
143 run_dump_test "group0a"
144 run_dump_test "group0b"
145 run_dump_test "group0c"
146 run_dump_test "group1a" $dump_opts
147 run_dump_test "group1b"
148 run_dump_test "group2"
149 run_dump_test "group3"
150
151 run_dump_test "attach-1"
152 run_dump_test "attach-err"
153
154 switch -glob $target_triplet {
155 hppa64*-*-hpux* { }
156 riscv*-*-* { }
157 default {
158 run_dump_test "groupautoa" $dump_opts
159 }
160 }
161 switch -glob $target_triplet {
162 hppa64*-*-hpux* { }
163 riscv*-*-* { }
164 xtensa*-*-* { }
165 default {
166 run_dump_test "groupautob"
167 }
168 }
169 switch -glob $target_triplet {
170 alpha*-*-* { }
171 am3*-*-* { }
172 *c54x*-*-* { }
173 cr16*-*-* { }
174 crx*-*-* { }
175 h8300-*-* { }
176 hppa*-*-* { }
177 iq2000*-*-* { }
178 mips*-*-* { }
179 mn10200-*-* { }
180 mn10300-*-* { }
181 msp43*-*-* { }
182 rl78-*-* { }
183 riscv*-*-* { }
184 rx-*-* { }
185 loongarch*-*-* { }
186 default {
187 # The next test can fail if the target does not convert fixups
188 # against ordinary symbols into relocations against section symbols.
189 # This is usually revealed by the error message:
190 # symbol `sym' required but not present
191 setup_xfail "m681*-*-*" "m68hc*-*-*" "xgate-*-*" "vax-*-*" "avr-*-*"
192 run_dump_test redef
193 run_dump_test equ-reloc
194 }
195 }
196 run_dump_test "pseudo"
197 run_dump_test "section0"
198 run_dump_test "section1"
199 # The h8300 port issues a warning message for
200 # new sections created without atrributes.
201 if {! [istarget "h8300-*-*"]} then {
202 set as_flags "-al --generate-missing-build-notes=no"
203 switch -glob $target_triplet {
204 i*86-*-* -
205 x86_64-*-* {
206 set as_flags "$as_flags -mx86-used-note=no"
207 }
208 riscv*-*-* {
209 set as_flags "$as_flags -march-attr"
210 }
211 }
212 run_elf_list_test "section2" "$target_machine" "$as_flags" "-s" ""
213 }
214 run_dump_test "section3"
215 run_dump_test "section4" $dump_opts
216 if {! [istarget "h8300-*-*"] && ! [istarget "rx-*-*"]} then {
217 # The h8300 port issues a warning message for
218 # new sections created without atrributes.
219 # The RX port does not complain about changing the attributes of the
220 # .data and .bss sections since it does not use those names.
221 run_elf_list_test "section5" "" "-al -Z" "-SW" "| grep \" \\\\.test\\\[0-9\\\]\""
222 }
223 run_dump_test "struct"
224 if { ![istarget "alpha*-*-*"] } then {
225 # The alpha port uses .set for state, e.g. nomacro.
226 run_dump_test "symtab"
227 }
228 run_dump_test "symver"
229 run_dump_test "pr21661"
230 run_dump_test "pr14891"
231
232 # No indirect functions on non-GNU targets.
233 # The Visium and MSP set the ELF header's OSABI field to ELFOSABI_STANDALONE.
234 # The non-eabi ARM ports sets it to ELFOSABI_ARM.
235 # So for these targets we cannot include an IFUNC symbol type
236 # in the symbol type test.
237 # We also need to exclude targets that do not support unique objects.
238 if { [istarget "*-*-hpux*"]
239 || [istarget "arm*-*-*"]
240 || [istarget "mips*-*-*"]
241 || [istarget "msp*-*-*"]
242 || [istarget "visium-*-*"]
243 || [istarget "kvx*-*-*"]
244 || ![supports_gnu_unique]
245 } then {
246 # hppa64 has a non-standard common directive
247 if { ![istarget "hppa64*-*-hpux*"] } then {
248 run_elf_list_test "type-noifunc" "" "" "-s" "| grep \"1 *\\\[FONTC\\\]\""
249 }
250 } else {
251 run_dump_test ifunc-1
252 run_elf_list_test "type" "" "" "-s" "| grep \"1 *\\\[FIONTCU\\\]\""
253 run_elf_list_test "type-2" "" "--warn" "-s" "| grep \"0 *\\\[FIONT\\\]\""
254 }
255
256 run_dump_test "section6"
257 run_dump_test "section7"
258 run_dump_test "section8"
259 run_dump_test "section9"
260 run_dump_test "section10" $dump_opts
261 run_dump_test "section11" $dump_opts
262 run_dump_test "section12a"
263 run_dump_test "section12b"
264 run_dump_test "section13"
265 run_dump_test "section14"
266 run_dump_test "section15"
267 run_dump_test "section16a"
268 run_dump_test "section16b"
269 run_dump_test "section17"
270 run_dump_test "section18"
271 run_dump_test "section19"
272 run_dump_test "section20"
273 run_dump_test "section21"
274 run_dump_test "section22"
275 run_dump_test "section23a"
276 run_dump_test "section23b"
277 run_dump_test "section24a"
278 run_dump_test "section24b"
279 run_dump_test "section25"
280 run_dump_test "section26"
281 run_dump_test "section27"
282 run_dump_test "section28"
283 run_dump_test "section29"
284 run_dump_test "section30" $dump_opts
285 run_dump_test "sh-link-zero"
286 run_dump_test "size"
287 run_dump_test "dwarf2-1" $dump_opts
288 run_dump_test "dwarf2-2" $dump_opts
289 run_dump_test "dwarf2-3" $dump_opts
290 run_dump_test "dwarf2-4" $dump_opts
291 run_dump_test "dwarf2-5" $dump_opts
292 run_dump_test "dwarf2-6" $dump_opts
293 run_dump_test "dwarf2-7" $dump_opts
294 run_dump_test "dwarf2-8" $dump_opts
295 run_dump_test "dwarf2-9" $dump_opts
296 run_dump_test "dwarf2-10" $dump_opts
297 run_dump_test "dwarf2-11" $dump_opts
298 run_dump_test "dwarf2-12" $dump_opts
299 run_dump_test "dwarf2-13" $dump_opts
300 run_dump_test "dwarf2-14" $dump_opts
301 run_dump_test "dwarf2-15" $dump_opts
302 run_dump_test "dwarf2-16" $dump_opts
303 run_dump_test "dwarf2-17" $dump_opts
304 run_dump_test "dwarf2-18" $dump_opts
305 run_dump_test "dwarf2-19" $dump_opts
306 run_dump_test "dwarf2-20" $dump_opts
307 run_dump_test "dwarf2-21" $dump_opts
308 run_dump_test "dwarf-5-file0" $dump_opts
309 run_dump_test "dwarf-5-file0-2" $dump_opts
310 run_dump_test "dwarf-5-file0-3" $dump_opts
311 run_dump_test "dwarf-5-dir0" $dump_opts
312 run_dump_test "dwarf-5-loc0" $dump_opts
313 run_dump_test "dwarf-4-cu" $dump_opts
314 run_dump_test "dwarf-5-cu" $dump_opts
315 run_dump_test "dwarf-5-nop-for-line-table" $dump_opts
316 run_dump_test "dwarf-5-irp" $dump_opts
317 run_dump_test "dwarf-5-macro" $dump_opts
318 run_dump_test "dwarf-5-macro-include" $dump_opts
319 run_dump_test "dwarf-3-func" $dump_opts
320 run_dump_test "dwarf-5-func" $dump_opts
321 run_dump_test "dwarf-5-func-global" $dump_opts
322 run_dump_test "dwarf-5-func-local" $dump_opts
323
324 # Exclude targets defining ONLY_STANDARD_ESCAPES. It's not clear how these
325 # are supposed to reference macro arguments in double-quoted strings.
326 if { ![istarget "avr-*-*"]
327 && ![istarget "cris*-*-*"]
328 && ![istarget "msp430-*-*"]
329 && ![istarget "z80-*-*"] } then {
330 run_list_test line
331 }
332
333 run_dump_test "pr25917"
334 run_dump_test "bss"
335 run_dump_test "bad-bss"
336 run_dump_test "bad-section-flag"
337 run_dump_test "bad-size"
338 run_dump_test "bad-group"
339 run_dump_test "pr27355"
340
341 run_dump_test "syms"
342 run_dump_test "startof"
343
344 run_dump_test "missing-build-notes"
345
346 run_dump_test "common1"
347 run_dump_test "common2"
348
349 # hpux has a non-standard common directive.
350 if { ![istarget "*-*-hpux*"] } then {
351 switch -glob $target_triplet {
352 ia64-*-* {
353 run_dump_test "common3a" { { as "--defsym lcomm_align=1" } }
354 run_dump_test "common3b" { { as "--defsym lcomm_align=1" } }
355 }
356 default {
357 run_dump_test "common3a"
358 run_dump_test "common3b"
359 }
360 }
361 run_dump_test "common4a"
362 run_dump_test "common4b"
363 run_dump_test "common5a"
364 run_dump_test "common5b"
365 run_dump_test "common5c"
366 run_dump_test "common5d"
367 }
368
369 run_dump_test "strtab"
370
371 run_dump_test "bignums" $dump_opts
372 run_dump_test "section-symbol-redef"
373 run_dump_test "pr27228"
374 }