]>
Commit | Line | Data |
---|---|---|
fd67aa11 | 1 | # Copyright (C) 1999-2024 Free Software Foundation, Inc. |
252b5132 RH |
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 | |
32866df7 | 5 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 6 | # (at your option) any later version. |
65951855 | 7 | # |
252b5132 RH |
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. | |
65951855 | 12 | # |
252b5132 RH |
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 | |
b43b5d5f | 15 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
252b5132 RH |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-dejagnu@prep.ai.mit.edu | |
19 | ||
113675b7 | 20 | # Written by Nick Clifton <nickc@cygnus.com> |
252b5132 RH |
21 | # Based on scripts written by Ian Lance Taylor <ian@cygnus.com> |
22 | # and Ken Raeburn <raeburn@cygnus.com>. | |
23 | ||
09c11c86 NC |
24 | # Exclude non-ELF targets. |
25 | if ![is_elf_format] { | |
26 | verbose "$READELF is only intended for ELF targets" 2 | |
27 | return | |
28 | } | |
29 | ||
252b5132 RH |
30 | # First some helpful procedures, then the tests themselves |
31 | ||
32 | # Return the contents of the filename given | |
33 | proc file_contents { filename } { | |
34 | set file [open $filename r] | |
35 | set contents [read $file] | |
36 | close $file | |
37 | return $contents | |
38 | } | |
39 | ||
9921923c HPN |
40 | # Find out the size by reading the output of the EI_CLASS field. |
41 | # Similar to the test for readelf -h, but we're just looking for the | |
42 | # EI_CLASS line here. | |
a0a8a934 | 43 | proc readelf_find_size { binary_file test_iteration } { |
9921923c HPN |
44 | global READELF |
45 | global READELFFLAGS | |
46 | global readelf_size | |
47 | ||
48 | set readelf_size "" | |
a0a8a934 | 49 | set testname "finding out ELF size with readelf -h ($test_iteration)" |
7f6a71ff JM |
50 | set got [remote_exec host "$READELF $READELFFLAGS -h $binary_file" "" "/dev/null" "readelf.out"] |
51 | if [is_remote host] then { | |
52 | remote_upload host "readelf.out" | |
53 | } | |
9921923c | 54 | |
7f6a71ff | 55 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then { |
9921923c HPN |
56 | send_log $got |
57 | fail $testname | |
58 | return | |
59 | } | |
60 | ||
61 | if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \ | |
62 | [file_contents readelf.out] nil readelf_size] } { | |
63 | verbose -log "EI_CLASS field not found in output" | |
64 | verbose -log "output is \n[file_contents readelf.out]" | |
65 | fail $testname | |
66 | return | |
67 | } else { | |
68 | verbose -log "ELF size is $readelf_size" | |
69 | } | |
70 | ||
71 | pass $testname | |
72 | } | |
73 | ||
252b5132 RH |
74 | # Run an individual readelf test. |
75 | # Basically readelf is run on the binary_file with the given options. | |
76 | # Readelf's output is captured and then compared against the contents | |
9921923c | 77 | # of the regexp_file-readelf_size if it exists, else regexp_file. |
252b5132 | 78 | |
b9b204b3 | 79 | proc readelf_test { options binary_file regexp_file } { |
252b5132 RH |
80 | |
81 | global READELF | |
82 | global READELFFLAGS | |
9921923c | 83 | global readelf_size |
252b5132 RH |
84 | global srcdir |
85 | global subdir | |
65951855 | 86 | |
11bb0c7a AM |
87 | set testname "readelf $options [file rootname [file tail $binary_file]]" |
88 | ||
9921923c | 89 | send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n" |
7f6a71ff | 90 | set got [remote_exec host "$READELF $READELFFLAGS $options $binary_file" "" "/dev/null" "readelf.out"] |
252b5132 | 91 | |
7f6a71ff | 92 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
11bb0c7a | 93 | fail "$testname (reason: unexpected output)" |
252b5132 | 94 | send_log $got |
3f7de0e7 | 95 | send_log "\n" |
252b5132 RH |
96 | return |
97 | } | |
98 | ||
d1bcae83 L |
99 | if { [is_elf_unused_section_symbols ] } { |
100 | set target_machine unused | |
101 | } else { | |
102 | set target_machine "" | |
103 | } | |
ade0b24f | 104 | if [istarget "mips*-*-*"] then { |
9cc0123f | 105 | if [is_bad_symtab] then { |
eed3fa3b | 106 | set target_machine mips |
9cc0123f AM |
107 | } else { |
108 | set target_machine tmips | |
eed3fa3b | 109 | } |
ade0b24f NC |
110 | } |
111 | ||
112 | if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then { | |
113 | set regexp_file $regexp_file-$readelf_size-$target_machine | |
114 | } elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then { | |
115 | set regexp_file $regexp_file-$target_machine | |
116 | } elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then { | |
9921923c HPN |
117 | set regexp_file $regexp_file-$readelf_size |
118 | } | |
119 | ||
252b5132 | 120 | if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then { |
ca0e11aa NC |
121 | send_log [file_contents readelf.out] |
122 | send_log "\n" | |
11bb0c7a | 123 | fail $testname |
252b5132 RH |
124 | return |
125 | } | |
126 | ||
11bb0c7a | 127 | pass $testname |
252b5132 RH |
128 | } |
129 | ||
cbb356d9 NC |
130 | # Simple proc to skip certain expected warning messages. |
131 | ||
132 | proc prune_readelf_wi_warnings { text } { | |
133 | regsub -all "(^|\n)(.*Skipping unexpected symbol type.*)" $text "\\1" text | |
134 | return $text | |
135 | } | |
136 | ||
137 | # Testing the "readelf -wi" option is difficult because there | |
138 | # is no guaranteed order to the output, and because some ports | |
139 | # will use indirect string references, whilst others will use | |
140 | # direct references. So instead of having an expected output | |
141 | # file, like the other readelf tests, we grep for strings that | |
142 | # really ought to be there. | |
143 | ||
144 | proc readelf_wi_test {} { | |
145 | global READELF | |
146 | global READELFFLAGS | |
147 | global srcdir | |
148 | global subdir | |
65951855 | 149 | |
cbb356d9 NC |
150 | # Compile the second test file. |
151 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
152 | verbose "Unable to compile test file." | |
153 | untested "readelf -wi" | |
154 | return | |
155 | } | |
156 | ||
157 | # Download it. | |
8d263650 | 158 | set tempfile [remote_download host tmpdir/testprog.o] |
cbb356d9 NC |
159 | |
160 | # Run "readelf -wi" on it. | |
7f6a71ff | 161 | set got [remote_exec host "$READELF $READELFFLAGS -wi $tempfile" "" "/dev/null" "readelf.out"] |
cbb356d9 NC |
162 | |
163 | # Upload the results. | |
8d263650 | 164 | set output [remote_upload host readelf.out] |
cbb356d9 | 165 | |
8d263650 | 166 | file_on_host delete $tempfile |
65951855 | 167 | |
cbb356d9 | 168 | # Strip any superflous warnings. |
7f6a71ff | 169 | set got [prune_readelf_wi_warnings [lindex $got 1]] |
cbb356d9 NC |
170 | |
171 | if ![string match "" $got] then { | |
b279a55c | 172 | fail "readelf $READELFFLAGS -wi (reason: unexpected output)" |
cbb356d9 NC |
173 | send_log $got |
174 | send_log "\n" | |
175 | return | |
176 | } | |
177 | ||
178 | if ![file size $output] then { | |
179 | # If the output file is empty, then this target does not | |
180 | # generate dwarf2 output. This is not a failure. | |
181 | verbose "No output from 'readelf -wi'" | |
182 | untested "readelf -wi" | |
183 | return | |
184 | } | |
65951855 | 185 | |
cbb356d9 NC |
186 | # Search for strings that should be in the output. |
187 | set sought { | |
188 | ".*DW_TAG_compile_unit.*" | |
189 | ".*DW_TAG_subprogram.*" | |
190 | ".*DW_TAG_base_type.*" | |
e959744e | 191 | ".*DW_AT_producer.*(GNU C|indirect string|indexed string).*" |
02391b8b | 192 | ".*DW_AT_language.*(ANSI C|C11).*" |
e959744e | 193 | ".*DW_AT_name.*(testprog.c|indirect string|indexed string).*" |
cbb356d9 | 194 | ".*DW_AT_name.*fn.*" |
e959744e RP |
195 | ".*DW_AT_name.*(main|indirect string|indexed string).*" |
196 | ".*(DW_OP_addr: 0|DW_OP_addrx <0>).*" | |
cbb356d9 NC |
197 | ".*DW_AT_name.*(main|indirect string).*" |
198 | } | |
65951855 | 199 | |
13761a11 NC |
200 | # The MSP430 in LARGE mode does not generate a DW_OP_addr. |
201 | setup_xfail msp430*-*-* | |
202 | ||
65951855 | 203 | foreach looked_for $sought { |
cbb356d9 NC |
204 | set lines [grep $output $looked_for] |
205 | if ![llength $lines] then { | |
206 | fail "readelf -wi: missing: $looked_for" | |
207 | send_log readelf.out | |
208 | return | |
209 | } | |
210 | } | |
211 | ||
8d263650 | 212 | file_on_host delete $output |
65951855 | 213 | |
cbb356d9 NC |
214 | # All done. |
215 | pass "readelf -wi" | |
216 | } | |
252b5132 | 217 | |
1b315056 CS |
218 | # This tests "readelf -wa", but on a file with a compressed |
219 | # .debug_abbrev section. | |
220 | ||
221 | proc readelf_compressed_wa_test {} { | |
222 | global READELF | |
223 | global READELFFLAGS | |
224 | global srcdir | |
225 | global subdir | |
65951855 | 226 | |
1b315056 CS |
227 | # Compile the compressed-debug-section test file. |
228 | if { [target_compile $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o object debug] != "" } { | |
229 | verbose "Unable to compile test file." | |
230 | untested "readelf -wa (compressed)" | |
231 | return | |
232 | } | |
233 | ||
234 | # Download it. | |
235 | set tempfile [remote_download host tmpdir/dw2-compressed.o] | |
236 | ||
237 | # Run "readelf -wa" on it. | |
238 | set got [remote_exec host "$READELF $READELFFLAGS -wa $tempfile" "" "/dev/null" "readelf.out"] | |
239 | ||
240 | # Upload the results. | |
241 | set output [remote_upload host readelf.out] | |
242 | ||
243 | file_on_host delete $tempfile | |
65951855 | 244 | |
1b315056 CS |
245 | if { [string compare [file_contents readelf.out] [file_contents $srcdir/$subdir/readelf.wa]] != 0 } then { |
246 | fail "readelf -wa (compressed)" | |
247 | verbose "output is \n[file_contents readelf.out]" 2 | |
248 | verbose "expected is \n[file_contents $srcdir/$subdir/readelf.wa]" 2 | |
249 | return | |
250 | } | |
251 | ||
252 | pass "readelf -wa (compressed)" | |
253 | } | |
252b5132 | 254 | |
09c11c86 NC |
255 | # Test readelf's dumping abilities. |
256 | ||
257 | proc readelf_dump_test {} { | |
258 | global READELF | |
259 | global READELFFLAGS | |
260 | global srcdir | |
261 | global subdir | |
65951855 | 262 | |
09c11c86 NC |
263 | # Assemble the dump test file. |
264 | if {![binutils_assemble $srcdir/$subdir/dumptest.s tmpdir/dumptest.o]} then { | |
17e04eff | 265 | unsupported "readelf -p: failed to assemble dump test file" |
09c11c86 NC |
266 | return |
267 | } | |
268 | # Download it. | |
269 | set tempfile [remote_download host tmpdir/dumptest.o] | |
270 | ||
271 | # Run "readelf -p.data" on it. | |
96037eb0 NC |
272 | set sect_names [get_standard_section_names] |
273 | if { $sect_names != "" } { | |
274 | set got [remote_exec host "$READELF $READELFFLAGS -p[lindex $sect_names 1] $tempfile" "" "/dev/null" "readelf.out"] | |
275 | } else { | |
276 | set got [remote_exec host "$READELF $READELFFLAGS -p.data $tempfile" "" "/dev/null" "readelf.out"] | |
277 | } | |
09c11c86 NC |
278 | set got [lindex $got 1] |
279 | ||
280 | # Upload the results. | |
281 | set output [remote_upload host readelf.out] | |
282 | ||
283 | # Check for something going wrong. | |
284 | if ![string match "" $got] then { | |
285 | fail "readelf -p: unexpected output" | |
286 | send_log $got | |
287 | send_log "\n" | |
288 | return | |
289 | } | |
290 | ||
291 | # Search for strings that should be in the output. | |
292 | set sought { | |
293 | ".*test_string.*" | |
294 | } | |
65951855 RM |
295 | |
296 | foreach looked_for $sought { | |
09c11c86 NC |
297 | set lines [grep $output $looked_for] |
298 | if ![llength $lines] then { | |
299 | fail "readelf -p: missing: $looked_for" | |
300 | send_log readelf.out | |
301 | return | |
302 | } | |
303 | } | |
304 | ||
65951855 | 305 | file_on_host delete $tempfile |
09c11c86 NC |
306 | file_on_host delete $output |
307 | ||
308 | # All done. | |
309 | pass "readelf -p" | |
310 | ||
311 | # XXX FIXME: Add test of readelf -x here | |
252b5132 RH |
312 | } |
313 | ||
75a2da57 AH |
314 | # Tests whether readelf can read thin archives |
315 | proc readelf_thin_archive_test {} { | |
316 | global AR | |
317 | ||
318 | if ![is_remote host] { | |
319 | set tempfile tmpdir/bintest.o | |
320 | set templib tmpdir/bintest.thin.a | |
321 | set libname tmpdir/bintest.thin.a | |
322 | } else { | |
323 | set tempfile [remote_download host tmpdir/bintest.o] | |
324 | set templib [remote_download host tmpdir/bintest.thin.a] | |
325 | set libname bintest.thin.a | |
326 | } | |
327 | ||
328 | set testname "readelf -h bintest.thin" | |
329 | set got [binutils_run $AR "rcT $libname ${tempfile}"] | |
330 | if ![string match "" $got] { | |
331 | fail $testname | |
332 | return | |
333 | } | |
334 | ||
335 | readelf_test -h $templib readelf.h.thin | |
336 | ||
337 | pass $testname | |
338 | } | |
339 | ||
252b5132 RH |
340 | if ![is_remote host] { |
341 | if {[which $READELF] == 0} then { | |
342 | perror "$READELF does not exist" | |
343 | return | |
344 | } | |
345 | } | |
346 | ||
347 | send_user "Version [binutil_version $READELF]" | |
348 | ||
89084430 | 349 | # Assemble the test file. |
252b5132 | 350 | if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then { |
17e04eff AM |
351 | unsupported "readelf -h bintest (failed to assemble)" |
352 | unsupported "readelf -S bintest (failed to assemble)" | |
353 | unsupported "readelf -s bintest (failed to assemble)" | |
354 | unsupported "readelf -r bintest (failed to assemble)" | |
f3185997 NC |
355 | global readelf_size |
356 | set readelf_size "" | |
252b5132 | 357 | } else { |
252b5132 | 358 | |
11bb0c7a AM |
359 | if ![is_remote host] { |
360 | set tempfile tmpdir/bintest.o | |
361 | } else { | |
362 | set tempfile [remote_download host tmpdir/bintest.o] | |
363 | } | |
9921923c | 364 | |
11bb0c7a | 365 | # First, determine the size, so specific output matchers can be used. |
a0a8a934 | 366 | readelf_find_size $tempfile 1 |
11bb0c7a AM |
367 | |
368 | # Run the tests. | |
b9b204b3 AM |
369 | readelf_test -h $tempfile readelf.h |
370 | readelf_test -S $tempfile readelf.s | |
11bb0c7a | 371 | setup_xfail "mips-*-*irix*" |
b9b204b3 AM |
372 | readelf_test -s $tempfile readelf.ss |
373 | readelf_test -r $tempfile readelf.r | |
75a2da57 AH |
374 | |
375 | readelf_thin_archive_test | |
11bb0c7a | 376 | } |
252b5132 | 377 | |
79bc120c NC |
378 | # Test demangling symbol names. |
379 | if {![binutils_assemble $srcdir/$subdir/mangled.s tmpdir/mangled.o]} then { | |
17e04eff | 380 | unsupported "readelf -s -C bintest (failed to assemble)" |
79bc120c NC |
381 | } else { |
382 | ||
383 | if ![is_remote host] { | |
384 | set tempfile tmpdir/mangled.o | |
385 | } else { | |
386 | set tempfile [remote_download host tmpdir/mangled.o] | |
387 | } | |
388 | ||
389 | # Run the test. | |
b9b204b3 | 390 | readelf_test {--syms --demangle --wide} $tempfile readelf.demangled |
79bc120c NC |
391 | } |
392 | ||
cbb356d9 | 393 | readelf_wi_test |
1b315056 | 394 | readelf_compressed_wa_test |
09c11c86 NC |
395 | |
396 | readelf_dump_test | |
8b971f9f | 397 | |
99fabbc9 JL |
398 | # These dump tests require an assembler. |
399 | if {[which $AS] != 0} then { | |
400 | run_dump_test "pr25543" | |
401 | run_dump_test "retain1a" | |
402 | run_dump_test "retain1b" | |
403 | run_dump_test "readelf-maskos-1a" | |
404 | run_dump_test "readelf-maskos-1b" | |
0be51eb4 | 405 | if {![istarget *-*-hpux*]} then { |
b9b204b3 AM |
406 | run_dump_test pr26548 |
407 | if {![binutils_assemble_flags $srcdir/$subdir/pr26548.s tmpdir/pr26548e.o {--defsym ERROR=1}]} then { | |
408 | unsupported "pr26548e (failed to assemble)" | |
409 | } else { | |
410 | if ![is_remote host] { | |
411 | set tempfile tmpdir/pr26548e.o | |
412 | } else { | |
413 | set tempfile [remote_download host tmpdir/pr26548e.o] | |
414 | } | |
415 | readelf_test -Wwi $tempfile pr26548e.d | |
416 | } | |
417 | } | |
99fabbc9 | 418 | } |
79bc120c | 419 | |
8b971f9f NC |
420 | # PR 13482 - Check for off-by-one errors when dumping .note sections. |
421 | if {![binutils_assemble $srcdir/$subdir/version.s tmpdir/version.o]} then { | |
17e04eff | 422 | unsupported "readelf -n version (failed to assemble)" |
8b971f9f | 423 | } else { |
0e602686 NC |
424 | |
425 | if ![is_remote host] { | |
426 | set tempfile tmpdir/version.o | |
427 | } else { | |
428 | set tempfile [remote_download host tmpdir/version.o] | |
429 | } | |
430 | ||
b9b204b3 | 431 | readelf_test -n $tempfile readelf.n |
8b971f9f NC |
432 | } |
433 | ||
d1c4b12b NC |
434 | |
435 | # PR 18374 - Check that relocations against the .debug_loc section | |
436 | # do not prevent readelf from displaying all the location lists. | |
437 | if {![binutils_assemble $srcdir/$subdir/pr18374.s tmpdir/pr18374.o]} then { | |
17e04eff | 438 | unsupported "readelf --debug-dump=loc pr18374 (failed to assemble)" |
0e602686 NC |
439 | } else { |
440 | ||
441 | if ![is_remote host] { | |
442 | set tempfile tmpdir/pr18374.o | |
443 | } else { | |
444 | set tempfile [remote_download host tmpdir/pr18374.o] | |
445 | } | |
446 | ||
b9b204b3 | 447 | readelf_test --debug-dump=loc $tempfile readelf.pr18374 |
d1c4b12b NC |
448 | } |
449 | ||
0e602686 | 450 | |
9f272209 AO |
451 | # locview - Check dumping of location lists with location views. |
452 | if {![binutils_assemble $srcdir/$subdir/locview-1.s tmpdir/locview-1.o]} then { | |
17e04eff | 453 | unsupported "readelf --debug-dump=loc locview-1 (failed to assemble)" |
9f272209 AO |
454 | } else { |
455 | ||
456 | if ![is_remote host] { | |
457 | set tempfile tmpdir/locview-1.o | |
458 | } else { | |
459 | set tempfile [remote_download host tmpdir/locview-1.o] | |
460 | } | |
461 | ||
b9b204b3 | 462 | readelf_test --debug-dump=loc $tempfile readelf.locview-1 |
9f272209 AO |
463 | } |
464 | if {![binutils_assemble $srcdir/$subdir/locview-2.s tmpdir/locview-2.o]} then { | |
17e04eff | 465 | unsupported "readelf --debug-dump=loc locview-2 (failed to assemble)" |
9f272209 AO |
466 | } else { |
467 | ||
468 | if ![is_remote host] { | |
469 | set tempfile tmpdir/locview-2.o | |
470 | } else { | |
471 | set tempfile [remote_download host tmpdir/locview-2.o] | |
472 | } | |
473 | ||
b9b204b3 | 474 | readelf_test --debug-dump=loc $tempfile readelf.locview-2 |
9f272209 AO |
475 | } |
476 | ||
477 | ||
0e602686 NC |
478 | # Check that decompressed dumps work. |
479 | if {![binutils_assemble $srcdir/$subdir/z.s tmpdir/z.o]} then { | |
17e04eff | 480 | unsupported "readelf --decompress --hex-dump .debug_loc z (failed to assemble)" |
d1c4b12b | 481 | } else { |
d1c4b12b | 482 | |
0e602686 NC |
483 | if ![is_remote host] { |
484 | set tempfile tmpdir/z.o | |
485 | } else { | |
486 | set tempfile [remote_download host tmpdir/z.o] | |
487 | } | |
488 | ||
b9b204b3 | 489 | readelf_test {--decompress --hex-dump .debug_loc} $tempfile readelf.z |
0e602686 | 490 | } |
a567769b | 491 | |
76244462 | 492 | set flags "" |
3ac9da49 | 493 | |
04914e37 NC |
494 | # Skip the next test for the RISCV architectures because they |
495 | # do not support .ULEB128 pseudo-ops with non-constant values. | |
a567769b JK |
496 | if ![istarget "riscv*-*-*"] then { |
497 | ||
3b83ea38 | 498 | if [istarget "hppa*64*-*-hpux*"] { |
76244462 | 499 | set flags "--defsym HPUX=1" |
3b83ea38 | 500 | } |
04914e37 | 501 | |
76244462 | 502 | # LoongArch relax align add nops, so label subtractions will increase |
503 | if [istarget "loongarch*-*-*"] { | |
504 | set flags "-mno-relax" | |
505 | } | |
506 | ||
a567769b | 507 | # Assemble the DWARF-5 test file. |
76244462 | 508 | if {![binutils_assemble_flags $srcdir/$subdir/dw5.S tmpdir/dw5.o $flags]} then { |
17e04eff | 509 | unsupported "readelf -wiaoRlL dw5 (failed to assemble)" |
a567769b | 510 | } else { |
a567769b | 511 | |
11bb0c7a AM |
512 | # Download it. |
513 | if ![is_remote host] { | |
514 | set tempfile tmpdir/dw5.o | |
515 | } else { | |
516 | set tempfile [remote_download host tmpdir/dw5.o] | |
517 | } | |
518 | ||
519 | # First, determine the size, so specific output matchers can be used. | |
a0a8a934 | 520 | readelf_find_size $tempfile 2 |
a567769b | 521 | |
11bb0c7a | 522 | # Make sure that readelf can decode the contents. |
b9b204b3 | 523 | readelf_test -wiaoRlL $tempfile dw5.W |
11bb0c7a | 524 | } |
a567769b | 525 | } |
04914e37 NC |
526 | |
527 | # Assemble the DWARF-5 attributes test file. | |
528 | if {![binutils_assemble_flags $srcdir/$subdir/dwarf-attributes.S tmpdir/dwarf-attributes.o ""]} then { | |
17e04eff | 529 | unsupported "readelf -wi dwarf-attributes (failed to assemble)" |
04914e37 NC |
530 | } else { |
531 | # Download it. | |
532 | if ![is_remote host] { | |
533 | set tempfile tmpdir/dwarf-attributes.o | |
534 | } else { | |
535 | set tempfile [remote_download host tmpdir/dwarf-attributes.o] | |
536 | } | |
537 | ||
538 | # First, determine the size, so specific output matchers can be used. | |
a0a8a934 | 539 | readelf_find_size $tempfile 3 |
04914e37 NC |
540 | |
541 | # Make sure that readelf can decode the contents. | |
b9b204b3 | 542 | readelf_test -wi $tempfile dwarf-attributes.W |
04914e37 | 543 | } |
dda8d76d NC |
544 | |
545 | # Check that debug link sections can be dumped. | |
546 | if {![binutils_assemble $srcdir/$subdir/debuglink.s tmpdir/debuglink.o]} then { | |
17e04eff | 547 | unsupported "readelf --debug-dump=links (failed to assemble debuglink.s)" |
dda8d76d NC |
548 | } else { |
549 | if ![is_remote host] { | |
550 | set tempfile tmpdir/debuglink.o | |
551 | } else { | |
552 | set tempfile [remote_download host tmpdir/debuglink.o] | |
553 | } | |
554 | ||
b9b204b3 | 555 | readelf_test {--debug-dump=links -wN} $tempfile readelf.k |
dda8d76d | 556 | |
d85bf2ba | 557 | # Check that debug link sections can be followed. |
dda8d76d | 558 | if {![binutils_assemble $srcdir/$subdir/linkdebug.s tmpdir/linkdebug.debug]} then { |
17e04eff | 559 | unsupported "readelf --debug-dump=follow-links (failed to assemble linkdebug.s)" |
dda8d76d | 560 | } else { |
d85bf2ba NC |
561 | if [is_remote host] { |
562 | set tempfile2 [remote_download host tmpdir/linkdebug.debug] | |
dda8d76d NC |
563 | } |
564 | ||
ca0e11aa | 565 | readelf_test "-wKis -P" $tempfile readelf.wKis |
dda8d76d NC |
566 | } |
567 | } | |
568 | ||
d85bf2ba | 569 | if {![binutils_assemble $srcdir/$subdir/dwo.s tmpdir/dwo.o]} then { |
17e04eff | 570 | unsupported "readelf --debug-dump=links (failed to assemble dwo.s)" |
d85bf2ba NC |
571 | } else { |
572 | if ![is_remote host] { | |
573 | set tempfile tmpdir/dwo.o | |
574 | } else { | |
575 | set tempfile [remote_download host tmpdir/dwo.o] | |
576 | } | |
577 | ||
b9b204b3 | 578 | readelf_test {--debug-dump=links --debug-dump=no-follow-links} $tempfile readelf.k2 |
d85bf2ba NC |
579 | } |
580 | ||
1b513401 | 581 | if {![binutils_assemble $srcdir/$subdir/zero-sec.s tmpdir/zero-sec.o]} then { |
17e04eff | 582 | unsupported "readelf --enable-checks (failed to assemble zero-sec.s)" |
1b513401 NC |
583 | } else { |
584 | if ![is_remote host] { | |
585 | set tempfile tmpdir/zero-sec.o | |
586 | } else { | |
587 | set tempfile [remote_download host tmpdir/zero-sec.o] | |
588 | } | |
589 | ||
b9b204b3 | 590 | readelf_test {--enable-checks --sections --wide} $tempfile zero-sec.r |
1b513401 | 591 | } |
d85bf2ba | 592 | |
80fda85c L |
593 | if ![is_remote host] { |
594 | set test $srcdir/$subdir/pr26112.o.bz2 | |
595 | # We need to strip the ".bz2", but can leave the dirname. | |
596 | set t $subdir/[file tail $test] | |
597 | set testname [file rootname $t] | |
598 | verbose $testname | |
599 | set tempfile tmpdir/pr26112.o | |
600 | if {[catch "system \"bzip2 -dc $test > $tempfile\""] != 0} { | |
601 | untested "bzip2 -dc ($testname)" | |
602 | } else { | |
b9b204b3 | 603 | readelf_test {--debug-dump=macro -wN} $tempfile pr26112.r |
80fda85c | 604 | } |
d195b95c L |
605 | |
606 | set test $srcdir/$subdir/pr26160.dwp.bz2 | |
607 | # We need to strip the ".bz2", but can leave the dirname. | |
608 | set t $subdir/[file tail $test] | |
609 | set testname [file rootname $t] | |
610 | verbose $testname | |
611 | set tempfile tmpdir/pr26160.dwp | |
612 | if {[catch "system \"bzip2 -dc $test > $tempfile\""] != 0} { | |
613 | untested "bzip2 -dc ($testname)" | |
614 | } else { | |
615 | readelf_test {-wi} $tempfile pr26160.r | |
616 | } | |
80fda85c | 617 | } |
3ac9da49 NK |
618 | |
619 | # Check dwarf-5 support for DW_OP_addrx. | |
76244462 | 620 | if {![binutils_assemble_flags $srcdir/$subdir/dw5-op.S tmpdir/dw5-op.o $flags]} then { |
3ac9da49 NK |
621 | unsupported "readelf -wi dw5-op (failed to assemble)" |
622 | } else { | |
623 | ||
624 | # Download it. | |
625 | if ![is_remote host] { | |
626 | set tempfile tmpdir/dw5-op.o | |
627 | } else { | |
628 | set tempfile [remote_download host tmpdir/dw5-op.o] | |
629 | } | |
630 | ||
631 | # First, determine the size, so specific output matchers can be used. | |
632 | readelf_find_size $tempfile 2 | |
633 | ||
634 | # Make sure that readelf can decode the contents. | |
635 | readelf_test -wi $tempfile dw5-op.W | |
636 | } | |
8e8d0b63 NC |
637 | |
638 | # Test the -j/--display-section option. | |
639 | # Check that multiple options accumulate. | |
640 | # Check that both numbers and names can be used. | |
641 | readelf_test {-j .rela.debug_info --display-section=.rel.debug_info} $tempfile display-section.r | |
642 | readelf_test --display-section=0 $tempfile display-section.0 | |
643 | ||
644 | ||
fcf8f323 NC |
645 | # Test that RELR relocations are display correctly. |
646 | proc readelf_relr_test {} { | |
647 | global srcdir | |
648 | global subdir | |
649 | global READELF | |
650 | global READELFFLAGS | |
651 | ||
652 | set testname "readelf -r (RELR)" | |
653 | ||
654 | # Assemble the RELR test file (using magic to work for both 32-bit and | |
655 | # 64-bit targets). | |
656 | if {![binutils_assemble $srcdir/$subdir/relr.s tmpdir/relr.o]} then { | |
657 | unsupported "$testname: failed to assemble RELR test file" | |
658 | return | |
659 | } | |
660 | ||
661 | # Download it. | |
662 | set tempfile [remote_download host tmpdir/relr.o] | |
663 | ||
664 | # Run "readelf -r" on it. | |
665 | set got [remote_exec host "$READELF $READELFFLAGS -r $tempfile" "" "/dev/null" "readelf.out"] | |
666 | set got [lindex $got 1] | |
667 | ||
668 | # Upload the results. | |
669 | set output [remote_upload host readelf.out] | |
670 | ||
671 | # Check for something going wrong. | |
672 | if ![string match "" $got] then { | |
673 | fail "$testname: unexpected output" | |
674 | send_log $got | |
675 | send_log "\n" | |
676 | return | |
677 | } | |
678 | ||
679 | # Search for strings that should be in the output. | |
680 | # There will also be these strings: | |
681 | # readelf: Error: Section 4 has invalid sh_entsize of 0 | |
682 | # readelf: Error: (Using the expected size of 8 for the rest of this dump) | |
683 | # But we ignore them... | |
684 | ||
685 | set sought { | |
686 | "0000: 0+01000 0+01000 .*" | |
687 | "0001: 0+00003 0+0100. .*" | |
688 | } | |
689 | ||
690 | foreach looked_for $sought { | |
691 | set lines [grep $output $looked_for] | |
692 | if ![llength $lines] then { | |
693 | fail "$testname: missing: $looked_for" | |
694 | send_log readelf.out | |
695 | return | |
696 | } | |
697 | } | |
698 | ||
699 | file_on_host delete $tempfile | |
700 | file_on_host delete $output | |
701 | ||
702 | # All done. | |
703 | pass "$testname" | |
704 | } | |
705 | ||
706 | # The AVR, H8300, IP2K and Z80 targets' .dc.a pseudo-op creates a | |
707 | # 16-bit entry rather than a 32-bit entry. Thus creating an | |
708 | # invalid RELR relocation. | |
709 | setup_xfail "avr-*-*" "h8300-*-*" "ip2k-*-*" "z80-*-*" | |
710 | ||
711 | readelf_relr_test |