2022-01-02 06:30:17 +08:00
# Copyright (C) 1994-2022 Free Software Foundation, Inc.
1999-05-03 15:29:11 +08:00
# 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
2007-07-06 00:54:46 +08:00
# the Free Software Foundation; either version 3 of the License, or
1999-05-03 15:29:11 +08:00
# (at your option) any later version.
2015-10-15 19:07:13 +08:00
#
1999-05-03 15:29:11 +08:00
# 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.
2015-10-15 19:07:13 +08:00
#
1999-05-03 15:29:11 +08:00
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
2005-05-08 22:17:41 +08:00
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
1999-05-03 15:29:11 +08:00
# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@prep.ai.mit.edu
# Written by Ian Lance Taylor <ian@cygnus.com>
if ![is_remote host] {
if {[which $OBJCOPY] == 0} then {
perror "$OBJCOPY does not exist"
return
}
}
send_user "Version [binutil_version $OBJCOPY]"
if ![is_remote host] {
2004-05-12 11:28:46 +08:00
set tempfile tmpdir/bintest.o
set copyfile tmpdir/copy
1999-05-03 15:29:11 +08:00
} else {
set tempfile [remote_download host tmpdir/bintest.o]
set copyfile copy
}
# Test that objcopy does not modify a file when copying it.
2020-03-27 18:54:26 +08:00
# "object" or "executable" values for type are supported.
1999-05-03 15:29:11 +08:00
2020-03-27 18:54:26 +08:00
proc objcopy_test {testname srcfile type asflags ldflags} {
2005-10-20 04:49:03 +08:00
global OBJCOPY
global OBJCOPYFLAGS
global srcdir
global subdir
global tempfile
global copyfile
2020-03-27 18:54:26 +08:00
set t_tempfile $tempfile
set t_copyfile ${copyfile}.o
1999-05-03 15:29:11 +08:00
2020-03-27 18:54:26 +08:00
if { $type != "object" && $type != "executable" } {
error "objcopy_test accepts only \"object\" or \"executable\" values for type"
}
if {![binutils_assemble_flags $srcdir/$subdir/${srcfile} $t_tempfile "$asflags"]} then {
2021-02-12 14:35:12 +08:00
unsupported "objcopy $type ($testname)"
2020-03-27 18:54:26 +08:00
remote_file host delete $t_tempfile
2005-10-20 04:49:03 +08:00
return
1999-05-03 15:29:11 +08:00
}
2020-03-28 07:58:03 +08:00
set xflags ""
2020-03-27 18:54:26 +08:00
if { $type == "executable" } {
global LD
# Check that LD exists
if {[which $LD] == 0} then {
untested "objcopy $type ($testname)"
return
}
2020-03-28 07:58:03 +08:00
2020-03-27 18:54:26 +08:00
# Use tempfile and copyfile without the .o extension for executable files
set t_tempfile [string range $tempfile 0 end-2]
set t_copyfile $copyfile
set got [binutils_run $LD "$tempfile -o $t_tempfile $ldflags"]
if { ![string equal "" $got] } then {
2021-02-12 14:35:12 +08:00
unsupported "objcopy $type ($testname)"
2020-03-27 18:54:26 +08:00
return
}
2020-03-30 23:30:02 +08:00
set xflags "--preserve-dates"
2021-04-14 23:06:42 +08:00
sleep 1
2020-03-27 18:54:26 +08:00
}
2020-03-28 07:58:03 +08:00
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $xflags $t_tempfile $t_copyfile"]
2005-10-20 04:49:03 +08:00
2015-10-15 19:07:13 +08:00
if ![string equal "" $got] then {
2020-10-22 19:48:11 +08:00
send_log "$got\n"
2020-03-27 18:54:26 +08:00
fail "objcopy $type ($testname)"
1999-05-03 15:29:11 +08:00
} else {
2020-03-27 18:54:26 +08:00
send_log "cmp $t_tempfile $t_copyfile\n"
verbose "cmp $t_tempfile $t_copyfile"
2005-10-20 04:49:03 +08:00
if [is_remote host] {
2020-03-27 18:54:26 +08:00
set src1 tmpdir/bintest
set src2 tmpdir/copy
remote_upload host $t_tempfile $src1
remote_upload host $t_copyfile $src2
2005-10-20 04:49:03 +08:00
} else {
2020-03-27 18:54:26 +08:00
set src1 $t_tempfile
set src2 $t_copyfile
2005-10-20 04:49:03 +08:00
}
set status [remote_exec build cmp "${src1} ${src2}"]
set exec_output [lindex $status 1]
set exec_output [prune_warnings $exec_output]
2015-10-15 19:07:13 +08:00
if [string equal "" $exec_output] then {
2020-03-27 18:54:26 +08:00
pass "objcopy $type ($testname)"
2021-04-14 23:06:42 +08:00
if { $type == "executable" } {
set dir [file dirname $t_copyfile]
set f2 [file tail $t_copyfile]
set status [remote_exec host find "$dir -name $f2 -newer $t_tempfile -print"]
set exec_output [lindex $status 1]
if [string equal "" $exec_output] then {
pass "objcopy $type ($testname) timestamp"
} else {
fail "objcopy $type ($testname) timestamp"
}
}
2005-10-20 04:49:03 +08:00
} else {
send_log "$exec_output\n"
verbose "$exec_output" 1
1999-05-03 15:29:11 +08:00
2005-10-20 04:49:03 +08:00
# On OSF/1, this succeeds with gas and fails with /bin/as.
setup_xfail "alpha*-*-osf*"
1999-05-03 15:29:11 +08:00
2020-03-27 18:54:26 +08:00
fail "objcopy $type ($testname)"
2005-10-20 04:49:03 +08:00
}
1999-05-03 15:29:11 +08:00
}
}
2020-03-28 07:58:03 +08:00
setup_xfail "hppa*-*-*"
setup_xfail "sh-*-coff*"
setup_xfail "tic54x-*-*"
clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"
2020-03-28 12:01:02 +08:00
clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "hppa*-*-*elf*"
2020-03-27 18:54:26 +08:00
objcopy_test "simple copy" bintest.s object "" ""
2005-10-20 04:49:03 +08:00
2019-05-14 17:40:04 +08:00
# Test verilog data width
proc objcopy_test_verilog {testname} {
global OBJCOPY
global OBJCOPYFLAGS
global srcdir
global subdir
global copyfile
set binfile tmpdir/verilogtest.o
set verilog tmpdir/verilog
set got [binutils_assemble $srcdir/$subdir/verilogtest.s $binfile]
if {![binutils_assemble $srcdir/$subdir/verilogtest.s $binfile]} then {
2021-02-12 14:35:12 +08:00
unsupported "objcopy ($testname)"
2019-05-14 17:40:04 +08:00
return
}
set got [binutils_run $OBJCOPY "-O verilog $binfile $verilog"]
if ![string equal "" $got] then {
fail "objcopy ($testname)"
}
set got [binutils_run $OBJCOPY "-O verilog --verilog-data-width 0 $binfile $verilog-0.hex"]
if ![regexp "verilog data width must be at least 1 byte" $got] then {
fail "objcopy ($testname 0) {$got}"
} else {
pass "objcopy ($testname 0)"
}
foreach width {1 2 4 8} {
set got [binutils_run $OBJCOPY "-O verilog --verilog-data-width $width $binfile $verilog-$width.hex"]
if ![string equal "" $got] then {
fail "objcopy ($testname $width)"
}
send_log "regexp_diff $verilog-$width.hex $srcdir/$subdir/verilog-$width.hex\n"
if {! [regexp_diff "$verilog-$width.hex" "$srcdir/$subdir/verilog-$width.hex"]} {
pass "objcopy ($testname $width)"
} else {
fail "objcopy ($testname $width)"
}
}
}
objcopy_test_verilog "verilog data width"
2016-06-22 21:42:26 +08:00
if { [file exists $tempfile] } {
# Test reversing bytes in a section.
2007-04-23 18:59:07 +08:00
2016-06-22 21:42:26 +08:00
set reversed ${tempfile}-reversed
set sect_names [get_standard_section_names]
if { $sect_names != "" } {
2020-08-27 23:25:03 +08:00
if { [istarget hppa*-*-hpux*] } {
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j \$PRIVATE\$ -j [lindex $sect_names 1] --reverse-bytes=4 $tempfile $reversed"]
} else {
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j [lindex $sect_names 1] --reverse-bytes=4 $tempfile $reversed"]
}
2016-06-22 21:42:26 +08:00
} else {
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j .data --reverse-bytes=4 $tempfile $reversed"]
2007-04-23 18:59:07 +08:00
}
2016-06-22 21:42:26 +08:00
if ![string equal "" $got] then {
fail "objcopy --reverse-bytes"
} else {
if [is_remote host] {
remote_upload host ${reversed} tmpdir/copy-reversed.o
set reversed tmpdir/copy-reversed.o
}
2007-04-23 18:59:07 +08:00
2016-06-22 21:42:26 +08:00
set origdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $tempfile"]
set revdata [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s -j .data $reversed"]
2007-04-23 18:59:07 +08:00
2016-06-22 21:42:26 +08:00
set want "^ \[0-9\]+ (\[0-9\]+)"
set found_orig [regexp -lineanchor $want $origdata -> origdata]
set found_rev [regexp -lineanchor $want $revdata -> revdata]
2011-01-01 09:56:59 +08:00
2016-06-22 21:42:26 +08:00
if {$found_orig == 0 || $found_rev == 0} then {
fail "objcopy --reverse-bytes"
} else {
scan $origdata "%2x%2x%2x%2x" b1 b2 b3 b4
scan $revdata "%2x%2x%2x%2x" c4 c3 c2 c1
if {$b1 == $c1 && $b2 == $c2 && $b3 == $c3 && $b4 == $c4} then {
pass "objcopy --reverse-bytes"
} else {
fail "objcopy --reverse-bytes"
}
}
2007-04-23 18:59:07 +08:00
}
}
2010-09-10 20:11:28 +08:00
# Test interleaved copy of multiple byte width
set sequence_file sequence_file
set file [open ${sequence_file} w]
puts ${file} "12345678"
close ${file}
if [is_remote host] {
remote_upload host ${sequence_file} tmpdir/sequence_file
set sequence_file tmpdir/sequence_file
}
set got [binutils_run $OBJCOPY "-I binary -i 4 -b 0 --interleave-width 2 ${sequence_file} ${copyfile}"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $got] then {
2010-09-10 20:11:28 +08:00
fail "objcopy -i --interleave-width"
} else {
if [is_remote host] {
remote_upload host ${copyfile} tmpdir/interleave_output
set interleave_output tmpdir/interleave_output
} else {
set interleave_output ${copyfile}
}
set file [open ${interleave_output} r]
gets $file line
send_log "$line\n"
verbose $line
2015-10-15 19:07:13 +08:00
if ![string equal "1256" $line] then {
2010-09-10 20:11:28 +08:00
fail "objcopy -i --interleave-width"
}
pass "objcopy -i --interleave-width"
close $file
}
1999-05-03 15:29:11 +08:00
# Test generating S records.
2016-06-22 21:42:26 +08:00
if { [file exists $tempfile] } {
# We make the srec filename 8.3 compatible. Note that the header string
# matched against depends on the name of the file. Ugh.
1999-05-03 15:29:11 +08:00
if [is_remote host] {
2016-06-22 21:42:26 +08:00
set srecfile copy.sre
set header_string S00B0000636F70792E737265C1
} else {
set srecfile ${copyfile}.srec
set header_string S0130000746D706469722F636F70792E7372656397
1999-05-03 15:29:11 +08:00
}
2016-06-22 21:42:26 +08:00
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"]
if ![string equal "" $got] then {
1999-05-03 15:29:11 +08:00
fail "objcopy -O srec"
} else {
2016-06-22 21:42:26 +08:00
if [is_remote host] {
remote_upload host ${srecfile} tmpdir/copy.srec
set srecfile tmpdir/copy.srec
1999-05-03 15:29:11 +08:00
}
2016-06-22 21:42:26 +08:00
set file [open ${srecfile} r]
# The first S record is fixed by the file name we are using.
gets $file line
1999-05-03 15:29:11 +08:00
send_log "$line\n"
verbose $line
2016-06-22 21:42:26 +08:00
if ![regexp "$header_string.*" $line] {
send_log "bad header\n"
1999-05-03 15:29:11 +08:00
fail "objcopy -O srec"
} else {
2016-06-22 21:42:26 +08:00
while {[gets $file line] != -1 \
&& [regexp "^S\[123\]\[0-9a-fA-F\]+\[\r\n\]*$" $line]} {
1999-05-03 15:29:11 +08:00
send_log "$line\n"
verbose $line
2016-06-22 21:42:26 +08:00
set line "**EOF**"
}
send_log "$line\n"
verbose $line
if ![regexp "^S\[789\]\[0-9a-fA-F\]+\[\r\n\]*$" $line] then {
send_log "bad trailer\n"
1999-05-03 15:29:11 +08:00
fail "objcopy -O srec"
} else {
2016-06-22 21:42:26 +08:00
if {[gets $file line] != -1} then {
send_log "garbage at end\n"
send_log "$line\n"
verbose $line
1999-05-03 15:29:11 +08:00
fail "objcopy -O srec"
} else {
2016-06-22 21:42:26 +08:00
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${srecfile}"]
if ![regexp "file format srec" $got] then {
send_log "objdump failed\n"
fail "objcopy -O srec"
} else {
pass "objcopy -O srec"
}
1999-05-03 15:29:11 +08:00
}
}
}
2016-06-22 21:42:26 +08:00
close $file
}
1999-05-03 15:29:11 +08:00
}
# Test setting and adjusting the start address. We only test this
# while generating S records, because we may not be able to set the
# start address for other object file formats, and the S record case
# is the only useful one anyhow.
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $tempfile"]
if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
perror "objdump can not recognize bintest.o"
set origstart ""
} else {
2004-02-20 23:21:54 +08:00
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $got] then {
1999-05-03 15:29:11 +08:00
fail "objcopy --set-start"
} else {
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
fail "objcopy --set-start"
} else {
if {$srecstart != 0x7654} then {
send_log "$srecstart != 0x7654\n"
fail "objcopy --set-start"
} else {
pass "objcopy --set-start"
}
}
}
2004-02-20 23:21:54 +08:00
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $got] then {
1999-05-03 15:29:11 +08:00
fail "objcopy --adjust-start"
} else {
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"]
if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
fail "objcopy --adjust-start"
} else {
if {$srecstart != $origstart + 0x123} then {
send_log "$srecstart != $origstart + 0x123\n"
fail "objcopy --adjust-start"
} else {
pass "objcopy --adjust-start"
}
}
}
}
# Test adjusting the overall VMA, and adjusting the VMA of a
# particular section. We again only test this when generating S
# records.
set low ""
set lowname ""
set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $tempfile"]
set headers_regexp "\[ 0-9\]+(\[^ \]+)\[ \]*(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)\[ \]+\[0-9a-fA-F\]+\[ \]+2\[*\]\[*\]\[0-9\]+(.*)"
set got $headers
while {[regexp $headers_regexp $got all name size vma rest]} {
set vma 0x$vma
set size 0x$size
if {$size != 0} {
if {$low == "" || $vma < $low} {
set low $vma
set lowname $name
}
}
set got $rest
}
if {$low == "" || $origstart == ""} then {
perror "objdump can not recognize bintest.o"
} else {
2004-02-20 23:21:54 +08:00
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $got] then {
1999-05-03 15:29:11 +08:00
fail "objcopy --adjust-vma"
} else {
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"]
set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
if ![regexp $want $got all start vma] then {
fail "objcopy --adjust-vma"
} else {
set vma 0x$vma
if {$vma != $low + 0x123} then {
send_log "$vma != $low + 0x123\n"
fail "objcopy --adjust-vma"
} else {
if {$start != $origstart + 0x123} then {
send_log "$start != $origstart + 0x123\n"
fail "objcopy --adjust-vma"
} else {
pass "objcopy --adjust-vma"
}
}
}
}
set arg ""
set got $headers
while {[regexp $headers_regexp $got all name size vma rest]} {
set vma 0x$vma
if {$vma == $low} then {
set arg "$arg --adjust-section-vma $name+4"
}
set got $rest
}
2004-02-20 23:21:54 +08:00
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $got] then {
1999-05-03 15:29:11 +08:00
fail "objcopy --adjust-section-vma +"
} else {
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
if ![regexp $want $got all vma] then {
fail "objcopy --adjust-section-vma +"
} else {
set vma 0x$vma
if {$vma != $low + 4} then {
send_log "$vma != $low + 4\n"
fail "objcopy --adjust-section-vma +"
} else {
pass "objcopy --adjust-section-vma +"
}
}
}
regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
2004-02-20 23:21:54 +08:00
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $got] then {
1999-05-03 15:29:11 +08:00
fail "objcopy --adjust-section-vma ="
} else {
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"]
set want "file format srec.*sec1\[ \]+\[0-9a-fA-F\]+\[ \]+(\[0-9a-fA-F\]+)"
if ![regexp $want $got all vma] then {
fail "objcopy --adjust-section-vma ="
} else {
set vma 0x$vma
if {$vma != $low + 4} then {
send_log "$vma != $low + 4\n"
fail "objcopy --adjust-section-vma ="
} else {
pass "objcopy --adjust-section-vma ="
}
}
}
}
# Test stripping an object.
proc strip_test { } {
2001-11-30 01:34:07 +08:00
global AR
1999-05-03 15:29:11 +08:00
global CC
global STRIP
global STRIPFLAGS
global NM
global NMFLAGS
global srcdir
global subdir
2011-07-01 05:41:05 +08:00
global READELF
1999-05-03 15:29:11 +08:00
set test "strip"
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
untested $test
return
}
2011-07-01 05:41:05 +08:00
set osabi_fail "false"
if [is_elf_format] {
verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.in"
set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.in"]
if { [lindex $exec_output 0] != 0 } then {
2021-02-12 14:35:12 +08:00
fail "$test preserving OS/ABI"
2011-07-01 05:41:05 +08:00
set osabi_fail "true"
} else {
verbose -log "grep OS/ABI tmpdir/osabi.in"
catch "exec grep OS/ABI tmpdir/osabi.in" osabi_in
}
}
1999-05-03 15:29:11 +08:00
if [is_remote host] {
2001-11-30 01:34:07 +08:00
set archive libstrip.a
2004-05-12 11:28:46 +08:00
set objfile [remote_download host tmpdir/testprog.o]
2001-11-30 01:34:07 +08:00
remote_file host delete $archive
} else {
set archive tmpdir/libstrip.a
set objfile tmpdir/testprog.o
}
remote_file build delete tmpdir/libstrip.a
set exec_output [binutils_run $AR "rc $archive ${objfile}"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
2001-11-30 01:34:07 +08:00
fail $test
2015-10-15 19:07:13 +08:00
unresolved "$test preserving OS/ABI"
2001-11-30 01:34:07 +08:00
return
}
2006-04-25 22:06:10 +08:00
set exec_output [binutils_run $STRIP "-g $archive"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
2006-04-25 22:06:10 +08:00
fail $test
2015-10-15 19:07:13 +08:00
unresolved "$test preserving OS/ABI"
2006-04-25 22:06:10 +08:00
return
}
2001-11-30 01:34:07 +08:00
set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
2001-11-30 01:34:07 +08:00
fail $test
2015-10-15 19:07:13 +08:00
unresolved "$test preserving OS/ABI"
2001-11-30 01:34:07 +08:00
return
}
2011-07-01 05:41:05 +08:00
if { $osabi_fail != "true" && [is_elf_format] } {
verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.out"
set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.out"]
if { [lindex $exec_output 0] != 0 } then {
2021-02-12 14:35:12 +08:00
fail "$test preserving OS/ABI"
2011-07-01 05:41:05 +08:00
} else {
verbose -log "grep OS/ABI tmpdir/osabi.out"
catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out
if { "$osabi_in" == "$osabi_out" } {
pass "$test preserving OS/ABI"
} else {
fail "$test preserving OS/ABI"
}
}
}
2001-11-30 01:34:07 +08:00
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
untested $test
return
}
if [is_remote host] {
2004-05-12 11:28:46 +08:00
set objfile [remote_download host tmpdir/testprog.o]
1999-05-03 15:29:11 +08:00
} else {
set objfile tmpdir/testprog.o
}
set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
1999-05-03 15:29:11 +08:00
fail $test
return
}
set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2002-08-27 07:15:48 +08:00
if ![string match "*: no symbols*" $exec_output] {
1999-05-03 15:29:11 +08:00
fail $test
return
}
pass $test
}
strip_test
# Test stripping an object file with saving a symbol
proc strip_test_with_saving_a_symbol { } {
global CC
global STRIP
global STRIPFLAGS
global NM
global NMFLAGS
global srcdir
global subdir
set test "strip with saving a symbol"
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
untested $test
return
}
if [is_remote host] {
2004-05-12 11:28:46 +08:00
set objfile [remote_download host tmpdir/testprog.o]
1999-05-03 15:29:11 +08:00
} else {
set objfile tmpdir/testprog.o
}
set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
1999-05-03 15:29:11 +08:00
fail $test
return
}
set exec_output [binutils_run $NM "$NMFLAGS $objfile"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2002-05-29 13:00:33 +08:00
if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
1999-05-03 15:29:11 +08:00
&& ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} {
fail $test
return
}
pass $test
}
strip_test_with_saving_a_symbol
# Build a final executable.
2021-08-19 11:45:06 +08:00
set exe [exeext]
set test_prog "testprog${exe}"
2003-06-19 15:45:50 +08:00
1999-05-03 15:29:11 +08:00
proc copy_setup { } {
global srcdir
global subdir
2001-02-12 08:21:59 +08:00
global gcc_gas_flag
2003-06-19 15:45:50 +08:00
global test_prog
2008-07-08 16:15:09 +08:00
global host_triplet
2015-10-15 19:07:13 +08:00
2004-05-12 11:28:46 +08:00
set res [build_wrapper testglue.o]
set flags { debug }
2015-10-15 19:07:13 +08:00
2018-04-19 04:55:29 +08:00
if { [istarget *-*-uclinux*] && ![istarget tic6x-*-*] && ![istarget arm*-*-uclinuxfdpiceabi] } {
2007-02-27 20:19:16 +08:00
return 1
}
2015-10-15 19:07:13 +08:00
1999-05-03 15:29:11 +08:00
if { $res != "" } {
2004-05-12 11:28:46 +08:00
lappend flags "additional_flags=[lindex $res 1]"
set add_libs "testglue.o"
1999-05-03 15:29:11 +08:00
} else {
2004-05-12 11:28:46 +08:00
set add_libs ""
1999-05-03 15:29:11 +08:00
}
2010-11-08 14:43:40 +08:00
if { [istarget *-*-linux*]
|| [istarget *-*-gnu*] } {
2001-02-12 08:21:59 +08:00
foreach i $gcc_gas_flag {
set flags "additional_flags=$i $flags"
}
}
2003-06-19 15:45:50 +08:00
if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } {
1999-05-03 15:29:11 +08:00
return 2
}
2004-05-12 11:28:46 +08:00
set result [remote_load target tmpdir/$test_prog]
set status [lindex $result 0]
1999-05-03 15:29:11 +08:00
if { $status != "pass" } {
2008-07-08 16:15:09 +08:00
send_log "cannot run executable, status = ${status} on ${host_triplet}\n"
2015-10-15 19:07:13 +08:00
return 3
1999-05-03 15:29:11 +08:00
}
return 0
}
# Test copying an executable.
proc copy_executable { prog flags test1 test2 } {
2003-06-19 15:45:50 +08:00
global test_prog
1999-05-03 15:29:11 +08:00
if [is_remote host] {
2004-05-12 11:28:46 +08:00
set testfile [remote_download host tmpdir/$test_prog]
1999-05-03 15:29:11 +08:00
set testcopy copyprog
} else {
2003-06-19 15:45:50 +08:00
set testfile tmpdir/$test_prog
1999-05-03 15:29:11 +08:00
set testcopy tmpdir/copyprog
}
2004-05-12 11:28:46 +08:00
remote_file host delete $testcopy
1999-05-03 15:29:11 +08:00
set exec_output [binutils_run $prog "$flags $testfile $testcopy"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
1999-05-03 15:29:11 +08:00
fail $test1
2015-10-15 19:07:13 +08:00
if [string equal "" $test2] {
2007-05-02 18:38:00 +08:00
return
}
1999-05-03 15:29:11 +08:00
fail $test2
return
}
if [is_remote host] {
remote_upload host $testcopy tmpdir/copyprog
}
2003-06-19 15:45:50 +08:00
set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"]
2004-05-12 11:28:46 +08:00
set exec_output [lindex $status 1]
1999-05-03 15:29:11 +08:00
2015-10-15 19:07:13 +08:00
if [string equal "" $exec_output] then {
1999-05-03 15:29:11 +08:00
pass $test1
} else {
send_log "$exec_output\n"
verbose "$exec_output"
# This will fail for many reasons. For example, it will most
# likely fail if a non-GNU linker is used. Therefore, we do
# not insist that it pass. If you are using an assembler and
# linker based on the same BFD as objcopy, it is worth
# investigating to see why this failure occurs. If we are
# cross compiling, we assume that a GNU linker is being used,
# and expect it to succeed.
if {[isnative]} then {
setup_xfail "*-*-*"
}
2016-06-23 20:41:57 +08:00
# This also fails for some mips targets. See elf32-mips.c
1999-05-03 15:29:11 +08:00
# mips_elf_sym_is_global.
2016-06-23 20:41:57 +08:00
if { [is_bad_symtab] } then {
setup_xfail "*-*-*"
}
1999-05-03 15:29:11 +08:00
1999-11-02 00:48:05 +08:00
setup_xfail "arm*-*-pe"
2010-03-31 01:45:19 +08:00
setup_xfail "*-*-mingw*"
2009-06-26 09:26:28 +08:00
setup_xfail "*-*-cygwin*"
2015-10-15 19:07:13 +08:00
1999-05-03 15:29:11 +08:00
fail $test1
}
2015-10-15 19:07:13 +08:00
if [string equal "" $test2] {
2007-05-02 18:38:00 +08:00
return
}
1999-05-03 15:29:11 +08:00
set output [remote_load target tmpdir/copyprog]
2004-05-12 11:28:46 +08:00
set status [lindex $output 0]
1999-05-03 15:29:11 +08:00
if { $status != "pass" } {
fail $test2
} else {
pass $test2
}
}
# Test stripping an executable
2015-10-15 19:07:13 +08:00
proc strip_executable { prog flags test1 test2 } {
1999-05-03 15:29:11 +08:00
global NM
global NMFLAGS
2011-07-01 05:41:05 +08:00
global READELF
1999-05-03 15:29:11 +08:00
2009-04-02 21:47:44 +08:00
remote_file build delete tmpdir/striprog
1999-05-03 15:29:11 +08:00
remote_download build tmpdir/copyprog tmpdir/striprog
if [is_remote host] {
2004-05-12 11:28:46 +08:00
set copyfile [remote_download host tmpdir/striprog]
1999-05-03 15:29:11 +08:00
} else {
set copyfile tmpdir/striprog
}
2011-07-01 05:41:05 +08:00
set osabi_fail "false"
if [is_elf_format] {
verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.in"
set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.in"]
if { [lindex $exec_output 0] != 0 } then {
2021-02-12 14:35:12 +08:00
fail "$test1 preserving OS/ABI"
2011-07-01 05:41:05 +08:00
set osabi_fail "true"
} else {
verbose -log "grep OS/ABI tmpdir/osabi.in"
catch "exec grep OS/ABI tmpdir/osabi.in" osabi_in
}
}
1999-05-03 15:29:11 +08:00
set exec_output [binutils_run $prog "$flags ${copyfile}"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
fail $test1
if [string equal "" $test2] {
return
}
fail $test2
1999-05-03 15:29:11 +08:00
return
}
if [is_remote host] {
2004-05-12 11:28:46 +08:00
remote_upload host ${copyfile} tmpdir/striprog
1999-05-03 15:29:11 +08:00
}
2011-07-01 05:41:05 +08:00
if { $osabi_fail != "true" && [is_elf_format] } {
verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.out"
set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.out"]
if { [lindex $exec_output 0] != 0 } then {
2021-02-12 14:35:12 +08:00
fail "$test1 preserving OS/ABI"
2011-07-01 05:41:05 +08:00
} else {
verbose -log "grep OS/ABI tmpdir/osabi.out"
catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out
if { "$osabi_in" == "$osabi_out" } {
2015-10-15 19:07:13 +08:00
pass "$test1 preserving OS/ABI"
2011-07-01 05:41:05 +08:00
} else {
2015-10-15 19:07:13 +08:00
fail "$test1 preserving OS/ABI"
2011-07-01 05:41:05 +08:00
}
}
}
1999-05-03 15:29:11 +08:00
set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
2002-08-27 07:15:48 +08:00
if ![string match "*: no symbols*" $exec_output] {
2015-10-15 19:07:13 +08:00
fail $test1
1999-05-03 15:29:11 +08:00
return
}
2015-10-15 19:07:13 +08:00
if [string equal "" $test2] {
return
}
set result [remote_load target tmpdir/striprog]
set status [lindex $result 0]
if { $status != "pass" } {
fail $test2
return
}
pass $test2
1999-05-03 15:29:11 +08:00
}
# Test stripping an executable with saving a symbol
2015-10-15 19:07:13 +08:00
proc strip_executable_with_saving_a_symbol { prog flags test1 test2 } {
1999-05-03 15:29:11 +08:00
global NM
global NMFLAGS
2009-04-02 21:47:44 +08:00
remote_file build delete tmpdir/striprog
1999-05-03 15:29:11 +08:00
remote_download build tmpdir/copyprog tmpdir/striprog
if [is_remote host] {
2004-05-12 11:28:46 +08:00
set copyfile [remote_download host tmpdir/striprog]
1999-05-03 15:29:11 +08:00
} else {
set copyfile tmpdir/striprog
}
set exec_output [binutils_run $prog "$flags ${copyfile}"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
fail $test1
if [string equal "" $test2] {
return
}
fail $test2
1999-05-03 15:29:11 +08:00
return
}
set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"]
2002-02-18 17:13:48 +08:00
if { [istarget mmix-knuth-mmixware] } {
# Whenever there's a symbol in the mmo format, there's the symbol
# Main, so remove it manually from the expected output for sake of
# this test.
# Using "" not {} to get the \n and \r translated.
regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output
}
2004-03-30 17:54:15 +08:00
if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \
&& ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} {
2015-10-15 19:07:13 +08:00
fail $test1
1999-05-03 15:29:11 +08:00
return
}
2015-10-15 19:07:13 +08:00
if [string equal "" $test2] {
return
}
if [is_remote host] {
remote_upload host ${copyfile} tmpdir/striprog
}
set result [remote_load target tmpdir/striprog]
set status [lindex $result 0]
if { $status != "pass" } {
fail $test2
return
}
pass $test2
1999-05-03 15:29:11 +08:00
}
2008-05-29 15:07:21 +08:00
# Test keeping only debug symbols of an executable
proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } {
2009-04-02 21:47:44 +08:00
remote_file build delete tmpdir/striprog
2008-05-29 15:07:21 +08:00
remote_download build tmpdir/copyprog tmpdir/striprog
if [is_remote host] {
set copyfile [remote_download host tmpdir/striprog]
} else {
set copyfile tmpdir/striprog
}
set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
2008-05-29 15:07:21 +08:00
fail $test1
return
}
pass $test1
set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
2008-05-29 15:07:21 +08:00
fail $test2
return
}
pass $test2
}
2015-08-05 23:16:39 +08:00
# Tests that in a debug only copy of a file the sections
2017-07-18 23:58:14 +08:00
# headers whose types have been changed to NOBITS still
2015-08-05 23:16:39 +08:00
# retain their sh_link fields.
proc keep_debug_symbols_and_check_links { prog flags test } {
global READELF
remote_file build delete tmpdir/striprog
remote_download build tmpdir/copyprog tmpdir/striprog
if [is_remote host] {
set copyfile [remote_download host tmpdir/striprog]
} else {
set copyfile tmpdir/striprog
}
set exec_output [binutils_run $prog "$flags ${copyfile}"]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] {
2015-08-05 23:16:39 +08:00
fail $test
return
}
set got [binutils_run $READELF "-S --wide ${copyfile}"]
set fails 0
# Regexp to match a section with NOBITS type and extract its name and sh_link fields
while {[regexp \
{[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ ]+NOBITS[ ]+[0-9a-fA-F]+ [0-9a-fA-F]+ [0-9a-fA-F]+ [0-9]+[ A]+([0-9]+)(.*)} \
$got all name link rest]} {
set sh_link 0x$link
if {$sh_link == 0} {
# Only some NOBITS sections should have a non-zero sh_link field.
# Look for them by name.
verbose "NOBITS section .$name has a 0 sh_link field\n"
switch $name {
"rela.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
"rel.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
"hash" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
"gnu_version" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
"dynsym" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
"gnu.version_r" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
"dynamic" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
"symtab" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" }
}
}
set got $rest
}
if {$fails == 0} {
pass $test
} else {
fail $test
}
}
2022-02-03 14:33:22 +08:00
# For ELF relocatables, test that --only-keep-debug
# marks non-debug output sections as NOBITS.
proc keep_debug_symbols_for_elf_relocatable { prog flags test } {
global srcdir
global subdir
global READELF
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
untested $test
return
}
if [is_remote host] {
set relocatable [remote_download host tmpdir/testprog.o]
} else {
set relocatable tmpdir/testprog.o
}
set non_debug_sections {}
set got [binutils_run $READELF "-S --wide ${relocatable}"]
while { [regexp \
{[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+([A-Z]*)[ \t]+[0-9]+(.*)} \
$got all name type flag rest] } {
if { $type != "NOTE" && [regexp {[AG]} $flag] } {
lappend non_debug_sections $name
}
set got $rest
}
set exec_output [binutils_run $prog "$flags ${relocatable}"]
if ![string equal "" $exec_output] {
fail $test
return
}
set fails 0
set got [binutils_run $READELF "-S --wide ${relocatable}"]
while { [regexp \
{[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+[A-Z]*[ \t]+[0-9]+(.*)} \
$got all name type rest] } {
if { [lsearch -exact $non_debug_sections $name] >= 0 && $type != "NOBITS" } {
set fails 1
send_log "Expected SHT_NOBITS type for .$name\n"
}
set got $rest
}
if { $fails == 1 } {
fail $test
return
}
pass $test
}
2015-08-05 23:16:39 +08:00
1999-05-03 15:29:11 +08:00
set test1 "simple objcopy of executable"
2015-10-15 19:07:13 +08:00
set test1r "run objcopy of executable"
set test2 "strip executable"
set test2r "run stripped executable"
set test3 "strip executable with saving a symbol"
set test3r "run stripped executable with saving a symbol"
set test4 "keep only debug data"
set test5 "simple objcopy of debug data"
2015-08-05 23:16:39 +08:00
if [is_elf_format] {
2015-10-15 19:07:13 +08:00
set test6 "NOBITS sections retain sh_link field"
2022-02-03 14:33:22 +08:00
set test7 "--only-keep-debug for ELF relocatables"
2015-08-05 23:16:39 +08:00
}
1999-05-03 15:29:11 +08:00
switch [copy_setup] {
"1" {
# do nothing
}
"2" {
untested $test1
2015-10-15 19:07:13 +08:00
untested $test1r
1999-05-03 15:29:11 +08:00
untested $test2
2015-10-15 19:07:13 +08:00
untested $test2r
1999-05-03 15:29:11 +08:00
untested $test3
2015-10-15 19:07:13 +08:00
untested $test3r
1999-05-03 15:29:11 +08:00
untested $test4
2008-05-29 15:07:21 +08:00
untested $test5
2015-08-05 23:16:39 +08:00
if [is_elf_format] {
2015-10-15 19:07:13 +08:00
untested $test6
2015-08-05 23:16:39 +08:00
}
1999-05-03 15:29:11 +08:00
}
"3" {
2007-05-02 18:38:00 +08:00
copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" ""
2015-10-15 19:07:13 +08:00
unsupported $test1r
strip_executable "$STRIP" "$STRIPFLAGS" "$test2" ""
unsupported $test2r
strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" ""
unsupported $test3r
keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \
"$OBJCOPY" "$OBJCOPYFLAGS" "$test5"
2015-08-05 23:16:39 +08:00
if [is_elf_format] {
2015-10-15 19:07:13 +08:00
keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6"
2022-02-03 14:33:22 +08:00
keep_debug_symbols_for_elf_relocatable "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7"
2015-08-05 23:16:39 +08:00
}
1999-05-03 15:29:11 +08:00
}
"0" {
2015-10-15 19:07:13 +08:00
copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test1r"
strip_executable "$STRIP" "$STRIPFLAGS" "$test2" "$test2r"
strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" "$test3r"
keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \
"$OBJCOPY" "$OBJCOPYFLAGS" "$test5"
2015-08-05 23:16:39 +08:00
if [is_elf_format] {
2015-10-15 19:07:13 +08:00
keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6"
2022-02-03 14:33:22 +08:00
keep_debug_symbols_for_elf_relocatable "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7"
2015-08-05 23:16:39 +08:00
}
1999-05-03 15:29:11 +08:00
}
}
2005-10-20 01:39:43 +08:00
2005-10-21 01:06:41 +08:00
proc objcopy_test_readelf {testname srcfile} {
global OBJCOPY
global OBJCOPYFLAGS
global READELF
global srcdir
global subdir
if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/bintest.o]} then {
2021-02-12 14:35:12 +08:00
unsupported "objcopy ($testname)"
2005-10-21 01:06:41 +08:00
return
}
verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"
2007-08-28 21:21:58 +08:00
set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
if { [lindex $exec_output 0] != 0
2015-10-15 19:07:13 +08:00
|| ![string equal "" [lindex $exec_output 1]] } then {
2005-10-21 01:06:41 +08:00
fail "objcopy ($testname)"
2006-05-01 12:01:25 +08:00
return
2005-10-21 01:06:41 +08:00
}
verbose -log "$READELF -a tmpdir/bintest.o > tmpdir/bintest.o.out"
2007-08-28 21:21:58 +08:00
set exec_output [remote_exec host "$READELF -a tmpdir/bintest.o" "" "/dev/null" "tmpdir/bintest.o.out"]
if { [lindex $exec_output 0] != 0 } then {
2021-02-12 14:35:12 +08:00
fail "objcopy ($testname)"
2007-08-28 21:21:58 +08:00
return
}
set exec_output [prune_warnings [lindex $exec_output 1]]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] then {
2005-10-21 01:06:41 +08:00
unresolved "objcopy ($testname)"
return
}
verbose -log "$READELF -a tmpdir/copy.o > tmpdir/copy.o.out"
2007-08-28 21:21:58 +08:00
set exec_output [remote_exec host "$READELF -a tmpdir/copy.o" "" "/dev/null" "tmpdir/copy.o.out"]
if { [lindex $exec_output 0] != 0 } then {
2021-02-12 14:35:12 +08:00
fail "objcopy ($testname)"
2007-08-28 21:21:58 +08:00
return
}
set exec_output [prune_warnings [lindex $exec_output 1]]
2015-10-15 19:07:13 +08:00
if ![string equal "" $exec_output] then {
2005-10-21 01:06:41 +08:00
unresolved "objcopy ($testname)"
return
}
verbose -log "diff tmpdir/bintest.o.out tmpdir/copy.o.out"
catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output
set exec_output [prune_warnings $exec_output]
2015-10-15 19:07:13 +08:00
if [string equal "" $exec_output] then {
2005-10-21 01:06:41 +08:00
pass "objcopy ($testname)"
} else {
fail "objcopy ($testname)"
}
}
objcopy: Improve wildcard matching for symbols with '!' prefix.
When using options such as --localize-symbol, --globalize-symbol, etc,
along with the --wildcard option, prefixing a symbol name with '!'
should provide non-matching behaviour, as example the following example
is given in the manual:
--wildcard --weaken-symbol !foo --weaken-symbol fo*
which should weaken all symbols matching the pattern 'fo*', but not the
symbol 'foo'.
However, this currently does not work, the current logic will waken all
symbols matching the pattern 'fo*' AND all symbols that are not 'foo'.
The symbol 'foo' is covered by the first condition, and so is weakened,
while, other symbols, for example 'bar' will match the second condition,
and so be weakened.
This patch adjusts the logic so that a pattern prefixed with '!'
specifically DOES NOT apply the relevant change to any matching symbols,
instead of applying the change to all non-matching symbols. So this:
--weaken-symbol !foo
will ensure that the symbol 'foo' is not weakened, but says nothing
about symbols that are not 'foo'. As a result, a pattern prefixed with
'!' now only makes sense when used alongside a more wide ranging
wildcard pattern.
This change should make the wildcard matching feature more useful, with
no overall loss of functionality. The example given in the manual,
weaken all symbols matching 'fo*' except 'foo' can now be achieved, but
so too can more complex examples, such as weaken all symbols matching
'fo*' except 'foo', 'foa', and 'fob', like this:
--wildcard --weaken-symbol !foo \
--weaken-symbol !foa \
--weaken-symbol !fob \
--weaken-symbol fo*
Under the previous scheme, something as symbols as, weaken all symbols
except 'foo' could have been achieved with this:
--weaken-symbol !foo
however, this will no longer work. To achieve the same result under the
new scheme this is now required:
--weaken-symbol !foo --weaken-symbol *
binutils/ChangeLog:
* objcopy.c (is_specified_symbol_predicate): Don't stop at first
match. Non-match rules set found to FALSE.
binutils/testsuite/ChangeLog:
* binutils-all/objcopy.exp: Run new symbol tests.
(objcopy_test_symbol_manipulation): New function.
* binutils-all/symbols-1.d: New file.
* binutils-all/symbols-2.d: New file.
* binutils-all/symbols-3.d: New file.
* binutils-all/symbols-4.d: New file.
* binutils-all/symbols.s: New file.
2015-07-31 20:48:22 +08:00
proc objcopy_test_symbol_manipulation {} {
global srcdir
global subdir
set test_list [lsort [glob -nocomplain $srcdir/$subdir/symbols-*.d]]
foreach t $test_list {
# We need to strip the ".d", but can leave the dirname.
verbose [file rootname $t]
run_dump_test [file rootname $t]
}
}
Properly implement STT_COMMON
The BFD configure option, --enable-elf-stt-common, can't be to used to
verify STT_COMMON implementation with the normal binutils build. Instead,
this patch removes it from BFD. It adds --elf-stt-common=[no|yes] to ELF
assembler/objcopy and adds -z common/-z nocommon to ld.
A configure option, --enable-elf-stt-common, is added to gas to specify
whether ELF assembler should generate common symbols with the STT_COMMON
type by default.
Since BSF_KEEP_G is never used, it is renamed to BSF_ELF_COMMON for ELF
common symbols.
bfd/
PR ld/19645
* bfd.c (bfd): Change flags to 20 bits.
(BFD_CONVERT_ELF_COMMON): New.
(BFD_USE_ELF_STT_COMMON): Likewise.
(BFD_FLAGS_SAVED): Add BFD_CONVERT_ELF_COMMON and
BFD_USE_ELF_STT_COMMON.
(BFD_FLAGS_FOR_BFD_USE_MASK): Likewise.
* configure.ac: Remove --enable-elf-stt-common.
* elf.c (swap_out_syms): Choose STT_COMMON or STT_OBJECT for
common symbol depending on BFD_CONVERT_ELF_COMMON and
BFD_USE_ELF_STT_COMMON.
* elfcode.h (elf_slurp_symbol_table): Set BSF_ELF_COMMON for
STT_COMMON.
* elflink.c (bfd_elf_link_mark_dynamic_symbol): Also check
STT_COMMON.
(elf_link_convert_common_type): New function.
(elf_link_output_extsym): Choose STT_COMMON or STT_OBJECT for
common symbol depending on BFD_CONVERT_ELF_COMMON and
BFD_USE_ELF_STT_COMMON. Set sym.st_info after sym.st_shndx.
* elfxx-target.h (TARGET_BIG_SYM): Add BFD_CONVERT_ELF_COMMON
and BFD_USE_ELF_STT_COMMON to object_flags.
(TARGET_LITTLE_SYM): Likewise.
* syms.c (BSF_KEEP_G): Renamed to ...
(BSF_ELF_COMMON): This.
* bfd-in2.h: Regenerated.
* config.in: Likewise.
* configure: Likewise.
binutils/
PR ld/19645
* NEWS: Mention --elf-stt-common= for objcopy.
* doc/binutils.texi: Document --elf-stt-common= for objcopy.
* objcopy.c (do_elf_stt_common): New.
(command_line_switch): Add OPTION_ELF_STT_COMMON.
(copy_options): Add --elf-stt-common=.
(copy_usage): Add --elf-stt-common=.
(copy_object): Also check do_elf_stt_common for ELF targets.
(copy_file): Handle do_elf_stt_common.
(copy_main): Handle OPTION_ELF_STT_COMMON.
* readelf.c (apply_relocations): Support STT_COMMON.
* testsuite/binutils-all/common-1.s: New file.
* testsuite/binutils-all/common-1a.d: Likewise.
* testsuite/binutils-all/common-1b.d: Likewise.
* testsuite/binutils-all/common-1c.d: Likewise.
* testsuite/binutils-all/common-1d.d: Likewise.
* testsuite/binutils-all/common-1e.d: Likewise.
* testsuite/binutils-all/common-1f.d: Likewise.
* testsuite/binutils-all/common-2.s: Likewise.
* testsuite/binutils-all/common-2a.d: Likewise.
* testsuite/binutils-all/common-2b.d: Likewise.
* testsuite/binutils-all/common-2c.d: Likewise.
* testsuite/binutils-all/common-2d.d: Likewise.
* testsuite/binutils-all/common-2e.d: Likewise.
* testsuite/binutils-all/common-2f.d: Likewise.
* testsuite/binutils-all/objcopy.exp
(objcopy_test_elf_common_symbols): New proc.
Run objcopy_test_elf_common_symbols for ELF targets
gas/
PR ld/19645
* NEWS: Mention --enable-elf-stt-common and --elf-stt-common=
for ELF assemblers.
* as.c (flag_use_elf_stt_common): New.
(show_usage): Add --elf-stt-common=.
(option_values): Add OPTION_ELF_STT_COMMON.
(std_longopts): Add --elf-stt-common=.
(parse_args): Handle --elf-stt-common=.
* as.h (flag_use_elf_stt_common): New.
* config.in: Regenerated.
* configure: Likewise.
* configure.ac: Add --enable-elf-stt-common and define
DEFAULT_GENERATE_ELF_STT_COMMON.
* gas/write.c (write_object_file): Set BFD_CONVERT_ELF_COMMON
and BFD_USE_ELF_STT_COMMON if flag_use_elf_stt_common is set.
* doc/as.texinfo: Document --elf-stt-common=.
* testsuite/gas/elf/common3.s: New file.
* testsuite/gas/elf/common3a.d: Likewise.
* testsuite/gas/elf/common3b.d: Likewise.
* testsuite/gas/elf/common4.s: Likewise.
* testsuite/gas/elf/common4a.d: Likewise.
* testsuite/gas/elf/common4b.d: Likewise.
* testsuite/gas/i386/dw2-compress-3b.d: Likewise.
* testsuite/gas/i386/dw2-compressed-3b.d: Likewise.
* testsuite/gas/elf/elf.exp: Run common3a, common3b, common4a
and common4b.
* testsuite/gas/i386/dw2-compress-3.d: Renamed to ...
* testsuite/gas/i386/dw2-compress-3a.d: This. Pass
--elf-stt-common=no to as.
* testsuite/gas/i386/dw2-compressed-3.d: Renamed to ...
* testsuite/gas/i386/dw2-compressed-3a.d: This. Pass
--elf-stt-common=no to as.
* testsuite/gas/i386/i386.exp: Run dw2-compress-3a,
dw2-compress-3b, dw2-compressed-3a and dw2-compressed-3b instead
of dw2-compress-3 and dw2-compressed-3.
include/
PR ld/19645
* bfdlink.h (bfd_link_elf_stt_common): New enum.
(bfd_link_info): Add elf_stt_common.
ld/
PR ld/19645
* NEWS: Mention -z common/-z nocommon for ELF targets.
* emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Handle
-z common and -z nocommon.
* ld.texinfo: Document -z common/-z nocommon.
* lexsup.c (elf_shlib_list_options): Add -z common/-z nocommon.
* testsuite/ld-elf/tls_common.exp: Test --elf-stt-common=no and
--elf-stt-common=yes with assembler.
* testsuite/ld-elfcomm/common-1.s: New file.
* testsuite/ld-elfcomm/common-1a.d: Likewise.
* testsuite/ld-elfcomm/common-1b.d: Likewise.
* testsuite/ld-elfcomm/common-1c.d: Likewise.
* testsuite/ld-elfcomm/common-1d.d: Likewise.
* testsuite/ld-elfcomm/common-1e.d: Likewise.
* testsuite/ld-elfcomm/common-1f.d: Likewise.
* testsuite/ld-elfcomm/common-2.s: Likewise.
* testsuite/ld-elfcomm/common-2a.d: Likewise.
* testsuite/ld-elfcomm/common-2b.d: Likewise.
* testsuite/ld-elfcomm/common-2c.d: Likewise.
* testsuite/ld-elfcomm/common-2d.d: Likewise.
* testsuite/ld-elfcomm/common-2e.d: Likewise.
* testsuite/ld-elfcomm/common-2f.d: Likewise.
* testsuite/ld-elfcomm/common-3a.rd: Likewise.
* testsuite/ld-elfcomm/common-3b.rd: Likewise.
* testsuite/ld-i386/pr19645.d: Likewise.
* testsuite/ld-i386/pr19645.s: Likewise.
* testsuite/ld-x86-64/largecomm-1.s: Likewise.
* testsuite/ld-x86-64/largecomm-1a.d: Likewise.
* testsuite/ld-x86-64/largecomm-1b.d: Likewise.
* testsuite/ld-x86-64/largecomm-1c.d: Likewise.
* testsuite/ld-x86-64/largecomm-1d.d: Likewise.
* testsuite/ld-x86-64/largecomm-1e.d: Likewise.
* testsuite/ld-x86-64/largecomm-1f.d: Likewise.
* testsuite/ld-x86-64/pr19645.d: Likewise.
* testsuite/ld-x86-64/pr19645.s: Likewise.
* testsuite/ld-elfcomm/elfcomm.exp: Test --elf-stt-common=yes
with assembler.
(assembler_generates_commons): Removed.
Run -z common/-z nocommon tests. Run *.d tests.
* testsuite/ld-i386/i386.exp: Run pr19645.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-x86-64/dwarfreloc.exp: Test --elf-stt-common with
assembler. Test STT_COMMON with readelf.
2016-02-23 01:18:52 +08:00
proc objcopy_test_elf_common_symbols {} {
global srcdir
global subdir
# hpux has a non-standard common directive.
if { [istarget "*-*-hpux*"] } then {
return
}
set test_list [lsort [glob -nocomplain $srcdir/$subdir/common-*.d]]
foreach t $test_list {
# We need to strip the ".d", but can leave the dirname.
verbose [file rootname $t]
run_dump_test [file rootname $t]
}
}
2005-10-20 01:39:43 +08:00
# ia64 specific tests
if { ([istarget "ia64-*-elf*"]
|| [istarget "ia64-*-linux*"]) } {
2020-03-27 18:54:26 +08:00
objcopy_test "ia64 link order" link-order.s object "" ""
2005-10-20 04:49:03 +08:00
}
2005-10-20 01:39:43 +08:00
2005-10-20 04:49:03 +08:00
# ELF specific tests
2018-08-13 12:11:18 +08:00
set elf64 ""
2005-10-20 04:49:03 +08:00
if [is_elf_format] {
objcopy: Improve wildcard matching for symbols with '!' prefix.
When using options such as --localize-symbol, --globalize-symbol, etc,
along with the --wildcard option, prefixing a symbol name with '!'
should provide non-matching behaviour, as example the following example
is given in the manual:
--wildcard --weaken-symbol !foo --weaken-symbol fo*
which should weaken all symbols matching the pattern 'fo*', but not the
symbol 'foo'.
However, this currently does not work, the current logic will waken all
symbols matching the pattern 'fo*' AND all symbols that are not 'foo'.
The symbol 'foo' is covered by the first condition, and so is weakened,
while, other symbols, for example 'bar' will match the second condition,
and so be weakened.
This patch adjusts the logic so that a pattern prefixed with '!'
specifically DOES NOT apply the relevant change to any matching symbols,
instead of applying the change to all non-matching symbols. So this:
--weaken-symbol !foo
will ensure that the symbol 'foo' is not weakened, but says nothing
about symbols that are not 'foo'. As a result, a pattern prefixed with
'!' now only makes sense when used alongside a more wide ranging
wildcard pattern.
This change should make the wildcard matching feature more useful, with
no overall loss of functionality. The example given in the manual,
weaken all symbols matching 'fo*' except 'foo' can now be achieved, but
so too can more complex examples, such as weaken all symbols matching
'fo*' except 'foo', 'foa', and 'fob', like this:
--wildcard --weaken-symbol !foo \
--weaken-symbol !foa \
--weaken-symbol !fob \
--weaken-symbol fo*
Under the previous scheme, something as symbols as, weaken all symbols
except 'foo' could have been achieved with this:
--weaken-symbol !foo
however, this will no longer work. To achieve the same result under the
new scheme this is now required:
--weaken-symbol !foo --weaken-symbol *
binutils/ChangeLog:
* objcopy.c (is_specified_symbol_predicate): Don't stop at first
match. Non-match rules set found to FALSE.
binutils/testsuite/ChangeLog:
* binutils-all/objcopy.exp: Run new symbol tests.
(objcopy_test_symbol_manipulation): New function.
* binutils-all/symbols-1.d: New file.
* binutils-all/symbols-2.d: New file.
* binutils-all/symbols-3.d: New file.
* binutils-all/symbols-4.d: New file.
* binutils-all/symbols.s: New file.
2015-07-31 20:48:22 +08:00
objcopy_test_symbol_manipulation
Properly implement STT_COMMON
The BFD configure option, --enable-elf-stt-common, can't be to used to
verify STT_COMMON implementation with the normal binutils build. Instead,
this patch removes it from BFD. It adds --elf-stt-common=[no|yes] to ELF
assembler/objcopy and adds -z common/-z nocommon to ld.
A configure option, --enable-elf-stt-common, is added to gas to specify
whether ELF assembler should generate common symbols with the STT_COMMON
type by default.
Since BSF_KEEP_G is never used, it is renamed to BSF_ELF_COMMON for ELF
common symbols.
bfd/
PR ld/19645
* bfd.c (bfd): Change flags to 20 bits.
(BFD_CONVERT_ELF_COMMON): New.
(BFD_USE_ELF_STT_COMMON): Likewise.
(BFD_FLAGS_SAVED): Add BFD_CONVERT_ELF_COMMON and
BFD_USE_ELF_STT_COMMON.
(BFD_FLAGS_FOR_BFD_USE_MASK): Likewise.
* configure.ac: Remove --enable-elf-stt-common.
* elf.c (swap_out_syms): Choose STT_COMMON or STT_OBJECT for
common symbol depending on BFD_CONVERT_ELF_COMMON and
BFD_USE_ELF_STT_COMMON.
* elfcode.h (elf_slurp_symbol_table): Set BSF_ELF_COMMON for
STT_COMMON.
* elflink.c (bfd_elf_link_mark_dynamic_symbol): Also check
STT_COMMON.
(elf_link_convert_common_type): New function.
(elf_link_output_extsym): Choose STT_COMMON or STT_OBJECT for
common symbol depending on BFD_CONVERT_ELF_COMMON and
BFD_USE_ELF_STT_COMMON. Set sym.st_info after sym.st_shndx.
* elfxx-target.h (TARGET_BIG_SYM): Add BFD_CONVERT_ELF_COMMON
and BFD_USE_ELF_STT_COMMON to object_flags.
(TARGET_LITTLE_SYM): Likewise.
* syms.c (BSF_KEEP_G): Renamed to ...
(BSF_ELF_COMMON): This.
* bfd-in2.h: Regenerated.
* config.in: Likewise.
* configure: Likewise.
binutils/
PR ld/19645
* NEWS: Mention --elf-stt-common= for objcopy.
* doc/binutils.texi: Document --elf-stt-common= for objcopy.
* objcopy.c (do_elf_stt_common): New.
(command_line_switch): Add OPTION_ELF_STT_COMMON.
(copy_options): Add --elf-stt-common=.
(copy_usage): Add --elf-stt-common=.
(copy_object): Also check do_elf_stt_common for ELF targets.
(copy_file): Handle do_elf_stt_common.
(copy_main): Handle OPTION_ELF_STT_COMMON.
* readelf.c (apply_relocations): Support STT_COMMON.
* testsuite/binutils-all/common-1.s: New file.
* testsuite/binutils-all/common-1a.d: Likewise.
* testsuite/binutils-all/common-1b.d: Likewise.
* testsuite/binutils-all/common-1c.d: Likewise.
* testsuite/binutils-all/common-1d.d: Likewise.
* testsuite/binutils-all/common-1e.d: Likewise.
* testsuite/binutils-all/common-1f.d: Likewise.
* testsuite/binutils-all/common-2.s: Likewise.
* testsuite/binutils-all/common-2a.d: Likewise.
* testsuite/binutils-all/common-2b.d: Likewise.
* testsuite/binutils-all/common-2c.d: Likewise.
* testsuite/binutils-all/common-2d.d: Likewise.
* testsuite/binutils-all/common-2e.d: Likewise.
* testsuite/binutils-all/common-2f.d: Likewise.
* testsuite/binutils-all/objcopy.exp
(objcopy_test_elf_common_symbols): New proc.
Run objcopy_test_elf_common_symbols for ELF targets
gas/
PR ld/19645
* NEWS: Mention --enable-elf-stt-common and --elf-stt-common=
for ELF assemblers.
* as.c (flag_use_elf_stt_common): New.
(show_usage): Add --elf-stt-common=.
(option_values): Add OPTION_ELF_STT_COMMON.
(std_longopts): Add --elf-stt-common=.
(parse_args): Handle --elf-stt-common=.
* as.h (flag_use_elf_stt_common): New.
* config.in: Regenerated.
* configure: Likewise.
* configure.ac: Add --enable-elf-stt-common and define
DEFAULT_GENERATE_ELF_STT_COMMON.
* gas/write.c (write_object_file): Set BFD_CONVERT_ELF_COMMON
and BFD_USE_ELF_STT_COMMON if flag_use_elf_stt_common is set.
* doc/as.texinfo: Document --elf-stt-common=.
* testsuite/gas/elf/common3.s: New file.
* testsuite/gas/elf/common3a.d: Likewise.
* testsuite/gas/elf/common3b.d: Likewise.
* testsuite/gas/elf/common4.s: Likewise.
* testsuite/gas/elf/common4a.d: Likewise.
* testsuite/gas/elf/common4b.d: Likewise.
* testsuite/gas/i386/dw2-compress-3b.d: Likewise.
* testsuite/gas/i386/dw2-compressed-3b.d: Likewise.
* testsuite/gas/elf/elf.exp: Run common3a, common3b, common4a
and common4b.
* testsuite/gas/i386/dw2-compress-3.d: Renamed to ...
* testsuite/gas/i386/dw2-compress-3a.d: This. Pass
--elf-stt-common=no to as.
* testsuite/gas/i386/dw2-compressed-3.d: Renamed to ...
* testsuite/gas/i386/dw2-compressed-3a.d: This. Pass
--elf-stt-common=no to as.
* testsuite/gas/i386/i386.exp: Run dw2-compress-3a,
dw2-compress-3b, dw2-compressed-3a and dw2-compressed-3b instead
of dw2-compress-3 and dw2-compressed-3.
include/
PR ld/19645
* bfdlink.h (bfd_link_elf_stt_common): New enum.
(bfd_link_info): Add elf_stt_common.
ld/
PR ld/19645
* NEWS: Mention -z common/-z nocommon for ELF targets.
* emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Handle
-z common and -z nocommon.
* ld.texinfo: Document -z common/-z nocommon.
* lexsup.c (elf_shlib_list_options): Add -z common/-z nocommon.
* testsuite/ld-elf/tls_common.exp: Test --elf-stt-common=no and
--elf-stt-common=yes with assembler.
* testsuite/ld-elfcomm/common-1.s: New file.
* testsuite/ld-elfcomm/common-1a.d: Likewise.
* testsuite/ld-elfcomm/common-1b.d: Likewise.
* testsuite/ld-elfcomm/common-1c.d: Likewise.
* testsuite/ld-elfcomm/common-1d.d: Likewise.
* testsuite/ld-elfcomm/common-1e.d: Likewise.
* testsuite/ld-elfcomm/common-1f.d: Likewise.
* testsuite/ld-elfcomm/common-2.s: Likewise.
* testsuite/ld-elfcomm/common-2a.d: Likewise.
* testsuite/ld-elfcomm/common-2b.d: Likewise.
* testsuite/ld-elfcomm/common-2c.d: Likewise.
* testsuite/ld-elfcomm/common-2d.d: Likewise.
* testsuite/ld-elfcomm/common-2e.d: Likewise.
* testsuite/ld-elfcomm/common-2f.d: Likewise.
* testsuite/ld-elfcomm/common-3a.rd: Likewise.
* testsuite/ld-elfcomm/common-3b.rd: Likewise.
* testsuite/ld-i386/pr19645.d: Likewise.
* testsuite/ld-i386/pr19645.s: Likewise.
* testsuite/ld-x86-64/largecomm-1.s: Likewise.
* testsuite/ld-x86-64/largecomm-1a.d: Likewise.
* testsuite/ld-x86-64/largecomm-1b.d: Likewise.
* testsuite/ld-x86-64/largecomm-1c.d: Likewise.
* testsuite/ld-x86-64/largecomm-1d.d: Likewise.
* testsuite/ld-x86-64/largecomm-1e.d: Likewise.
* testsuite/ld-x86-64/largecomm-1f.d: Likewise.
* testsuite/ld-x86-64/pr19645.d: Likewise.
* testsuite/ld-x86-64/pr19645.s: Likewise.
* testsuite/ld-elfcomm/elfcomm.exp: Test --elf-stt-common=yes
with assembler.
(assembler_generates_commons): Removed.
Run -z common/-z nocommon tests. Run *.d tests.
* testsuite/ld-i386/i386.exp: Run pr19645.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-x86-64/dwarfreloc.exp: Test --elf-stt-common with
assembler. Test STT_COMMON with readelf.
2016-02-23 01:18:52 +08:00
objcopy_test_elf_common_symbols
2020-03-28 07:58:03 +08:00
setup_xfail "hppa*-*-*"
setup_xfail "sh-*-coff*"
setup_xfail "tic54x-*-*"
clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"
2020-03-28 12:01:02 +08:00
clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "hppa*-*-*elf*"
2020-03-27 18:54:26 +08:00
objcopy_test "ELF unknown section type" unknown.s object "" ""
2020-03-28 07:58:03 +08:00
2018-09-17 17:10:47 +08:00
objcopy_test_readelf "ELF group 1" group.s
objcopy_test_readelf "ELF group 2" group-2.s
objcopy_test_readelf "ELF group 3" group-3.s
objcopy_test_readelf "ELF group 4" group-4.s
Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX
Mark an ALLOC section, which should be placed in special memory area,
with SHF_GNU_MBIND. Its sh_info field indicates the special memory
type. GNU_MBIND section names start with ".mbind" so that they are
placed as orphan sections by linker. All input GNU_MBIND sections
with the same sh_type, sh_flags and sh_info are placed in one output
GNU_MBIND section. In executable and shared object, create a
GNU_MBIND segment for each GNU_MBIND section and its segment type is
PT_GNU_MBIND_LO plus the sh_info value. Each GNU_MBIND segment is
aligned at page boundary.
The assembler syntax:
.section .mbind.foo,"adx",%progbits
^ 0: Special memory type.
|
'd' for SHF_GNU_MBIND.
.section .mbind.foo,"adx",%progbits,0x1
^ 1: Special memory type.
|
'd' for SHF_GNU_MBIND.
.section .mbind.bar,"adG",%progbits,.foo_group,comdat,0x2
^ 2: Special memory type.
|
'd' for SHF_GNU_MBIND.
bfd/
* elf.c (get_program_header_size): Add a GNU_MBIND segment for
each GNU_MBIND section and align GNU_MBIND section to page size.
(_bfd_elf_map_sections_to_segments): Create a GNU_MBIND
segment for each GNU_MBIND section.
(_bfd_elf_init_private_section_data): Copy sh_info from input
for GNU_MBIND section.
binutils/
* NEWS: Mention support for ELF SHF_GNU_MBIND and
PT_GNU_MBIND_XXX.
* readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX.
(get_elf_section_flags): Handle SHF_GNU_MBIND.
(process_section_headers): Likewise.
* testsuite/binutils-all/mbind1.s: New file.
* testsuite/binutils-all/objcopy.exp: Run readelf test on
mbind1.s.
gas/
* NEWS: Mention support for ELF SHF_GNU_MBIND.
* config/obj-elf.c (section_match): New.
(get_section): Match both sh_info and group name.
(obj_elf_change_section): Add argument for sh_info. Pass both
sh_info and group name to get_section. Issue an error for
SHF_GNU_MBIND section without SHF_ALLOC. Set sh_info.
(obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'.
(obj_elf_section): Support SHF_GNU_MBIND section info.
* config/obj-elf.h (obj_elf_change_section): Add argument for
sh_info.
* config/tc-arm.c (start_unwind_section): Pass 0 as sh_info to
obj_elf_change_section.
* config/tc-ia64.c (obj_elf_vms_common): Likewise.
* config/tc-microblaze.c (microblaze_s_data): Likewise.
(microblaze_s_sdata): Likewise.
(microblaze_s_rdata): Likewise.
(microblaze_s_bss): Likewise.
* config/tc-mips.c (s_change_section): Likewise.
* config/tc-msp430.c (msp430_profiler): Likewise.
* config/tc-rx.c (parse_rx_section): Likewise.
* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
* doc/as.texinfo: Document 'd' for SHF_GNU_MBIND.
* testsuite/gas/elf/elf.exp: Run section12a, section12b and
section13.
* testsuite/gas/elf/section10.d: Updated.
* testsuite/gas/elf/section10.s: Likewise.
* testsuite/gas/elf/section12.s: New file.
* testsuite/gas/elf/section12a.d: Likewise.
* testsuite/gas/elf/section12b.d: Likewise.
* testsuite/gas/elf/section13.l: Likewise.
* testsuite/gas/elf/section13.d: Likewise.
* testsuite/gas/elf/section13.s: Likewise.
include/
* elf/common.h (PT_GNU_MBIND_NUM): New.
(PT_GNU_MBIND_LO): Likewise.
(PT_GNU_MBIND_HI): Likewise.
(SHF_GNU_MBIND): Likewise.
ld/
* NEWS: Mention support for ELF SHF_GNU_MBIND and
PT_GNU_MBIND_XXX.
* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place
input GNU_MBIND sections with the same type, attributes and
sh_info field into a single output GNU_MBIND section.
* testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b.
* testsuite/ld-elf/mbind1.s: New file.
* testsuite/ld-elf/mbind1a.d: Likewise.
* testsuite/ld-elf/mbind1b.d: Likewise.
* testsuite/ld-elf/mbind1c.d: Likewise.
* testsuite/ld-elf/mbind2a.s: Likewise.
* testsuite/ld-elf/mbind2b.c: Likewise.
2017-04-05 00:05:48 +08:00
objcopy_test_readelf "GNU_MBIND section" mbind1.s
2010-02-18 08:13:30 +08:00
run_dump_test "group-5"
2011-09-16 12:23:19 +08:00
run_dump_test "group-6"
2018-02-13 11:39:48 +08:00
run_dump_test "group-7a"
run_dump_test "group-7b"
run_dump_test "group-7c"
2006-05-01 22:09:35 +08:00
run_dump_test "copy-1"
2010-02-01 17:59:46 +08:00
run_dump_test "note-1"
2019-07-23 16:14:19 +08:00
# Use copytest.o from the note-1 test to determine ELF32 or ELF64
if [is_elf64 tmpdir/copytest.o] {
2018-08-13 12:11:18 +08:00
set elf64 "--defsym ELF64=1"
2017-03-01 19:09:46 +08:00
run_dump_test "note-2-64"
2017-08-17 21:49:01 +08:00
run_dump_test "note-3-64"
2018-01-03 18:28:33 +08:00
run_dump_test "note-4-64"
2019-10-25 23:46:07 +08:00
run_dump_test "note-6-64"
2017-03-01 19:09:46 +08:00
} else {
run_dump_test "note-2-32"
2017-08-17 21:49:01 +08:00
run_dump_test "note-3-32"
2018-01-03 18:28:33 +08:00
run_dump_test "note-4-32"
2019-10-25 23:46:07 +08:00
run_dump_test "note-6-32"
2017-03-01 19:09:46 +08:00
}
2018-04-26 22:12:42 +08:00
run_dump_test "note-5"
2005-10-20 01:39:43 +08:00
}
2006-04-26 21:37:05 +08:00
run_dump_test "copy-2"
2006-05-03 22:21:18 +08:00
run_dump_test "copy-3"
2009-03-10 08:48:10 +08:00
run_dump_test "copy-4"
2018-10-11 18:38:10 +08:00
run_dump_test "copy-5"
2019-01-08 22:52:53 +08:00
run_dump_test "copy-6"
2018-10-11 18:38:10 +08:00
2018-08-13 12:11:18 +08:00
# Use bintest.o from the copy-4 test to determine ELF reloc type
set reloc_format rel
if { [is_elf_format] && [is_rela tmpdir/bintest.o] } {
set reloc_format rela
}
2015-09-30 00:35:47 +08:00
run_dump_test "pr19020a"
run_dump_test "pr19020b"
2006-06-24 00:23:09 +08:00
if [is_elf_format] {
2006-09-15 07:37:35 +08:00
run_dump_test "strip-1"
run_dump_test "strip-2"
2007-04-13 03:20:46 +08:00
run_dump_test "strip-3"
2008-10-02 05:54:59 +08:00
run_dump_test "strip-4"
run_dump_test "strip-5"
2008-10-02 07:10:48 +08:00
run_dump_test "strip-6"
run_dump_test "strip-7"
2008-10-02 09:06:12 +08:00
run_dump_test "strip-8"
run_dump_test "strip-9"
2015-08-08 01:28:42 +08:00
run_dump_test "strip-12"
binutils/testsuite: Support REL and MIPS64 reloc formats with `strip-13'
Add source variants for the `strip-13' test that produce relocations in
the REL and MIPS64 formats, fixing a failure for the `mips64el-openbsd'
target. This also corrects output for `i*86-*', `i960-*', `m6812-*' and
`m68hc12-*', o32 `mips*-*', and `score*-*' targets, which however does
not show up as a test result change due to lax error message matching
causing `bad value' previously produced by `strip' as a result of input
file rejection to be accepted as a test pass.
For `m6811-*' aka `m68hc11-*' targets this causes a phantom regression,
because they use 16-bit addressing and therefore `.dc.a' emits 16-bit
quantities causing relocation data constructed in assembly not to be as
expected. Previously input was rejected by `strip' with a `bad value'
message and now it is accepted, however due to the relocation data error
the relocation number is not one of the unsupported ones and the tool
completes successfully, which scores as a test failure.
Disable the test case for `m6811-*' and `m68hc11-*' targets then, as it
is a test case bug rather than a problem with the relevant backend. A
separate change to the test case is required to correct this problem, at
which point the test case can be enabled for the affected targets.
binutils/
* testsuite/binutils-all/strip-13.s: Rename to...
* testsuite/binutils-all/strip-13rela.s: ... this.
* testsuite/binutils-all/strip-13rel.s: New test source.
* testsuite/binutils-all/strip-13mips64.s: New test source.
* testsuite/binutils-all/strip-13.d: Remove `arm-*', `d10v-*',
`dlx-*' and `xgate-*' from `not-target' list. Add `m6811-*' and
`m68hc11-*' to `not-target' list.
* testsuite/binutils-all/objcopy.exp: Switch between sources for
`strip-13'.
2018-04-05 20:08:35 +08:00
if { [istarget "mips64*-*-openbsd*"] } {
set reloc_format mips64
}
2018-08-13 12:11:18 +08:00
# A relocation type not supported by any target
Andes Technology has good news for you, we plan to update the nds32 port of binutils on upstream!
We have not only removed all unsupported and obsolete code, but also supported lost of new features,
including better link-time relaxations and TLS implementations. Besides, the files generated by the
newly assembler and linker usually get higher performance and more optimized code size.
ld * emultempl/nds32elf.em (hyper_relax): New variable.
(nds32_elf_create_output_section_statements):
the parameters of bfd_elf32_nds32_set_target_option
(PARSE_AND_LIST_PROLOGUE, PARSE_AND_LIST_OPTIONS,
PARSE_AND_LIST_ARGS_CASES): Add new option --mhyper-relax.
* emultempl/nds32elf.em (nds32_elf_after_open): Updated.
* emultempl/nds32elf.em (tls_desc_trampoline): New variable.
* (nds32_elf_create_output_section_statements): Updated.
* (nds32_elf_after_parse): Disable relaxations when PIC is enable.
* (PARSE_AND_LIST_PROLOGUE, PARSE_AND_LIST_OPTIONS,
PARSE_AND_LIST_ARGS_CASES): Add new option --m[no-]tlsdesc-trampoline.
include * elf/nds32.h: Remove the unused target features.
* dis-asm.h (disassemble_init_nds32): Declared.
* elf/nds32.h (E_NDS32_NULL): Removed.
(E_NDS32_HAS_DSP_INST, E_NDS32_HAS_ZOL): New.
* opcode/nds32.h: Ident.
(N32_SUB6, INSN_LW): New macros.
(enum n32_opcodes): Updated.
* elf/nds32.h: Doc fixes.
* elf/nds32.h: Add R_NDS32_LSI.
* elf/nds32.h: Add new relocations for TLS.
gas * config/tc-nds32.c: Remove the unused target features.
(nds32_relax_relocs, md_pseudo_table, nds32_elf_record_fixup_exp,
nds32_set_elf_flags_by_insn, nds32_insert_relax_entry,
nds32_apply_fix): Likewise.
(nds32_no_ex9_begin): Removed.
* config/tc-nds32.c (add_mapping_symbol_for_align,
make_mapping_symbol, add_mapping_symbol): New functions.
* config/tc-nds32.h (enum mstate): New.
(nds32_segment_info_type): Likewise.
* configure.ac (--enable-dsp-ext, --enable-zol-ext): New options.
* config.in: Regenerated.
* configure: Regenerated.
* config/tc-nds32.c (nds32_dx_regs):
Set the value according to the configuration.
(nds32_perf_ext, nds32_perf_ext2, nds32_string_ext, nds32_audio_ext):
Likewise.
(nds32_dsp_ext): New variable. Set the value according to the
configuration.
(nds32_zol_ext): Likewise.
(asm_desc, nds32_pseudo_opcode_table): Make them static.
(nds32_set_elf_flags_by_insn): Updated.
(nds32_check_insn_available): Updated.
(nds32_str_tolower): New function.
* config/tc-nds32.c (relax_table): Updated.
(md_begin): Updated.
(md_assemble): Use XNEW macro to allocate space for `insn.info',
and then remember to free it.
(md_section_align): Cast (-1) to ValueT.
(nds32_get_align): Cast (~0U) to addressT.
(nds32_relax_branch_instructions): Updated.
(md_convert_frag): Add new local variable `final_r_type'.
(invalid_prev_frag): Add new bfd_boolean parameter `relax'.
All callers changed.
* config/tc-nds32.c (struct nds32_relocs_pattern): Add `insn' field.
(struct nds32_hint_map): Add `option_list' field.
(struct suffix_name, suffix_table): Remove the unused `pic' field.
(do_pseudo_b, do_pseudo_bal): Remove the suffix checking.
(do_pseudo_la_internal, do_pseudo_pushpopm): Indent.
(relax_hint_bias, relax_hint_id_current): New static variables.
(reset_bias, relax_hint_begin): New variables.
(nds_itoa): New function.
(CLEAN_REG, GET_OPCODE): New macros.
(struct relax_hint_id): New.
(nds32_relax_hint): For .relax_hint directive, we can use `begin'
and `end' to mark the relax pattern without giving exactly id number.
(nds32_elf_append_relax_relocs): Handle the case that the .relax_hint
directives are attached to pseudo instruction.
(nds32_elf_save_pseudo_pattern): Change the second parameter from
instruction's opcode to byte code.
(nds32_elf_build_relax_relation): Add new bfd_boolean parameter
`pseudo_hint'.
(nds32_lookup_pseudo_opcode): Fix the overflow issue.
(enum nds32_insn_type): Add N32_RELAX_ALU1 and N32_RELAX_16BIT.
(nds32_elf_record_fixup_exp, relax_ls_table, hint_map,
nds32_find_reloc_table, nds32_match_hint_insn, nds32_parse_name):
Updated.
* config/tc-nds32.h (MAX_RELAX_NUM): Extend it to 6.
(enum nds32_relax_hint_type): Merge NDS32_RELAX_HINT_LA and
NDS32_RELAX_HINT_LS into NDS32_RELAX_HINT_LALS. Add
NDS32_RELAX_HINT_LA_PLT, NDS32_RELAX_HINT_LA_GOT and
NDS32_RELAX_HINT_LA_GOTOFF.
* config/tc-nds32.h (relax_ls_table): Add floating load/store
to gp relax pattern.
(hint_map, nds32_find_reloc_table): Likewise.
* configure.ac: Define NDS32_LINUX_TOOLCHAIN.
* configure: Regenerated.
* config.in: Regenerated.
* config/tc-nds32.h (enum nds32_ramp): Updated.
(enum nds32_relax_hint_type): Likewise.
* config/tc-nds32.c: Include "errno.h" and "limits.h".
(relax_ls_table): Add TLS relax patterns.
(nds32_elf_append_relax_relocs): Attach BFD_RELOC_NDS32_GROUP on
each instructions of TLS patterns.
(nds32_elf_record_fixup_exp): Updated.
(nds32_apply_fix): Likewise.
(suffix_table): Add TLSDESC suffix.
binutils* testsuite/binutils-all/objcopy.exp: Set the unsupported reloc number
from 215 to 255 for NDS32.
bfd * elf32-nds32.c (nds32_elf_relax_loadstore):
Remove the unused target features.
(bfd_elf32_nds32_set_target_option): Remove the unused parameters.
(nds32_elf_relax_piclo12, nds32_elf_relax_letlslo12,
nds32_elf_relax_letlsadd, nds32_elf_relax_letlsls,
nds32_elf_relax_pltgot_suff, nds32_elf_relax_got_suff
nds32_elf_relax_gotoff_suff, calculate_plt_memory_address,
calculate_plt_offset, calculate_got_memory_address,
nds32_elf_check_dup_relocs): Removed.
All callers changed.
* elf32-nds32.h: Remove the unused macros and defines.
(elf_nds32_link_hash_table): Remove the unused variable.
(bfd_elf32_nds32_set_target_option): Update prototype.
(nds32_elf_ex9_init): Removed.
* elf32-nds32.c (nds32_convert_32_to_16): Updated.
* elf32-nds32.c (HOWTO2, HOWTO3): Define new HOWTO macros
to initialize array nds32_elf_howto_table in any order
without lots of EMPTY_HOWTO.
(nds32_reloc_map): Updated.
* reloc.c: Add BFD_RELOC_NDS32_LSI.
* bfd-in2.h: Regenerated.
* bfd/libbfd.h: Regenerated.
* elf32-nds32.c (nds32_elf_relax_howto_table): Add R_NDS32_LSI.
(nds32_reloc_map): Likewise.
(nds32_elf_relax_flsi): New function.
(nds32_elf_relax_section): Support floating load/store relaxation.
* elf32-nds32.c (NDS32_GUARD_SEC_P, elf32_nds32_local_gp_offset):
New macro.
(struct elf_nds32_link_hash_entry): New `offset_to_gp' field.
(struct elf_nds32_obj_tdata): New `offset_to_gp' and `hdr_size' fields.
(elf32_nds32_allocate_local_sym_info, nds32_elf_relax_guard,
nds32_elf_is_target_special_symbol, nds32_elf_maybe_function_sym):
New functions.
(nds32_info_to_howto_rel): Add BFD_ASSERT.
(bfd_elf32_bfd_reloc_type_table_lookup, nds32_elf_link_hash_newfunc,
nds32_elf_link_hash_table_create, nds32_elf_relocate_section,
nds32_elf_relax_loadstore, nds32_elf_relax_lo12, nds32_relax_adjust_label,
bfd_elf32_nds32_set_target_option, nds32_fag_mark_relax): Updated.
(nds32_elf_final_sda_base): Improve it to find the better gp value.
(insert_nds32_elf_blank): Must consider `len' when inserting blanks.
* elf32-nds32.h (bfd_elf32_nds32_set_target_option): Update prototype.
(struct elf_nds32_link_hash_table): Add new variable `hyper_relax'.
* elf32-nds32.c (elf32_nds32_allocate_dynrelocs): New function.
(create_got_section): Likewise.
(allocate_dynrelocs, nds32_elf_size_dynamic_sections,
nds32_elf_relocate_section, nds32_elf_finish_dynamic_symbol): Updated.
(nds32_elf_check_relocs): Fix the issue that the shared library may
has TEXTREL entry in the dynamic section.
(nds32_elf_create_dynamic_sections): Enable to call readonly_dynrelocs
since the TEXTREL issue is fixed in the nds32_elf_check_relocs.
(nds32_elf_finish_dynamic_sections): Update and add DT_RELASZ
dynamic entry.
(calculate_offset): Remove the unused parameter `pic_ext_target' and
related codes.
All callers changed.
(elf_backend_dtrel_excludes_plt): Disable it temporarily since it
will cause some errors for our test cases.
* elf32-nds32.c (nds32_elf_merge_private_bfd_data): Allow to link the
generic object.
* reloc.c: Add TLS relocations.
* libbfd.h: Regenerated.
* bfd-in2.h: Regenerated.
* elf32-nds32.h (struct section_id_list_t): New.
(elf32_nds32_lookup_section_id, elf32_nds32_check_relax_group,
elf32_nds32_unify_relax_group, nds32_elf_unify_tls_model):
New prototypes.
(elf32_nds32_compute_jump_table_size, elf32_nds32_local_tlsdesc_gotent):
New macro.
(nds32_insertion_sort, bfd_elf32_nds32_set_target_option,
elf_nds32_link_hash_table): Updated.
* elf32-nds32.c (enum elf_nds32_tls_type): New.
(struct elf32_nds32_relax_group_t, struct relax_group_list_t): New.
(elf32_nds32_add_dynreloc, patch_tls_desc_to_ie, get_tls_type,
fls, ones32, list_insert, list_insert_sibling, dump_chain,
elf32_nds32_check_relax_group, elf32_nds32_lookup_section_id,
elf32_nds32_unify_relax_group, nds32_elf_unify_tls_model): New functions.
(elf_nds32_obj_tdata): Add new fields.
(elf32_nds32_relax_group_ptr, nds32_elf_local_tlsdesc_gotent): New macros.
(nds32_elf_howto_table): Add TLS relocations.
(nds32_reloc_map): Likewise.
(nds32_elf_copy_indirect_symbol, nds32_elf_size_dynamic_sections,
nds32_elf_finish_dynamic_symbol, elf32_nds32_allocate_local_sym_info,
nds32_elf_relocate_section, bfd_elf32_nds32_set_target_option,
nds32_elf_check_relocs, allocate_dynrelocs): Updated.
(nds32_elf_relax_section): Call nds32_elf_unify_tls_model.
(dtpoff_base): Rename it to `gottpof' and then update it.
opcodes * nds32-asm.c (operand_fields): Remove the unused fields.
(nds32_opcodes): Remove the unused instructions.
* nds32-dis.c (nds32_ex9_info): Removed.
(nds32_parse_opcode): Updated.
(print_insn_nds32): Likewise.
* nds32-asm.c (config.h, stdlib.h, string.h): New includes.
(LEX_SET_FIELD, LEX_GET_FIELD): Update defines.
(nds32_asm_init, build_operand_hash_table, build_keyword_hash_table,
build_opcode_hash_table): New functions.
(nds32_keyword_table, nds32_keyword_count_table, nds32_field_table,
nds32_opcode_table): New.
(hw_ktabs): Declare it to a pointer rather than an array.
(build_hash_table): Removed.
* nds32-asm.h (enum): Add SYN_INPUT, SYN_OUTPUT, SYN_LOPT,
SYN_ROPT and upadte HW_GPR and HW_INT.
* nds32-dis.c (keywords): Remove const.
(match_field): New function.
(nds32_parse_opcode): Updated.
* disassemble.c (disassemble_init_for_target):
Add disassemble_init_nds32.
* nds32-dis.c (eum map_type): New.
(nds32_private_data): Likewise.
(get_mapping_symbol_type, is_mapping_symbol, nds32_symbol_is_valid,
nds32_add_opcode_hash_table, disassemble_init_nds32): New functions.
(print_insn_nds32): Updated.
* nds32-asm.c (parse_aext_reg): Add new parameter.
(parse_re, parse_re2, parse_aext_reg): Only reduced registers
are allowed to use.
All callers changed.
* nds32-asm.c (keyword_usr, keyword_sr): Updated.
(operand_fields): Add new fields.
(nds32_opcodes): Add new instructions.
(keyword_aridxi_mx): New keyword.
* nds32-asm.h (enum): Add NASM_ATTR_DSP_ISAEXT, HW_AEXT_ARIDXI_MX
and NASM_ATTR_ZOL.
(ALU2_1, ALU2_2, ALU2_3): New macros.
* nds32-dis.c (nds32_filter_unknown_insn): Updated.
2018-09-20 20:27:31 +08:00
if { [istarget "nds32*-*"] } {
set reloc 255
} else {
set reloc 215
}
2018-08-13 12:11:18 +08:00
run_dump_test "strip-13" [list \
[list source strip-13${reloc_format}.s] \
[list as "${elf64} --defsym RELOC=${reloc}"]]
2018-04-09 20:42:00 +08:00
# Select a relocation number that corresponds to one actually
# supported by the target and ABI being tested.
if { [istarget "aarch64*-*"] } {
set reloc 259
} elseif { [istarget "ia64*-*"] \
|| [istarget "m32r*-*"] \
2018-04-10 07:44:29 +08:00
|| [istarget "nds32*-*"] \
2018-04-09 20:42:00 +08:00
|| [istarget "v850*-*"] } {
set reloc 50
2018-04-10 07:44:29 +08:00
} elseif { [istarget "pru-*"] } {
set reloc 11
2018-04-09 20:42:00 +08:00
} else {
set reloc 1
}
run_dump_test "strip-14" [list \
2018-08-13 12:11:18 +08:00
[list source strip-14${reloc_format}.s] \
[list as "${elf64} --defsym RELOC=${reloc}"]]
2018-04-09 20:42:01 +08:00
run_dump_test "strip-15" [list \
2018-08-13 12:11:18 +08:00
[list source strip-15${reloc_format}.s] \
[list as "${elf64} --defsym RELOC=${reloc}"]]
Have info_to_howto functions return a success/fail status. Check this result. Stop strip from completeing if one of these functions fails.
bfd PR 22875
* elf-bfd.h (struct elf_backend_data): Change the return type of
the elf_info_to_howto and elf_info_to_howto_rel function pointers
to bfd_boolean.
* elfcode.h (elf_slurp_reloc_table_from_section): Check the return value from the info_to_howto function and fail if that function failed.
* elf32-h8300.c (elf32_h8_relocate_section): Check return value from the info_to_howto function.
(elf32_h8_relax_section): Likewise.
* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
* elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise.
* elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
* elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise.
* elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Likewise.
* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
* elfnn-ia64.c (elfNN_ia64_relocate_section): Likewise.
* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
(riscv_elf_relocate_section): Likewise.
* elf-hppa.h (elf_hppa_info_to_howto): Change return type to
bfd_boolean. Issue an error message, set an error value and
return FALSE if the reloc is not recognized.
(elf_hppa_info_to_howto_rel): Likewise.
* elf-m10200.c (mn10200_info_to_howto): Likewise.
* elf-m10300.c (mn10300_info_to_howto): Likewise.
* elf.c (_bfd_elf_no_info_to_howto): Likewise.
* elf32-arc.c (arc_info_to_howto_rel): Likewise.
* elf32-arm.c (elf32_arm_info_to_howto): Likewise.
* elf32-avr.c (avr_info_to_howto_rela): Likewise.
* elf32-bfin.c (bfin_info_to_howto): Likewise.
* elf32-cr16.c (elf_cr16_info_to_howto): Likewise.
* elf32-cr16c.c (elf_cr16c_info_to_howto): Likewise.
* elf32-cris.c (elf_cr16c_info_to_howto_rel, cris_info_to_howto_rela): Likewise.
* elf32-crx.c (elf_crx_info_to_howto): Likewise.
* elf32-d10v.c (d10v_info_to_howto_rel): Likewise.
* elf32-d30v.c (d30v_info_to_howto_rel, d30v_info_to_howto_rela): Likewise.
* elf32-dlx.c (dlx_rtype_to_howto, elf32_dlx_info_to_howto, elf32_dlx_info_to_howto_rel): Likewise.
* elf32-epiphany.c (epiphany_info_to_howto_rela): Likewise.
* elf32-fr30.c (fr30_info_to_howto_rela): Likewise.
* elf32-frv.c (frv_info_to_howto_rela, frvfdpic_info_to_howto_rel): Likewise.
* elf32-ft32.c (ft32_info_to_howto_rela): Likewise.
* elf32-gen.c (elf_generic_info_to_howto, elf_generic_info_to_howto_rel): Likewise.
* elf32-h8300.c (elf32_h8_info_to_howto, elf32_h8_info_to_howto_rel): Likewise.
* elf32-i370.c (i370_elf_info_to_howto): Likewise.
* elf32-i386.c (elf_i386_reloc_type_lookup, elf_i386_rtype_to_howto, elf_i386_info_to_howto_rel): Likewise.
* elf32-i860.c (lookup_howto, elf32_i860_info_to_howto_rela): Likewise.
* elf32-i960.c (elf32_i960_info_to_howto_rel): Likewise.
* elf32-ip2k.c (ip2k_info_to_howto_rela): Likewise.
* elf32-iq2000.c (iq2000_info_to_howto_rela): Likewise.
* elf32-lm32.c (lm32_info_to_howto_rela): Likewise.
* elf32-m32c.c (m32c_info_to_howto_rela): Likewise.
* elf32-m32r.c (m32r_info_to_howto_rel, m32r_info_to_howto): Likewise.
* elf32-m68hc11.c (m68hc11_info_to_howto_rel): Likewise.
* elf32-m68hc12.c (m68hc11_info_to_howto_rel): Likewise.
* elf32-m68k.c (rtype_to_howto): Likewise.
* elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
* elf32-mep.c (mep_info_to_howto_rela): Likewise.
* elf32-metag.c (metag_info_to_howto_rela): Likewise.
* elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
* elf32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): Likewise.
* elf32-moxie.c (moxie_info_to_howto_rela): Likewise.
* elf32-msp430.c (msp430_info_to_howto_rela): Likewise.
* elf32-mt.c (mt_info_to_howto_rela): Likewise.
* elf32-nds32.c (nds32_info_to_howto_rel, nds32_info_to_howto): Likewise.
* elf32-nios2.c (nios2_elf32_info_to_howto): Likewise.
* elf32-or1k.c (or1k_info_to_howto_rela): Likewise.
* elf32-pj.c (pj_elf_info_to_howto): Likewise.
* elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
* elf32-pru.c (pru_elf32_info_to_howto): Likewise.
* elf32-rl78.c (rl78_info_to_howto_rela): Likewise.
* elf32-rx.c (rx_info_to_howto_rela): Likewise.
* elf32-s390.c (elf_s390_info_to_howto): Likewise.
* elf32-score.c (s3_bfd_score_info_to_howto, _bfd_score_info_to_howto): Likewise.
* elf32-score7.c (s7_bfd_score_info_to_howto): Likewise.
* elf32-sh.c (sh_elf_info_to_howto): Likewise.
* elf32-spu.c (spu_elf_info_to_howto): Likewise.
* elf32-tic6x.c (elf32_tic6x_info_to_howto, elf32_tic6x_info_to_howto_rel): Likewise.
* elf32-tilepro.c (tilepro_info_to_howto_rela): Likewise.
* elf32-v850.c (v850_elf_info_to_howto_rel, v850_elf_info_to_howto_rela, v800_elf_info_to_howto): Likewise.
* elf32-vax.c (rtype_to_howto): Likewise.
* elf32-visium.c (visium_info_to_howto_rela): Likewise.
* elf32-wasm32.c (elf32_wasm32_rtype_to_howto, elf32_wasm32_info_to_howto_rela): Likewise.
* elf32-xc16x.c (elf32_xc16x_info_to_howto): Likewise.
* elf32-xgate.c (xgate_info_to_howto_rel): Likewise.
* elf32-xstormy16.c (xstormy16_info_to_howto_rela): Likewise.
* elf32-xtensa.c (elf_xtensa_info_to_howto_rela): Likewise.
* elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
* elf64-gen.c (elf_generic_info_to_howto, elf_generic_info_to_howto_rel): Likewise.
* elf64-ia64-vms.c (elf64_ia64_info_to_howto): Likewise.
* elf64-mips.c (mips_elf64_info_to_howto_rela): Likewise.
* elf64-mmix.c (mmix_info_to_howto_rela): Likewise.
* elf64-ppc.c (ppc64_elf_info_to_howto): Likewise.
* elf64-s390.c (elf_s390_reloc_type_lookup): Likewise.
* elf64-sh64.c (elf_s390_info_to_howto, sh_elf64_info_to_howto): Likewise.
* elf64-x86-64.c (elf_x86_64_info_to_howto): Likewise.
* elfn32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_info_to_howto): Likewise.
* elfnn-ia64.c (elfNN_ia64_info_to_howto): Likewise.
* elfnn-riscv.c (riscv_info_to_howto_rela): Likewise.
* elfxx-ia64.c (ia64_elf_reloc_type_lookup): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_info_to_howto): Likewise.
* elfxx-tilegx.c (tilegx_info_to_howto_rela): Likewise.
* elf32-score.h (s7_bfd_score_info_to_howto): Update prototype.
* elfxx-sparc.h (_bfd_sparc_elf_info_to_howto): Update prototype.
* elfxx-tilegx.h (tilegx_info_to_howto_rela): Update prototype.
* elfxx-target.h (elf_info_to_howto, elf_info_to_howto_rel): Default to NULL.
binutils PR 22875
* objcopy.c (copy_object): Check the error status after marking symbols used in relocations.
* testsuite/binutils-all/strip-13.s: New test source file.
* testsuite/binutils-all/strip-13.s: New test driver file.
* testsuite/binutils-all/objcopy.exp: Run the new test.
2018-02-27 18:15:13 +08:00
2016-05-16 15:51:26 +08:00
# This requires STB_GNU_UNIQUE support with OSABI set to GNU.
if { [supports_gnu_unique] } {
2010-09-23 20:04:37 +08:00
run_dump_test "strip-10"
}
2018-04-16 13:59:39 +08:00
run_dump_test "strip-11"
2007-04-24 18:56:58 +08:00
2007-05-15 12:23:50 +08:00
if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } {
# Check to make sure we don't strip a symbol named in relocations.
set test "objcopy keeps symbols needed by relocs"
2007-04-24 18:56:58 +08:00
2007-05-15 12:23:50 +08:00
set srcfile $srcdir/$subdir/needed-by-reloc.s
2007-04-24 18:56:58 +08:00
2007-05-15 12:23:50 +08:00
if {![binutils_assemble $srcfile tmpdir/bintest.o]} then {
2021-02-12 14:35:12 +08:00
unsupported $test
2007-05-15 12:23:50 +08:00
} else {
set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-symbol=foo tmpdir/bintest.o ${copyfile}.o"]
2007-04-24 18:56:58 +08:00
2007-05-15 12:23:50 +08:00
if [regexp "not stripping symbol `foo' because it is named in a relocation" $got] {
pass $test
} else {
fail $test
}
}
2007-04-24 18:56:58 +08:00
}
2007-05-15 12:23:50 +08:00
2012-03-13 08:41:22 +08:00
# The symbol table for some MIPS targets is sorted differently than
# the ELF canonical order, so the regexps in localize-hidden-1.d fail
2016-06-23 20:41:57 +08:00
# to match.
if { [is_bad_symtab] } then {
setup_xfail "*-*-*"
2012-03-13 08:41:22 +08:00
}
2007-05-15 12:23:50 +08:00
run_dump_test "localize-hidden-1"
2009-07-17 05:10:49 +08:00
run_dump_test "testranges"
run_dump_test "testranges-ia64"
2010-01-20 08:09:13 +08:00
run_dump_test "add-section"
2015-10-21 22:16:35 +08:00
run_dump_test "add-symbol"
2010-01-20 08:09:13 +08:00
run_dump_test "add-empty-section"
2010-05-18 11:31:07 +08:00
run_dump_test "exclude-1a"
run_dump_test "exclude-1b"
2015-08-24 20:02:39 +08:00
run_dump_test "only-section-01"
run_dump_test "remove-section-01"
objcopy/strip: Add option --remove-relocations=SECTIONPATTERN
The objcopy and strip tools make use of the bfd library to manipulate
the state of the input file (to produce an output file). Within the
input file (for ELF at least), relocations are held within a section,
and so, if the user wanted to remove the relocations, but keep the
section to which the relocations would have been applied, it is tempting
to think that specifying the name of a relocation section to objcopy's
--remove-section option might do what you want, for example:
objcopy --remove-section=.rela.text input.elf output.elf
However, this does not work. The reason is that when the input file is
loaded, relocations are not managed as sections, but are, instead,
loaded as data associated with the section to which the relocations
would be applied. In our example above the relocations in '.rela.text'
are held as data on the section '.text' once 'input.elf' is loaded.
One task that objcopy and strip do is copy the relocations from the
input file to the output file if the section is also being copied from
the input file to the output file.
This commit adds a new command line option for objcopy and strip,
--remove-relocations, which can be used to remove the relocations, while
keeping the section that the relocations would have been applied to, for
example:
objcopy --remove-relocations=.text input.elf output.elf
in this case the section '.text' will appear in both 'input.elf' and
'output.elf', but any relocations in 'input.elf' that apply to '.text'
will not be present in 'output.elf'.
I have also added a special case to the handling of --remove-section
that spots if a user tries to remove a relocation section (currently
this is done by spotting the '.rela.' or '.rel.' prefix) and forwards
the request to --remove-relocations.
As with --remove-section and --only-section the --remove-relocations
option supports the '!' prefix on the section-patterns it takes to allow
for sections to be specifically not matched.
There are tests for all the new functionality.
binutils/ChangeLog:
* doc/binutils.texi (objcopy): Document 'remove-relocations'.
(strip): Likewise.
* objcopy.c (SECTION_CONTEXT_REMOVE_RELOCS): Define.
(enum command_line_switch): Add 'OPTION_REMOVE_RELOCS'.
(struct option strip_options): Add 'remove-relocations'.
(struct option copy_options): Likewise.
(copy_usage): Likewise.
(strip_usage): Likewise.
(handle_remove_relocations_option): New function.
(discard_relocations): New function.
(handle_remove_section_option): New function.
(copy_relocations_in_section): Use discard_relocations.
(strip_main): Use handle_remove_section_option for
'remove-section', and handle 'remove-relocations' option.
(copy_main): Likewise.
* testsuite/binutils-all/objcopy.exp: Run new tests.
* testsuite/binutils-all/remove-relocs-01.d: New file.
* testsuite/binutils-all/remove-relocs-01.s: New file.
* testsuite/binutils-all/remove-relocs-02.d: New file.
* testsuite/binutils-all/remove-relocs-03.d: New file.
* testsuite/binutils-all/remove-relocs-04.d: New file.
* testsuite/binutils-all/remove-relocs-05.d: New file.
* testsuite/binutils-all/remove-relocs-06.d: New file.
2015-08-22 03:08:26 +08:00
2019-11-02 05:47:55 +08:00
run_dump_test "keep-section-1"
run_dump_test "keep-section-2"
objcopy/strip: Add option --remove-relocations=SECTIONPATTERN
The objcopy and strip tools make use of the bfd library to manipulate
the state of the input file (to produce an output file). Within the
input file (for ELF at least), relocations are held within a section,
and so, if the user wanted to remove the relocations, but keep the
section to which the relocations would have been applied, it is tempting
to think that specifying the name of a relocation section to objcopy's
--remove-section option might do what you want, for example:
objcopy --remove-section=.rela.text input.elf output.elf
However, this does not work. The reason is that when the input file is
loaded, relocations are not managed as sections, but are, instead,
loaded as data associated with the section to which the relocations
would be applied. In our example above the relocations in '.rela.text'
are held as data on the section '.text' once 'input.elf' is loaded.
One task that objcopy and strip do is copy the relocations from the
input file to the output file if the section is also being copied from
the input file to the output file.
This commit adds a new command line option for objcopy and strip,
--remove-relocations, which can be used to remove the relocations, while
keeping the section that the relocations would have been applied to, for
example:
objcopy --remove-relocations=.text input.elf output.elf
in this case the section '.text' will appear in both 'input.elf' and
'output.elf', but any relocations in 'input.elf' that apply to '.text'
will not be present in 'output.elf'.
I have also added a special case to the handling of --remove-section
that spots if a user tries to remove a relocation section (currently
this is done by spotting the '.rela.' or '.rel.' prefix) and forwards
the request to --remove-relocations.
As with --remove-section and --only-section the --remove-relocations
option supports the '!' prefix on the section-patterns it takes to allow
for sections to be specifically not matched.
There are tests for all the new functionality.
binutils/ChangeLog:
* doc/binutils.texi (objcopy): Document 'remove-relocations'.
(strip): Likewise.
* objcopy.c (SECTION_CONTEXT_REMOVE_RELOCS): Define.
(enum command_line_switch): Add 'OPTION_REMOVE_RELOCS'.
(struct option strip_options): Add 'remove-relocations'.
(struct option copy_options): Likewise.
(copy_usage): Likewise.
(strip_usage): Likewise.
(handle_remove_relocations_option): New function.
(discard_relocations): New function.
(handle_remove_section_option): New function.
(copy_relocations_in_section): Use discard_relocations.
(strip_main): Use handle_remove_section_option for
'remove-section', and handle 'remove-relocations' option.
(copy_main): Likewise.
* testsuite/binutils-all/objcopy.exp: Run new tests.
* testsuite/binutils-all/remove-relocs-01.d: New file.
* testsuite/binutils-all/remove-relocs-01.s: New file.
* testsuite/binutils-all/remove-relocs-02.d: New file.
* testsuite/binutils-all/remove-relocs-03.d: New file.
* testsuite/binutils-all/remove-relocs-04.d: New file.
* testsuite/binutils-all/remove-relocs-05.d: New file.
* testsuite/binutils-all/remove-relocs-06.d: New file.
2015-08-22 03:08:26 +08:00
# Test the remove relocation functionality
set test_list [lsort [glob -nocomplain $srcdir/$subdir/remove-relocs-*.d]]
foreach t $test_list {
# We need to strip the ".d", but can leave the dirname.
verbose [file rootname $t]
run_dump_test [file rootname $t]
}
2007-04-24 18:56:58 +08:00
}
2007-05-15 12:23:50 +08:00
run_dump_test "localize-hidden-2"
2016-02-02 19:30:21 +08:00
# Test objcopying an object file without global symbol
proc objcopy_test_without_global_symbol { } {
global OBJCOPY
global OBJCOPYFLAGS
global OBJDUMP
global OBJDUMPFLAGS
global srcdir
global subdir
set test "strip without global symbol "
if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object debug] != "" } {
untested $test
return
}
if [is_remote host] {
set objfile [remote_download host tmpdir/pr19547.o]
} else {
set objfile tmpdir/pr19547.o
}
set exec_output [binutils_run $OBJCOPY "$OBJCOPYFLAGS --strip-unneeded $objfile"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2016-02-02 19:30:21 +08:00
if ![string equal "" $exec_output] {
fail $test
return
}
set exec_output [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $objfile"]
2018-08-23 21:12:37 +08:00
set exec_output [prune_warnings $exec_output]
2016-02-02 19:30:21 +08:00
if {![regexp "no symbols" $exec_output]} {
fail $test
return
}
pass $test
}
2016-07-01 17:32:45 +08:00
# The AArch64 and ARM targets preserve mapping symbols
# in object files, so they will fail this test.
setup_xfail aarch64*-*-* arm*-*-*
2016-02-02 19:30:21 +08:00
objcopy_test_without_global_symbol
2018-09-10 10:27:08 +08:00
# objcopy remove relocation from executable test
proc objcopy_remove_relocations_from_executable { } {
global OBJCOPY
global srcdir
global subdir
global READELF
set test "remove-section relocation sections"
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/pr23611 executable debug] != "" } {
untested $test
return
}
if [is_remote host] {
set objfile [remote_download host tmpdir/pr23611]
} else {
set objfile tmpdir/pr23611
}
set out tmpdir/pr23611.out
set exec_output1 [binutils_run $OBJCOPY "-R .rela.plt -R .rela.dyn -R .rel.plt -R .rel.dyn $objfile $out"]
2021-08-19 11:45:06 +08:00
set exec_output1 [prune_warnings $exec_output1]
if ![string equal "" $exec_output1] {
fail $test
return
}
2018-09-10 10:27:08 +08:00
set exec_output2 [binutils_run $READELF "-S $out"]
if { [string match "*.rel.plt*" $exec_output2] || [string match "*.rela.plt*" $exec_output2] || [string match "*.rel.dyn*" $exec_output2] || [string match "*.rela.dyn*" $exec_output2] } {
fail $test
return
}
pass $test
}
2021-08-19 11:45:06 +08:00
if [is_elf_format] {
objcopy_remove_relocations_from_executable
}
2018-09-14 00:09:00 +08:00
run_dump_test "pr23633"
2019-10-02 18:55:02 +08:00
run_dump_test "set-section-alignment"
2020-03-27 18:54:26 +08:00
2020-03-28 07:58:03 +08:00
setup_xfail "hppa*-*-*"
setup_xfail "sh-*-coff*"
2020-03-28 12:01:02 +08:00
setup_xfail "spu-*-*"
2020-03-28 07:58:03 +08:00
clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"
2020-03-28 12:01:02 +08:00
clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "hppa*-*-*elf*"
2020-06-05 14:41:57 +08:00
if { [istarget pdp11-*-*] } {
set src "pr25662-pdp11.s"
} else {
set src "pr25662.s"
}
2020-09-09 01:01:45 +08:00
set ldflags "-T$srcdir/$subdir/pr25662.ld"
if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } {
append ldflags " --disable-reloc-section"
}
2020-07-07 08:53:06 +08:00
#xcoff doesn't support arbitrary sections
if { ![is_xcoff_format] } {
2020-09-09 01:01:45 +08:00
objcopy_test "pr25662" $src executable "" $ldflags
2020-07-07 08:53:06 +08:00
}