binutils-gdb/binutils/testsuite/binutils-all/readelf.exp
H.J. Lu d1bcae833b ELF: Don't generate unused section symbols
For ELF targets, section symbols are required only for relocations.
With -ffunction-sections -fdata-sections, there can be many unused
section symbols.  Sizes of libstdc++.a on Linux/x86-64 in GCC 11 are

With unused section symbols   : 39411698 bytes
Without unused section symbols: 39227002 bytes

The unused section symbols in libstdc++.a occupy more than 180 KB.

Add BSF_SECTION_SYM_USED to indicate if a section symbol should be
included in the symbol table.  The BSF_SECTION_SYM_USED should be set
if the section symbol is used for relocation or the section symbol is
always included in the symbol table.

Add keep_unused_section_symbols to bfd_target to indicate if unused
section symbols should be kept.  If TARGET_KEEP_UNUSED_SECTION_SYMBOLS
is defined as FALSE, unused ection symbols will be removed.

Tested on Linux/x86.  Other ELF backends need to:

1. Define TARGET_KEEP_UNUSED_SECTION_SYMBOLS to FALSE.
2. Mark used section symbols in assembler backend.
3. Remove unused section symbols from expected assembler and linker
outputs.

bfd/

	PR 27109
	* aix386-core.c (core_aix386_vec): Initialize
	keep_unused_section_symbol to TARGET_KEEP_UNUSED_SECTION_SYMBOLS.
	* aout-target.h (MY (vec)): Likewise.
	* binary.c (binary_vec): Likewise.
	* cisco-core.c (core_cisco_be_vec): Likewise.
	(core_cisco_le_vec): Likewise.
	* coff-alpha.c (alpha_ecoff_le_vec): Likewise.
	* coff-i386.c (TARGET_SYM): Likewise.
	(TARGET_SYM_BIG): Likewise.
	* coff-ia64.c (TARGET_SYM): Likewise.
	* coff-mips.c (mips_ecoff_le_vec): Likewise.
	(mips_ecoff_be_vec): Likewise.
	(mips_ecoff_bele_vec): Likewise.
	* coff-rs6000.c (rs6000_xcoff_vec): Likewise.
	(powerpc_xcoff_vec): Likewise.
	* coff-sh.c (sh_coff_small_vec): Likewise.
	(sh_coff_small_le_vec): Likewise.
	* coff-tic30.c (tic30_coff_vec): Likewise.
	* coff-tic54x.c (tic54x_coff0_vec): Likewise.
	(tic54x_coff0_beh_vec): Likewise.
	(tic54x_coff1_vec): Likewise.
	(tic54x_coff1_beh_vec): Likewise.
	(tic54x_coff2_vec): Likewise.
	(tic54x_coff2_beh_vec): Likewise.
	* coff-x86_64.c (TARGET_SYM): Likewise.
	(TARGET_SYM_BIG): Likewise.
	* coff64-rs6000.c (rs6000_xcoff64_vec): Likewise.
	(rs6000_xcoff64_aix_vec): Likewise.
	* coffcode.h (CREATE_BIG_COFF_TARGET_VEC): Likewise.
	(CREATE_BIGHDR_COFF_TARGET_VEC): Likewise.
	(CREATE_LITTLE_COFF_TARGET_VEC): Likewise.
	* elfxx-target.h (TARGET_BIG_SYM): Likewise.
	(TARGET_LITTLE_SYM): Likewise.
	* hppabsd-core.c (core_hppabsd_vec): Likewise.
	* hpux-core.c (core_hpux_vec): Likewise.
	* i386msdos.c (i386_msdos_vec): Likewise.
	* ihex.c (ihex_vec): Likewise.
	* irix-core.c (core_irix_vec): Likewise.
	* mach-o-target.c (TARGET_NAME): Likewise.
	* mmo.c (mmix_mmo_vec): Likewise.
	* netbsd-core.c (core_netbsd_vec): Likewise.
	* osf-core.c (core_osf_vec): Likewise.
	* pdp11.c (MY (vec)): Likewise.
	* pef.c (pef_vec): Likewise.
	(pef_xlib_vec): Likewise.
	* plugin.c (plugin_vec): Likewise.
	* ppcboot.c (powerpc_boot_vec): Likewise.
	* ptrace-core.c (core_ptrace_vec): Likewise.
	* sco5-core.c (core_sco5_vec): Likewise.
	* som.c (hppa_som_vec): Likewise.
	* srec.c (srec_vec): Likewise.
	(symbolsrec_vec): Likewise.
	* tekhex.c (tekhex_vec): Likewise.
	* trad-core.c (core_trad_vec): Likewise.
	* verilog.c (verilog_vec): Likewise.
	* vms-alpha.c (alpha_vms_vec): Likewise.
	* vms-lib.c (alpha_vms_lib_txt_vec): Likewise.
	* wasm-module.c (wasm_vec): Likewise.
	* xsym.c (sym_vec): Likewise.
	* elf.c (ignore_section_sym): Return TRUE if BSF_SECTION_SYM_USED
	isn't set.
	(elf_map_symbols): Don't include ignored section symbols.
	* elfcode.h (elf_slurp_symbol_table): Also set
	BSF_SECTION_SYM_USED on STT_SECTION symbols.
	* elflink.c (bfd_elf_final_link): Generated section symbols only
	when emitting relocations or reqired.
	* elfxx-x86.h (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New.
	* syms.c (BSF_SECTION_SYM_USED): New.
	* targets.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New.
	(bfd_target): Add keep_unused_section_symbols.
	(bfd_keep_unused_section_symbols): New.
	* bfd-in2.h: Regenerated.

binutils/

	PR 27109
	* objcopy.c (copy_object): Handle section symbols for
	non-relocatable inputs.
	* testsuite/binutils-all/readelf.exp (readelf_test): Check
	is_elf_unused_section_symbols.
	* testsuite/binutils-all/readelf.s-64: Updated.
	* testsuite/binutils-all/readelf.ss: Likewise.
	* testsuite/binutils-all/readelf.ss-64: Likewise.
	* testsuite/binutils-all/readelf.s-64-unused: New file.
	* testsuite/binutils-all/readelf.ss-64-unused: Likewise.
	* testsuite/binutils-all/readelf.ss-unused: Likewise.
	* testsuite/lib/binutils-common.exp
	(is_elf_unused_section_symbols): New proc.

gas/ChangeLog:

	PR 27109
	* read.c (s_reloc): Call symbol_mark_used_in_reloc on the
	section symbol.
	* subsegs.c (subseg_set_rest): Set BSF_SECTION_SYM_USED if needed.
	* write.c (adjust_reloc_syms): Call symbol_mark_used_in_reloc
	on the section symbol.
	(set_symtab): Don't generate unused section symbols.
	(maybe_generate_build_notes): Call symbol_mark_used_in_reloc
	on the section symbol.
	* config/obj-elf.c (elf_adjust_symtab): Call
	symbol_mark_used_in_reloc on the group signature symbol.
	* testsuite/gas/cfi/cfi-label.d: Remove unused section symbols
	from expected output.
	* testsuite/gas/elf/elf.exp (run_elf_list_test): Check
	is_elf_unused_section_symbols.
	* testsuite/gas/elf/section2.e: Updated.
	* testsuite/gas/elf/section2.e-unused: New file.
	* testsuite/gas/elf/symver.d: Remove unused section symbols.
	* testsuite/gas/i386/ilp32/elf/symver.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-size-1.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-size-3.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-size-5.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-unwind.d: Likewise.
	* testsuite/gas/i386/size-1.d: Likewise.
	* testsuite/gas/i386/size-3.d: Likewise.
	* testsuite/gas/i386/svr4.d: Likewise.
	* testsuite/gas/i386/x86-64-size-1.d: Likewise.
	* testsuite/gas/i386/x86-64-size-3.d: Likewise.
	* testsuite/gas/i386/x86-64-size-5.d: Likewise.
	* testsuite/gas/i386/x86-64-unwind.d: Likewise.

ld/

	PR 27109
	* testsuite/ld-elf/export-class.sd: Adjust the expected output.
	* testsuite/ld-elf/loadaddr3b.d: Likewise.
	* testsuite/ld-i386/ibt-plt-1.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
	* testsuite/ld-i386/pr19636-1d.d: Likewise.
	* testsuite/ld-i386/pr19636-1l.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64.d: Likewise.
	* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/pr19609-4e.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6a.d: Likewise.
	* testsuite/ld-x86-64/pr19609-6b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7b.d: Likewise.
	* testsuite/ld-x86-64/pr19609-7d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2l.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
	* testsuite/ld-x86-64/pr23854.d: Likewise.
	* testsuite/ld-x86-64/pr25416-3.d: Likewise.
	* testsuite/ld-x86-64/pr25416-4.d: Likewise.
	* testsuite/ld-i386/plt-pic.pd: Likewise.
	* testsuite/ld-i386/plt-pic2.dd: Likewise.
	* testsuite/ld-i386/plt.pd: Likewise.
	* testsuite/ld-i386/plt2.dd: Likewise.
	* testsuite/ld-i386/tlsbin.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.rd: Likewise.
	* testsuite/ld-i386/tlsbindesc.rd: Likewise.
	* testsuite/ld-i386/tlsdesc.rd: Likewise.
	* testsuite/ld-i386/tlsgdesc.rd: Likewise.
	* testsuite/ld-i386/tlsnopic.rd: Likewise.
	* testsuite/ld-i386/tlspic.rd: Likewise.
	* testsuite/ld-i386/tlspic2.rd: Likewise.
	* testsuite/ld-x86-64/mpx3.dd: Likewise.
	* testsuite/ld-x86-64/mpx3n.dd: Likewise.
	* testsuite/ld-x86-64/mpx4.dd: Likewise.
	* testsuite/ld-x86-64/mpx4n.dd: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-1.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-2.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4.od: Likewise.
	* testsuite/ld-x86-64/plt.pd: Likewise.
	* testsuite/ld-x86-64/plt2.dd: Likewise.
	* testsuite/ld-x86-64/tlsbin.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.rd: Likewise.
	* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsgdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlspic.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2.rd: Likewise.
	* testsuite/ld-elf/sec64k.exp: Check
	is_elf_unused_section_symbols.
2021-01-07 06:46:55 -08:00

561 lines
16 KiB
Plaintext

# Copyright (C) 1999-2021 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@prep.ai.mit.edu
# Written by Nick Clifton <nickc@cygnus.com>
# Based on scripts written by Ian Lance Taylor <ian@cygnus.com>
# and Ken Raeburn <raeburn@cygnus.com>.
# Exclude non-ELF targets.
if ![is_elf_format] {
verbose "$READELF is only intended for ELF targets" 2
return
}
# First some helpful procedures, then the tests themselves
# Return the contents of the filename given
proc file_contents { filename } {
set file [open $filename r]
set contents [read $file]
close $file
return $contents
}
# Find out the size by reading the output of the EI_CLASS field.
# Similar to the test for readelf -h, but we're just looking for the
# EI_CLASS line here.
proc readelf_find_size { binary_file test_iteration } {
global READELF
global READELFFLAGS
global readelf_size
set readelf_size ""
set testname "finding out ELF size with readelf -h ($test_iteration)"
set got [remote_exec host "$READELF $READELFFLAGS -h $binary_file" "" "/dev/null" "readelf.out"]
if [is_remote host] then {
remote_upload host "readelf.out"
}
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then {
send_log $got
fail $testname
return
}
if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
[file_contents readelf.out] nil readelf_size] } {
verbose -log "EI_CLASS field not found in output"
verbose -log "output is \n[file_contents readelf.out]"
fail $testname
return
} else {
verbose -log "ELF size is $readelf_size"
}
pass $testname
}
# Run an individual readelf test.
# Basically readelf is run on the binary_file with the given options.
# Readelf's output is captured and then compared against the contents
# of the regexp_file-readelf_size if it exists, else regexp_file.
proc readelf_test { options binary_file regexp_file xfails } {
global READELF
global READELFFLAGS
global readelf_size
global srcdir
global subdir
set testname "readelf $options [file rootname [file tail $binary_file]]"
send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n"
set got [remote_exec host "$READELF $READELFFLAGS $options $binary_file" "" "/dev/null" "readelf.out"]
foreach xfail $xfails {
setup_xfail $xfail
}
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
fail "$testname (reason: unexpected output)"
send_log $got
send_log "\n"
return
}
if { [is_elf_unused_section_symbols ] } {
set target_machine unused
} else {
set target_machine ""
}
if [istarget "mips*-*-*"] then {
if [is_bad_symtab] then {
set target_machine mips
} else {
set target_machine tmips
}
}
if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then {
set regexp_file $regexp_file-$readelf_size-$target_machine
} elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then {
set regexp_file $regexp_file-$target_machine
} elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then {
set regexp_file $regexp_file-$readelf_size
}
if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then {
fail $testname
verbose "output is \n[file_contents readelf.out]" 2
return
}
pass $testname
}
# Simple proc to skip certain expected warning messages.
proc prune_readelf_wi_warnings { text } {
regsub -all "(^|\n)(.*Skipping unexpected symbol type.*)" $text "\\1" text
return $text
}
# Testing the "readelf -wi" option is difficult because there
# is no guaranteed order to the output, and because some ports
# will use indirect string references, whilst others will use
# direct references. So instead of having an expected output
# file, like the other readelf tests, we grep for strings that
# really ought to be there.
proc readelf_wi_test {} {
global READELF
global READELFFLAGS
global srcdir
global subdir
# Compile the second test file.
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
verbose "Unable to compile test file."
untested "readelf -wi"
return
}
# Download it.
set tempfile [remote_download host tmpdir/testprog.o]
# Run "readelf -wi" on it.
set got [remote_exec host "$READELF $READELFFLAGS -wi $tempfile" "" "/dev/null" "readelf.out"]
# Upload the results.
set output [remote_upload host readelf.out]
file_on_host delete $tempfile
# Strip any superflous warnings.
set got [prune_readelf_wi_warnings [lindex $got 1]]
if ![string match "" $got] then {
fail "readelf $READELFFLAGS -wi (reason: unexpected output)"
send_log $got
send_log "\n"
return
}
if ![file size $output] then {
# If the output file is empty, then this target does not
# generate dwarf2 output. This is not a failure.
verbose "No output from 'readelf -wi'"
untested "readelf -wi"
return
}
# Search for strings that should be in the output.
set sought {
".*DW_TAG_compile_unit.*"
".*DW_TAG_subprogram.*"
".*DW_TAG_base_type.*"
".*DW_AT_producer.*(GNU C|indirect string).*"
".*DW_AT_language.*(ANSI C|C11).*"
".*DW_AT_name.*(testprog.c|indirect string).*"
".*DW_AT_name.*fn.*"
".*DW_AT_name.*(main|indirect string).*"
".*\(DW_OP_addr: 0\).*"
}
# The MSP430 in LARGE mode does not generate a DW_OP_addr.
setup_xfail msp430*-*-*
foreach looked_for $sought {
set lines [grep $output $looked_for]
if ![llength $lines] then {
fail "readelf -wi: missing: $looked_for"
send_log readelf.out
return
}
}
file_on_host delete $output
# All done.
pass "readelf -wi"
}
# This tests "readelf -wa", but on a file with a compressed
# .debug_abbrev section.
proc readelf_compressed_wa_test {} {
global READELF
global READELFFLAGS
global srcdir
global subdir
# Compile the compressed-debug-section test file.
if { [target_compile $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o object debug] != "" } {
verbose "Unable to compile test file."
untested "readelf -wa (compressed)"
return
}
# Download it.
set tempfile [remote_download host tmpdir/dw2-compressed.o]
# Run "readelf -wa" on it.
set got [remote_exec host "$READELF $READELFFLAGS -wa $tempfile" "" "/dev/null" "readelf.out"]
# Upload the results.
set output [remote_upload host readelf.out]
file_on_host delete $tempfile
if { [string compare [file_contents readelf.out] [file_contents $srcdir/$subdir/readelf.wa]] != 0 } then {
fail "readelf -wa (compressed)"
verbose "output is \n[file_contents readelf.out]" 2
verbose "expected is \n[file_contents $srcdir/$subdir/readelf.wa]" 2
return
}
pass "readelf -wa (compressed)"
}
# Test readelf's dumping abilities.
proc readelf_dump_test {} {
global READELF
global READELFFLAGS
global srcdir
global subdir
# Assemble the dump test file.
if {![binutils_assemble $srcdir/$subdir/dumptest.s tmpdir/dumptest.o]} then {
unresolved "readelf -p: failed to assemble dump test file"
return
}
# Download it.
set tempfile [remote_download host tmpdir/dumptest.o]
# Run "readelf -p.data" on it.
set sect_names [get_standard_section_names]
if { $sect_names != "" } {
set got [remote_exec host "$READELF $READELFFLAGS -p[lindex $sect_names 1] $tempfile" "" "/dev/null" "readelf.out"]
} else {
set got [remote_exec host "$READELF $READELFFLAGS -p.data $tempfile" "" "/dev/null" "readelf.out"]
}
set got [lindex $got 1]
# Upload the results.
set output [remote_upload host readelf.out]
# Check for something going wrong.
if ![string match "" $got] then {
fail "readelf -p: unexpected output"
send_log $got
send_log "\n"
return
}
# Search for strings that should be in the output.
set sought {
".*test_string.*"
}
foreach looked_for $sought {
set lines [grep $output $looked_for]
if ![llength $lines] then {
fail "readelf -p: missing: $looked_for"
send_log readelf.out
return
}
}
file_on_host delete $tempfile
file_on_host delete $output
# All done.
pass "readelf -p"
# XXX FIXME: Add test of readelf -x here
}
if ![is_remote host] {
if {[which $READELF] == 0} then {
perror "$READELF does not exist"
return
}
}
send_user "Version [binutil_version $READELF]"
# Assemble the test file.
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
unresolved "readelf -h bintest (failed to assemble)"
unresolved "readelf -S bintest (failed to assemble)"
unresolved "readelf -s bintest (failed to assemble)"
unresolved "readelf -r bintest (failed to assemble)"
global readelf_size
set readelf_size ""
} else {
if ![is_remote host] {
set tempfile tmpdir/bintest.o
} else {
set tempfile [remote_download host tmpdir/bintest.o]
}
# First, determine the size, so specific output matchers can be used.
readelf_find_size $tempfile 1
# Run the tests.
readelf_test -h $tempfile readelf.h {}
readelf_test -S $tempfile readelf.s {}
setup_xfail "mips-*-*irix*"
readelf_test -s $tempfile readelf.ss {}
readelf_test -r $tempfile readelf.r {}
}
# Test demangling symbol names.
if {![binutils_assemble $srcdir/$subdir/mangled.s tmpdir/mangled.o]} then {
unresolved "readelf -s -C bintest (failed to assemble)"
} else {
if ![is_remote host] {
set tempfile tmpdir/mangled.o
} else {
set tempfile [remote_download host tmpdir/mangled.o]
}
# Run the test.
readelf_test {--syms --demangle --wide} $tempfile readelf.demangled {}
}
readelf_wi_test
readelf_compressed_wa_test
readelf_dump_test
# These dump tests require an assembler.
if {[which $AS] != 0} then {
run_dump_test "pr25543"
run_dump_test "retain1a"
run_dump_test "retain1b"
run_dump_test "readelf-maskos-1a"
run_dump_test "readelf-maskos-1b"
}
# PR 13482 - Check for off-by-one errors when dumping .note sections.
if {![binutils_assemble $srcdir/$subdir/version.s tmpdir/version.o]} then {
unresolved "readelf -n version (failed to assemble)"
} else {
if ![is_remote host] {
set tempfile tmpdir/version.o
} else {
set tempfile [remote_download host tmpdir/version.o]
}
readelf_test -n $tempfile readelf.n {}
}
# PR 18374 - Check that relocations against the .debug_loc section
# do not prevent readelf from displaying all the location lists.
if {![binutils_assemble $srcdir/$subdir/pr18374.s tmpdir/pr18374.o]} then {
unresolved "readelf --debug-dump=loc pr18374 (failed to assemble)"
} else {
if ![is_remote host] {
set tempfile tmpdir/pr18374.o
} else {
set tempfile [remote_download host tmpdir/pr18374.o]
}
readelf_test --debug-dump=loc $tempfile readelf.pr18374 {}
}
# locview - Check dumping of location lists with location views.
if {![binutils_assemble $srcdir/$subdir/locview-1.s tmpdir/locview-1.o]} then {
unresolved "readelf --debug-dump=loc locview-1 (failed to assemble)"
} else {
if ![is_remote host] {
set tempfile tmpdir/locview-1.o
} else {
set tempfile [remote_download host tmpdir/locview-1.o]
}
readelf_test --debug-dump=loc $tempfile readelf.locview-1 {}
}
if {![binutils_assemble $srcdir/$subdir/locview-2.s tmpdir/locview-2.o]} then {
unresolved "readelf --debug-dump=loc locview-2 (failed to assemble)"
} else {
if ![is_remote host] {
set tempfile tmpdir/locview-2.o
} else {
set tempfile [remote_download host tmpdir/locview-2.o]
}
readelf_test --debug-dump=loc $tempfile readelf.locview-2 {}
}
# Check that decompressed dumps work.
if {![binutils_assemble $srcdir/$subdir/z.s tmpdir/z.o]} then {
unresolved "readelf --decompress --hex-dump .debug_loc z (failed to assemble)"
} else {
if ![is_remote host] {
set tempfile tmpdir/z.o
} else {
set tempfile [remote_download host tmpdir/z.o]
}
readelf_test {--decompress --hex-dump .debug_loc} $tempfile readelf.z {}
}
# Skip the next test for the RISCV architectures because they
# do not support .ULEB128 pseudo-ops with non-constant values.
if ![istarget "riscv*-*-*"] then {
set hpux ""
if [istarget "hppa*64*-*-hpux*"] {
set hpux "--defsym HPUX=1"
}
# Assemble the DWARF-5 test file.
if {![binutils_assemble_flags $srcdir/$subdir/dw5.S tmpdir/dw5.o $hpux]} then {
unresolved "readelf -wiaoRlL dw5 (failed to assemble)"
} else {
# Download it.
if ![is_remote host] {
set tempfile tmpdir/dw5.o
} else {
set tempfile [remote_download host tmpdir/dw5.o]
}
# First, determine the size, so specific output matchers can be used.
readelf_find_size $tempfile 2
# Make sure that readelf can decode the contents.
readelf_test -wiaoRlL $tempfile dw5.W {}
}
}
# Assemble the DWARF-5 attributes test file.
if {![binutils_assemble_flags $srcdir/$subdir/dwarf-attributes.S tmpdir/dwarf-attributes.o ""]} then {
unresolved "readelf -wi dwarf-attributes (failed to assemble)"
} else {
# Download it.
if ![is_remote host] {
set tempfile tmpdir/dwarf-attributes.o
} else {
set tempfile [remote_download host tmpdir/dwarf-attributes.o]
}
# First, determine the size, so specific output matchers can be used.
readelf_find_size $tempfile 3
# Make sure that readelf can decode the contents.
readelf_test -wi $tempfile dwarf-attributes.W {}
}
# Check that debug link sections can be dumped.
if {![binutils_assemble $srcdir/$subdir/debuglink.s tmpdir/debuglink.o]} then {
unresolved "readelf --debug-dump=links (failed to assemble debuglink.s)"
} else {
if ![is_remote host] {
set tempfile tmpdir/debuglink.o
} else {
set tempfile [remote_download host tmpdir/debuglink.o]
}
readelf_test {--debug-dump=links} $tempfile readelf.k {}
# Check that debug link sections can be followed.
if {![binutils_assemble $srcdir/$subdir/linkdebug.s tmpdir/linkdebug.debug]} then {
unresolved "readelf --debug-dump=follow-links (failed to assemble linkdebug.s)"
} else {
if [is_remote host] {
set tempfile2 [remote_download host tmpdir/linkdebug.debug]
}
readelf_test {-wKis} $tempfile readelf.wKis {}
}
}
if {![binutils_assemble $srcdir/$subdir/dwo.s tmpdir/dwo.o]} then {
unresolved "readelf --debug-dump=links (failed to assemble dwo.s)"
} else {
if ![is_remote host] {
set tempfile tmpdir/dwo.o
} else {
set tempfile [remote_download host tmpdir/dwo.o]
}
readelf_test {--debug-dump=links} $tempfile readelf.k2 {}
}
if {![binutils_assemble $srcdir/$subdir/zero-sec.s tmpdir/zero-sec.o]} then {
unresolved "readelf --enable-checks (failed to assemble zero-sec.s)"
} else {
if ![is_remote host] {
set tempfile tmpdir/zero-sec.o
} else {
set tempfile [remote_download host tmpdir/zero-sec.o]
}
readelf_test {--enable-checks --sections --wide} $tempfile zero-sec.r {}
}
if ![is_remote host] {
set test $srcdir/$subdir/pr26112.o.bz2
# We need to strip the ".bz2", but can leave the dirname.
set t $subdir/[file tail $test]
set testname [file rootname $t]
verbose $testname
set tempfile tmpdir/pr26112.o
if {[catch "system \"bzip2 -dc $test > $tempfile\""] != 0} {
untested "bzip2 -dc ($testname)"
} else {
readelf_test {--debug-dump=macro} $tempfile pr26112.r {}
}
}