old-cross-binutils/binutils/testsuite/binutils-all/update-section.exp
Alan Modra 9cc0123fea MIPS objcopy --rename-section fix
Some MIPS targets use a named section symbol rather than a symbol with
no name as is used with most ELF targets.  When renaming sections, the
named section symbol needs to be renamed too.

Rather than fix this bug, I'd originally intended to just correct the
xfail added recently for update-1.o vs update4.o in update-section.exp,
using the same set of targets for the localize-hidden-1 mips xfail.
I'd extracted that target test into a new function, is_bad_symtab.  It
turns out to be useful in readelf.exp too.

bfd/
	* config.bfd: Delete mips vxworks patterns matched earlier.
	Combine mips*-*-none with mips*-*-elf*.
binutils/
	* objcopy.c (find_section_rename): Forward declare.  Remove
	ibfd and sec_ptr param.  Add old_name param.  Allow for NULL
	returned_flags.  Move read of section name and flags to..
	(setup_section): ..here.  Update find_section_rename call.
	(filter_symbols): Rename section symbols for renamed sections.
	(copy_object): Call filter_symbols when renamed sections.
	* testsuite/lib/binutils-common.exp (is_bad_symtab): New.
	* testsuite/binutils-all/update-section.exp: Revert 96037eb0
	mips xfail.
	* testsuite/binutils-all/objcopy.exp (copy_executable): Use
	is_bad_symtab.
	(localize-hidden-1): xfail if is_bad_symtab.
	* testsuite/binutils-all/readelf.exp: Use is_bad_symtab to select
	between mips/tmips.
2016-06-24 23:26:29 +09:30

119 lines
3.5 KiB
Text

# Copyright (C) 2015-2016 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
if { [is_remote host] } then {
return
}
# These tests use ELF .section directives
if ![is_elf_format] {
return
}
send_user "Version [binutil_version $OBJCOPY]"
proc do_assemble {srcfile} {
global srcdir
global subdir
set objfile [regsub -- "\.s$" $srcfile ".o"]
if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/${objfile}]} then {
return 0;
}
return 1;
}
proc do_objcopy {objfile extraflags {pattern ""}} {
global OBJCOPY
global OBJCOPYFLAGS
set testname "objcopy $extraflags ${objfile}"
set got [binutils_run $OBJCOPY \
"$OBJCOPYFLAGS ${extraflags} tmpdir/${objfile}"]
if ![regexp $pattern $got] then {
fail "objcopy ($testname)"
return 0
}
if { $pattern != "" } then {
pass "objcopy ($testname)"
}
return 1
}
proc do_compare {file1 file2} {
set src1 "tmpdir/${file1}"
set src2 "tmpdir/${file2}"
set status [remote_exec build cmp "${src1} ${src2}"]
set exec_output [lindex $status 1]
set exec_output [prune_warnings $exec_output]
set testname "compare ${file1} ${file2}"
if [string match "" $exec_output] then {
pass "objcopy ($testname)"
} else {
send_log "$exec_output\n"
verbose "$exec_output" 1
fail "objcopy ($testname)"
return 0
}
return 1
}
#
# Start Of Tests
#
foreach f [list update-1.s update-2.s update-3.s update-4.s] {
if { ![do_assemble $f] } then {
unsupported "update-section.exp"
return
}
}
if { ![do_objcopy update-1.o \
"--dump-section .foo=tmpdir/dumped-contents"]
|| ![do_objcopy update-2.o \
"--update-section .foo=tmpdir/dumped-contents"]
|| ![do_objcopy update-3.o \
"--update-section .foo=tmpdir/dumped-contents"]
|| ![do_objcopy update-4.o \
"--update-section .bar=tmpdir/dumped-contents \
--rename-section .bar=.foo"] } then {
# If any of the above tests failed then a FAIL will already have
# been reported.
return
}
# Check that the updated object files are as expected.
do_compare update-1.o update-2.o
do_compare update-1.o update-3.o
do_compare update-1.o update-4.o
# Check that --update-section on an unknown section will fail.
if { ![do_objcopy update-2.o \
"--update-section .bar=tmpdir/dumped-contents" \
"error: .bar not found, can't be updated"] } then {
return
}
# Check that --update-section and --remove-section on the same section
# will fail.
if { ![do_objcopy update-2.o \
"--update-section .foo=tmpdir/dumped-contents \
--remove-section .foo" \
"error: section .foo matches both update and remove options"] \
} then {
return
}