1*1424dfb3Schristos#   Copyright (C) 1999-2020 Free Software Foundation, Inc.
2*1424dfb3Schristos
3*1424dfb3Schristos# This program is free software; you can redistribute it and/or modify
4*1424dfb3Schristos# it under the terms of the GNU General Public License as published by
5*1424dfb3Schristos# the Free Software Foundation; either version 3 of the License, or
6*1424dfb3Schristos# (at your option) any later version.
7*1424dfb3Schristos#
8*1424dfb3Schristos# This program is distributed in the hope that it will be useful,
9*1424dfb3Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
10*1424dfb3Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11*1424dfb3Schristos# GNU General Public License for more details.
12*1424dfb3Schristos#
13*1424dfb3Schristos# You should have received a copy of the GNU General Public License
14*1424dfb3Schristos# along with this program; if not, write to the Free Software
15*1424dfb3Schristos# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
16*1424dfb3Schristos
17*1424dfb3Schristos# Please email any bugs, comments, and/or additions to this file to:
18*1424dfb3Schristos# bug-dejagnu@prep.ai.mit.edu
19*1424dfb3Schristos
20*1424dfb3Schristos# Written by Nick Clifton <nickc@cygnus.com>
21*1424dfb3Schristos# Based on scripts written by Ian Lance Taylor <ian@cygnus.com>
22*1424dfb3Schristos# and Ken Raeburn <raeburn@cygnus.com>.
23*1424dfb3Schristos
24*1424dfb3Schristos# Exclude non-ELF targets.
25*1424dfb3Schristosif ![is_elf_format] {
26*1424dfb3Schristos    verbose "$READELF is only intended for ELF targets" 2
27*1424dfb3Schristos    return
28*1424dfb3Schristos}
29*1424dfb3Schristos
30*1424dfb3Schristos# First some helpful procedures, then the tests themselves
31*1424dfb3Schristos
32*1424dfb3Schristos# Return the contents of the filename given
33*1424dfb3Schristosproc file_contents { filename } {
34*1424dfb3Schristos    set file [open $filename r]
35*1424dfb3Schristos    set contents [read $file]
36*1424dfb3Schristos    close $file
37*1424dfb3Schristos    return $contents
38*1424dfb3Schristos}
39*1424dfb3Schristos
40*1424dfb3Schristos# Find out the size by reading the output of the EI_CLASS field.
41*1424dfb3Schristos# Similar to the test for readelf -h, but we're just looking for the
42*1424dfb3Schristos# EI_CLASS line here.
43*1424dfb3Schristosproc readelf_find_size { binary_file test_iteration } {
44*1424dfb3Schristos    global READELF
45*1424dfb3Schristos    global READELFFLAGS
46*1424dfb3Schristos    global readelf_size
47*1424dfb3Schristos
48*1424dfb3Schristos    set readelf_size ""
49*1424dfb3Schristos    set testname "finding out ELF size with readelf -h ($test_iteration)"
50*1424dfb3Schristos    set got [remote_exec host "$READELF $READELFFLAGS -h $binary_file" "" "/dev/null" "readelf.out"]
51*1424dfb3Schristos    if [is_remote host] then {
52*1424dfb3Schristos        remote_upload host "readelf.out"
53*1424dfb3Schristos    }
54*1424dfb3Schristos
55*1424dfb3Schristos    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then {
56*1424dfb3Schristos	send_log $got
57*1424dfb3Schristos	fail $testname
58*1424dfb3Schristos	return
59*1424dfb3Schristos    }
60*1424dfb3Schristos
61*1424dfb3Schristos    if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
62*1424dfb3Schristos	    [file_contents readelf.out] nil readelf_size] } {
63*1424dfb3Schristos	verbose -log "EI_CLASS field not found in output"
64*1424dfb3Schristos	verbose -log "output is \n[file_contents readelf.out]"
65*1424dfb3Schristos	fail $testname
66*1424dfb3Schristos	return
67*1424dfb3Schristos    } else {
68*1424dfb3Schristos	verbose -log "ELF size is $readelf_size"
69*1424dfb3Schristos    }
70*1424dfb3Schristos
71*1424dfb3Schristos    pass $testname
72*1424dfb3Schristos}
73*1424dfb3Schristos
74*1424dfb3Schristos# Run an individual readelf test.
75*1424dfb3Schristos# Basically readelf is run on the binary_file with the given options.
76*1424dfb3Schristos# Readelf's output is captured and then compared against the contents
77*1424dfb3Schristos# of the regexp_file-readelf_size if it exists, else regexp_file.
78*1424dfb3Schristos
79*1424dfb3Schristosproc readelf_test { options binary_file regexp_file xfails } {
80*1424dfb3Schristos
81*1424dfb3Schristos    global READELF
82*1424dfb3Schristos    global READELFFLAGS
83*1424dfb3Schristos    global readelf_size
84*1424dfb3Schristos    global srcdir
85*1424dfb3Schristos    global subdir
86*1424dfb3Schristos
87*1424dfb3Schristos    set testname "readelf $options [file rootname [file tail $binary_file]]"
88*1424dfb3Schristos
89*1424dfb3Schristos    send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n"
90*1424dfb3Schristos    set got [remote_exec host "$READELF $READELFFLAGS $options $binary_file" "" "/dev/null" "readelf.out"]
91*1424dfb3Schristos
92*1424dfb3Schristos    foreach xfail $xfails {
93*1424dfb3Schristos	setup_xfail $xfail
94*1424dfb3Schristos    }
95*1424dfb3Schristos
96*1424dfb3Schristos    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
97*1424dfb3Schristos	fail "$testname (reason: unexpected output)"
98*1424dfb3Schristos	send_log $got
99*1424dfb3Schristos	send_log "\n"
100*1424dfb3Schristos	return
101*1424dfb3Schristos    }
102*1424dfb3Schristos
103*1424dfb3Schristos    set target_machine ""
104*1424dfb3Schristos    if [istarget "mips*-*-*"] then {
105*1424dfb3Schristos	if [is_bad_symtab] then {
106*1424dfb3Schristos	    set target_machine mips
107*1424dfb3Schristos	} else {
108*1424dfb3Schristos	    set target_machine tmips
109*1424dfb3Schristos	}
110*1424dfb3Schristos    }
111*1424dfb3Schristos
112*1424dfb3Schristos    if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then {
113*1424dfb3Schristos	set regexp_file $regexp_file-$readelf_size-$target_machine
114*1424dfb3Schristos    } elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then {
115*1424dfb3Schristos	set regexp_file $regexp_file-$target_machine
116*1424dfb3Schristos    } elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then {
117*1424dfb3Schristos	set regexp_file $regexp_file-$readelf_size
118*1424dfb3Schristos    }
119*1424dfb3Schristos
120*1424dfb3Schristos    if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then {
121*1424dfb3Schristos	fail $testname
122*1424dfb3Schristos	verbose "output is \n[file_contents readelf.out]" 2
123*1424dfb3Schristos	return
124*1424dfb3Schristos    }
125*1424dfb3Schristos
126*1424dfb3Schristos    pass $testname
127*1424dfb3Schristos}
128*1424dfb3Schristos
129*1424dfb3Schristos# Simple proc to skip certain expected warning messages.
130*1424dfb3Schristos
131*1424dfb3Schristosproc prune_readelf_wi_warnings { text } {
132*1424dfb3Schristos    regsub -all "(^|\n)(.*Skipping unexpected symbol type.*)" $text "\\1" text
133*1424dfb3Schristos    return $text
134*1424dfb3Schristos}
135*1424dfb3Schristos
136*1424dfb3Schristos# Testing the "readelf -wi" option is difficult because there
137*1424dfb3Schristos# is no guaranteed order to the output, and because some ports
138*1424dfb3Schristos# will use indirect string references, whilst others will use
139*1424dfb3Schristos# direct references.  So instead of having an expected output
140*1424dfb3Schristos# file, like the other readelf tests, we grep for strings that
141*1424dfb3Schristos# really ought to be there.
142*1424dfb3Schristos
143*1424dfb3Schristosproc readelf_wi_test {} {
144*1424dfb3Schristos    global READELF
145*1424dfb3Schristos    global READELFFLAGS
146*1424dfb3Schristos    global srcdir
147*1424dfb3Schristos    global subdir
148*1424dfb3Schristos
149*1424dfb3Schristos    # Compile the second test file.
150*1424dfb3Schristos    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
151*1424dfb3Schristos	verbose "Unable to compile test file."
152*1424dfb3Schristos	untested "readelf -wi"
153*1424dfb3Schristos	return
154*1424dfb3Schristos    }
155*1424dfb3Schristos
156*1424dfb3Schristos    # Download it.
157*1424dfb3Schristos    set tempfile [remote_download host tmpdir/testprog.o]
158*1424dfb3Schristos
159*1424dfb3Schristos    # Run "readelf -wi" on it.
160*1424dfb3Schristos    set got [remote_exec host "$READELF $READELFFLAGS -wi $tempfile" "" "/dev/null" "readelf.out"]
161*1424dfb3Schristos
162*1424dfb3Schristos    # Upload the results.
163*1424dfb3Schristos    set output [remote_upload host readelf.out]
164*1424dfb3Schristos
165*1424dfb3Schristos    file_on_host delete $tempfile
166*1424dfb3Schristos
167*1424dfb3Schristos    # Strip any superflous warnings.
168*1424dfb3Schristos    set got [prune_readelf_wi_warnings [lindex $got 1]]
169*1424dfb3Schristos
170*1424dfb3Schristos    if ![string match "" $got] then {
171*1424dfb3Schristos	fail "readelf $READELFFLAGS -wi (reason: unexpected output)"
172*1424dfb3Schristos	send_log $got
173*1424dfb3Schristos	send_log "\n"
174*1424dfb3Schristos	return
175*1424dfb3Schristos    }
176*1424dfb3Schristos
177*1424dfb3Schristos    if ![file size $output] then {
178*1424dfb3Schristos	# If the output file is empty, then this target does not
179*1424dfb3Schristos	# generate dwarf2 output.  This is not a failure.
180*1424dfb3Schristos	verbose "No output from 'readelf -wi'"
181*1424dfb3Schristos	untested "readelf -wi"
182*1424dfb3Schristos	return
183*1424dfb3Schristos    }
184*1424dfb3Schristos
185*1424dfb3Schristos    # Search for strings that should be in the output.
186*1424dfb3Schristos    set sought {
187*1424dfb3Schristos	".*DW_TAG_compile_unit.*"
188*1424dfb3Schristos	".*DW_TAG_subprogram.*"
189*1424dfb3Schristos	".*DW_TAG_base_type.*"
190*1424dfb3Schristos	".*DW_AT_producer.*(GNU C|indirect string).*"
191*1424dfb3Schristos	".*DW_AT_language.*(ANSI C|C11).*"
192*1424dfb3Schristos	".*DW_AT_name.*(testprog.c|indirect string).*"
193*1424dfb3Schristos	".*DW_AT_name.*fn.*"
194*1424dfb3Schristos	".*DW_AT_name.*(main|indirect string).*"
195*1424dfb3Schristos	".*\(DW_OP_addr: 0\).*"
196*1424dfb3Schristos    }
197*1424dfb3Schristos
198*1424dfb3Schristos    # The MSP430 in LARGE mode does not generate a DW_OP_addr.
199*1424dfb3Schristos    setup_xfail msp430*-*-*
200*1424dfb3Schristos
201*1424dfb3Schristos    foreach looked_for $sought {
202*1424dfb3Schristos	set lines [grep $output $looked_for]
203*1424dfb3Schristos	if ![llength $lines] then {
204*1424dfb3Schristos	    fail "readelf -wi: missing: $looked_for"
205*1424dfb3Schristos	    send_log readelf.out
206*1424dfb3Schristos	    return
207*1424dfb3Schristos	}
208*1424dfb3Schristos    }
209*1424dfb3Schristos
210*1424dfb3Schristos    file_on_host delete $output
211*1424dfb3Schristos
212*1424dfb3Schristos    # All done.
213*1424dfb3Schristos    pass "readelf -wi"
214*1424dfb3Schristos}
215*1424dfb3Schristos
216*1424dfb3Schristos# This tests "readelf -wa", but on a file with a compressed
217*1424dfb3Schristos# .debug_abbrev section.
218*1424dfb3Schristos
219*1424dfb3Schristosproc readelf_compressed_wa_test {} {
220*1424dfb3Schristos    global READELF
221*1424dfb3Schristos    global READELFFLAGS
222*1424dfb3Schristos    global srcdir
223*1424dfb3Schristos    global subdir
224*1424dfb3Schristos
225*1424dfb3Schristos    # Compile the compressed-debug-section test file.
226*1424dfb3Schristos    if { [target_compile $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o object debug] != "" } {
227*1424dfb3Schristos	verbose "Unable to compile test file."
228*1424dfb3Schristos	untested "readelf -wa (compressed)"
229*1424dfb3Schristos	return
230*1424dfb3Schristos    }
231*1424dfb3Schristos
232*1424dfb3Schristos    # Download it.
233*1424dfb3Schristos    set tempfile [remote_download host tmpdir/dw2-compressed.o]
234*1424dfb3Schristos
235*1424dfb3Schristos    # Run "readelf -wa" on it.
236*1424dfb3Schristos    set got [remote_exec host "$READELF $READELFFLAGS -wa $tempfile" "" "/dev/null" "readelf.out"]
237*1424dfb3Schristos
238*1424dfb3Schristos    # Upload the results.
239*1424dfb3Schristos    set output [remote_upload host readelf.out]
240*1424dfb3Schristos
241*1424dfb3Schristos    file_on_host delete $tempfile
242*1424dfb3Schristos
243*1424dfb3Schristos    if { [string compare [file_contents readelf.out] [file_contents $srcdir/$subdir/readelf.wa]] != 0 } then {
244*1424dfb3Schristos	fail "readelf -wa (compressed)"
245*1424dfb3Schristos	verbose "output is \n[file_contents readelf.out]" 2
246*1424dfb3Schristos	verbose "expected is \n[file_contents $srcdir/$subdir/readelf.wa]" 2
247*1424dfb3Schristos	return
248*1424dfb3Schristos    }
249*1424dfb3Schristos
250*1424dfb3Schristos    pass "readelf -wa (compressed)"
251*1424dfb3Schristos}
252*1424dfb3Schristos
253*1424dfb3Schristos# Test readelf's dumping abilities.
254*1424dfb3Schristos
255*1424dfb3Schristosproc readelf_dump_test {} {
256*1424dfb3Schristos    global READELF
257*1424dfb3Schristos    global READELFFLAGS
258*1424dfb3Schristos    global srcdir
259*1424dfb3Schristos    global subdir
260*1424dfb3Schristos
261*1424dfb3Schristos    # Assemble the dump test file.
262*1424dfb3Schristos    if {![binutils_assemble $srcdir/$subdir/dumptest.s tmpdir/dumptest.o]} then {
263*1424dfb3Schristos      unresolved "readelf -p: failed to assemble dump test file"
264*1424dfb3Schristos      return
265*1424dfb3Schristos    }
266*1424dfb3Schristos    # Download it.
267*1424dfb3Schristos    set tempfile [remote_download host tmpdir/dumptest.o]
268*1424dfb3Schristos
269*1424dfb3Schristos    # Run "readelf -p.data" on it.
270*1424dfb3Schristos    set sect_names [get_standard_section_names]
271*1424dfb3Schristos    if { $sect_names != "" } {
272*1424dfb3Schristos	set got [remote_exec host "$READELF $READELFFLAGS -p[lindex $sect_names 1] $tempfile" "" "/dev/null" "readelf.out"]
273*1424dfb3Schristos    } else {
274*1424dfb3Schristos	set got [remote_exec host "$READELF $READELFFLAGS -p.data $tempfile" "" "/dev/null" "readelf.out"]
275*1424dfb3Schristos    }
276*1424dfb3Schristos    set got [lindex $got 1]
277*1424dfb3Schristos
278*1424dfb3Schristos    # Upload the results.
279*1424dfb3Schristos    set output [remote_upload host readelf.out]
280*1424dfb3Schristos
281*1424dfb3Schristos    # Check for something going wrong.
282*1424dfb3Schristos    if ![string match "" $got] then {
283*1424dfb3Schristos	fail "readelf -p: unexpected output"
284*1424dfb3Schristos	send_log $got
285*1424dfb3Schristos	send_log "\n"
286*1424dfb3Schristos	return
287*1424dfb3Schristos    }
288*1424dfb3Schristos
289*1424dfb3Schristos    # Search for strings that should be in the output.
290*1424dfb3Schristos    set sought {
291*1424dfb3Schristos	".*test_string.*"
292*1424dfb3Schristos    }
293*1424dfb3Schristos
294*1424dfb3Schristos    foreach looked_for $sought {
295*1424dfb3Schristos	set lines [grep $output $looked_for]
296*1424dfb3Schristos	if ![llength $lines] then {
297*1424dfb3Schristos	    fail "readelf -p: missing: $looked_for"
298*1424dfb3Schristos	    send_log readelf.out
299*1424dfb3Schristos	    return
300*1424dfb3Schristos	}
301*1424dfb3Schristos    }
302*1424dfb3Schristos
303*1424dfb3Schristos    file_on_host delete $tempfile
304*1424dfb3Schristos    file_on_host delete $output
305*1424dfb3Schristos
306*1424dfb3Schristos    # All done.
307*1424dfb3Schristos    pass "readelf -p"
308*1424dfb3Schristos
309*1424dfb3Schristos    # XXX FIXME: Add test of readelf -x here
310*1424dfb3Schristos}
311*1424dfb3Schristos
312*1424dfb3Schristosif ![is_remote host] {
313*1424dfb3Schristos    if {[which $READELF] == 0} then {
314*1424dfb3Schristos        perror "$READELF does not exist"
315*1424dfb3Schristos        return
316*1424dfb3Schristos    }
317*1424dfb3Schristos}
318*1424dfb3Schristos
319*1424dfb3Schristossend_user "Version [binutil_version $READELF]"
320*1424dfb3Schristos
321*1424dfb3Schristos# Assemble the test file.
322*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
323*1424dfb3Schristos    unresolved "readelf -h bintest (failed to assemble)"
324*1424dfb3Schristos    unresolved "readelf -S bintest (failed to assemble)"
325*1424dfb3Schristos    unresolved "readelf -s bintest (failed to assemble)"
326*1424dfb3Schristos    unresolved "readelf -r bintest (failed to assemble)"
327*1424dfb3Schristos    global readelf_size
328*1424dfb3Schristos    set readelf_size ""
329*1424dfb3Schristos} else {
330*1424dfb3Schristos
331*1424dfb3Schristos    if ![is_remote host] {
332*1424dfb3Schristos	set tempfile tmpdir/bintest.o
333*1424dfb3Schristos    } else {
334*1424dfb3Schristos	set tempfile [remote_download host tmpdir/bintest.o]
335*1424dfb3Schristos    }
336*1424dfb3Schristos
337*1424dfb3Schristos    # First, determine the size, so specific output matchers can be used.
338*1424dfb3Schristos    readelf_find_size $tempfile 1
339*1424dfb3Schristos
340*1424dfb3Schristos    # Run the tests.
341*1424dfb3Schristos    readelf_test -h $tempfile readelf.h  {}
342*1424dfb3Schristos    readelf_test -S $tempfile readelf.s  {}
343*1424dfb3Schristos    setup_xfail "mips-*-*irix*"
344*1424dfb3Schristos    readelf_test -s $tempfile readelf.ss {}
345*1424dfb3Schristos    readelf_test -r $tempfile readelf.r  {}
346*1424dfb3Schristos}
347*1424dfb3Schristos
348*1424dfb3Schristos# Test demangling symbol names.
349*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/mangled.s tmpdir/mangled.o]} then {
350*1424dfb3Schristos    unresolved "readelf -s -C bintest (failed to assemble)"
351*1424dfb3Schristos} else {
352*1424dfb3Schristos
353*1424dfb3Schristos    if ![is_remote host] {
354*1424dfb3Schristos	set tempfile tmpdir/mangled.o
355*1424dfb3Schristos    } else {
356*1424dfb3Schristos	set tempfile [remote_download host tmpdir/mangled.o]
357*1424dfb3Schristos    }
358*1424dfb3Schristos
359*1424dfb3Schristos    # Run the test.
360*1424dfb3Schristos    readelf_test {--syms --demangle --wide} $tempfile readelf.demangled {}
361*1424dfb3Schristos}
362*1424dfb3Schristos
363*1424dfb3Schristosreadelf_wi_test
364*1424dfb3Schristosreadelf_compressed_wa_test
365*1424dfb3Schristos
366*1424dfb3Schristosreadelf_dump_test
367*1424dfb3Schristosrun_dump_test "pr25543"
368*1424dfb3Schristos
369*1424dfb3Schristos
370*1424dfb3Schristos# PR 13482 - Check for off-by-one errors when dumping .note sections.
371*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/version.s tmpdir/version.o]} then {
372*1424dfb3Schristos    unresolved "readelf -n version (failed to assemble)"
373*1424dfb3Schristos} else {
374*1424dfb3Schristos
375*1424dfb3Schristos    if ![is_remote host] {
376*1424dfb3Schristos	set tempfile tmpdir/version.o
377*1424dfb3Schristos    } else {
378*1424dfb3Schristos	set tempfile [remote_download host tmpdir/version.o]
379*1424dfb3Schristos    }
380*1424dfb3Schristos
381*1424dfb3Schristos    readelf_test -n $tempfile readelf.n  {}
382*1424dfb3Schristos}
383*1424dfb3Schristos
384*1424dfb3Schristos
385*1424dfb3Schristos# PR 18374 - Check that relocations against the .debug_loc section
386*1424dfb3Schristos# do not prevent readelf from displaying all the location lists.
387*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/pr18374.s tmpdir/pr18374.o]} then {
388*1424dfb3Schristos    unresolved "readelf --debug-dump=loc pr18374 (failed to assemble)"
389*1424dfb3Schristos} else {
390*1424dfb3Schristos
391*1424dfb3Schristos    if ![is_remote host] {
392*1424dfb3Schristos	set tempfile tmpdir/pr18374.o
393*1424dfb3Schristos    } else {
394*1424dfb3Schristos	set tempfile [remote_download host tmpdir/pr18374.o]
395*1424dfb3Schristos    }
396*1424dfb3Schristos
397*1424dfb3Schristos    readelf_test --debug-dump=loc $tempfile readelf.pr18374  {}
398*1424dfb3Schristos}
399*1424dfb3Schristos
400*1424dfb3Schristos
401*1424dfb3Schristos# locview - Check dumping of location lists with location views.
402*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/locview-1.s tmpdir/locview-1.o]} then {
403*1424dfb3Schristos    unresolved "readelf --debug-dump=loc locview-1 (failed to assemble)"
404*1424dfb3Schristos} else {
405*1424dfb3Schristos
406*1424dfb3Schristos    if ![is_remote host] {
407*1424dfb3Schristos	set tempfile tmpdir/locview-1.o
408*1424dfb3Schristos    } else {
409*1424dfb3Schristos	set tempfile [remote_download host tmpdir/locview-1.o]
410*1424dfb3Schristos    }
411*1424dfb3Schristos
412*1424dfb3Schristos    readelf_test --debug-dump=loc $tempfile readelf.locview-1  {}
413*1424dfb3Schristos}
414*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/locview-2.s tmpdir/locview-2.o]} then {
415*1424dfb3Schristos    unresolved "readelf --debug-dump=loc locview-2 (failed to assemble)"
416*1424dfb3Schristos} else {
417*1424dfb3Schristos
418*1424dfb3Schristos    if ![is_remote host] {
419*1424dfb3Schristos	set tempfile tmpdir/locview-2.o
420*1424dfb3Schristos    } else {
421*1424dfb3Schristos	set tempfile [remote_download host tmpdir/locview-2.o]
422*1424dfb3Schristos    }
423*1424dfb3Schristos
424*1424dfb3Schristos    readelf_test --debug-dump=loc $tempfile readelf.locview-2  {}
425*1424dfb3Schristos}
426*1424dfb3Schristos
427*1424dfb3Schristos
428*1424dfb3Schristos# Check that decompressed dumps work.
429*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/z.s tmpdir/z.o]} then {
430*1424dfb3Schristos    unresolved "readelf --decompress --hex-dump .debug_loc z (failed to assemble)"
431*1424dfb3Schristos} else {
432*1424dfb3Schristos
433*1424dfb3Schristos    if ![is_remote host] {
434*1424dfb3Schristos	set tempfile tmpdir/z.o
435*1424dfb3Schristos    } else {
436*1424dfb3Schristos	set tempfile [remote_download host tmpdir/z.o]
437*1424dfb3Schristos    }
438*1424dfb3Schristos
439*1424dfb3Schristos    readelf_test {--decompress --hex-dump .debug_loc} $tempfile readelf.z  {}
440*1424dfb3Schristos}
441*1424dfb3Schristos
442*1424dfb3Schristos# Skip the next test for the RISCV architectures because they
443*1424dfb3Schristos# do not support .ULEB128 pseudo-ops with non-constant values.
444*1424dfb3Schristosif ![istarget "riscv*-*-*"] then {
445*1424dfb3Schristos
446*1424dfb3Schristos    set hpux ""
447*1424dfb3Schristos    if [istarget "hppa*64*-*-hpux*"] {
448*1424dfb3Schristos	set hpux "--defsym HPUX=1"
449*1424dfb3Schristos    }
450*1424dfb3Schristos
451*1424dfb3Schristos    # Assemble the DWARF-5 test file.
452*1424dfb3Schristos    if {![binutils_assemble_flags $srcdir/$subdir/dw5.S tmpdir/dw5.o $hpux]} then {
453*1424dfb3Schristos	unresolved "readelf -wiaoRlL dw5 (failed to assemble)"
454*1424dfb3Schristos    } else {
455*1424dfb3Schristos
456*1424dfb3Schristos	# Download it.
457*1424dfb3Schristos	if ![is_remote host] {
458*1424dfb3Schristos	    set tempfile tmpdir/dw5.o
459*1424dfb3Schristos	} else {
460*1424dfb3Schristos	    set tempfile [remote_download host tmpdir/dw5.o]
461*1424dfb3Schristos	}
462*1424dfb3Schristos
463*1424dfb3Schristos	# First, determine the size, so specific output matchers can be used.
464*1424dfb3Schristos	readelf_find_size $tempfile 2
465*1424dfb3Schristos
466*1424dfb3Schristos	# Make sure that readelf can decode the contents.
467*1424dfb3Schristos	readelf_test -wiaoRlL $tempfile dw5.W {}
468*1424dfb3Schristos    }
469*1424dfb3Schristos}
470*1424dfb3Schristos
471*1424dfb3Schristos# Assemble the DWARF-5 attributes test file.
472*1424dfb3Schristosif {![binutils_assemble_flags $srcdir/$subdir/dwarf-attributes.S tmpdir/dwarf-attributes.o ""]} then {
473*1424dfb3Schristos    unresolved "readelf -wi dwarf-attributes (failed to assemble)"
474*1424dfb3Schristos} else {
475*1424dfb3Schristos    # Download it.
476*1424dfb3Schristos    if ![is_remote host] {
477*1424dfb3Schristos	set tempfile tmpdir/dwarf-attributes.o
478*1424dfb3Schristos    } else {
479*1424dfb3Schristos	set tempfile [remote_download host tmpdir/dwarf-attributes.o]
480*1424dfb3Schristos    }
481*1424dfb3Schristos
482*1424dfb3Schristos    # First, determine the size, so specific output matchers can be used.
483*1424dfb3Schristos    readelf_find_size $tempfile 3
484*1424dfb3Schristos
485*1424dfb3Schristos    # Make sure that readelf can decode the contents.
486*1424dfb3Schristos    readelf_test -wi $tempfile dwarf-attributes.W {}
487*1424dfb3Schristos}
488*1424dfb3Schristos
489*1424dfb3Schristos# Check that debug link sections can be dumped.
490*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/debuglink.s tmpdir/debuglink.o]} then {
491*1424dfb3Schristos    unresolved "readelf --debug-dump=links (failed to assemble debuglink.s)"
492*1424dfb3Schristos} else {
493*1424dfb3Schristos    if ![is_remote host] {
494*1424dfb3Schristos	set tempfile tmpdir/debuglink.o
495*1424dfb3Schristos    } else {
496*1424dfb3Schristos	set tempfile [remote_download host tmpdir/debuglink.o]
497*1424dfb3Schristos    }
498*1424dfb3Schristos
499*1424dfb3Schristos    readelf_test {--debug-dump=links} $tempfile readelf.k  {}
500*1424dfb3Schristos
501*1424dfb3Schristos    # Check that debug link sections can be followed.
502*1424dfb3Schristos    if {![binutils_assemble $srcdir/$subdir/linkdebug.s tmpdir/linkdebug.debug]} then {
503*1424dfb3Schristos	unresolved "readelf --debug-dump=follow-links (failed to assemble linkdebug.s)"
504*1424dfb3Schristos    } else {
505*1424dfb3Schristos	if [is_remote host] {
506*1424dfb3Schristos	    set tempfile2 [remote_download host tmpdir/linkdebug.debug]
507*1424dfb3Schristos	}
508*1424dfb3Schristos
509*1424dfb3Schristos	readelf_test {-wKis} $tempfile readelf.wKis  {}
510*1424dfb3Schristos    }
511*1424dfb3Schristos}
512*1424dfb3Schristos
513*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/dwo.s tmpdir/dwo.o]} then {
514*1424dfb3Schristos    unresolved "readelf --debug-dump=links (failed to assemble dwo.s)"
515*1424dfb3Schristos} else {
516*1424dfb3Schristos    if ![is_remote host] {
517*1424dfb3Schristos	set tempfile tmpdir/dwo.o
518*1424dfb3Schristos    } else {
519*1424dfb3Schristos	set tempfile [remote_download host tmpdir/dwo.o]
520*1424dfb3Schristos    }
521*1424dfb3Schristos
522*1424dfb3Schristos    readelf_test {--debug-dump=links} $tempfile readelf.k2  {}
523*1424dfb3Schristos}
524*1424dfb3Schristos
525*1424dfb3Schristosif {![binutils_assemble $srcdir/$subdir/zero-sec.s tmpdir/zero-sec.o]} then {
526*1424dfb3Schristos    unresolved "readelf --enable-checks (failed to assemble zero-sec.s)"
527*1424dfb3Schristos} else {
528*1424dfb3Schristos    if ![is_remote host] {
529*1424dfb3Schristos	set tempfile tmpdir/zero-sec.o
530*1424dfb3Schristos    } else {
531*1424dfb3Schristos	set tempfile [remote_download host tmpdir/zero-sec.o]
532*1424dfb3Schristos    }
533*1424dfb3Schristos
534*1424dfb3Schristos    readelf_test {--enable-checks --sections --wide} $tempfile zero-sec.r {}
535*1424dfb3Schristos}
536*1424dfb3Schristos
537*1424dfb3Schristosif ![is_remote host] {
538*1424dfb3Schristos    set test $srcdir/$subdir/pr26112.o.bz2
539*1424dfb3Schristos    # We need to strip the ".bz2", but can leave the dirname.
540*1424dfb3Schristos    set t $subdir/[file tail $test]
541*1424dfb3Schristos    set testname [file rootname $t]
542*1424dfb3Schristos    verbose $testname
543*1424dfb3Schristos    set tempfile tmpdir/pr26112.o
544*1424dfb3Schristos    if {[catch "system \"bzip2 -dc $test > $tempfile\""] != 0} {
545*1424dfb3Schristos	untested "bzip2 -dc ($testname)"
546*1424dfb3Schristos    } else {
547*1424dfb3Schristos	readelf_test {--debug-dump=macro} $tempfile pr26112.r {}
548*1424dfb3Schristos    }
549*1424dfb3Schristos}
550