PR23611, objcopy is not removing executable relocatable sections
BFD handles ELF relocation sections in an executable differently to
relocation sections in a relocatable object. For a relocatable
object, BFD carries the relocations as data associated with the
section to which they apply; The relocation section doesn't appear as
a separate section. For an executable, dynamic relocation sections do
appear as separate sections. This means that objcopy needs to use
different strategies when dealing with relocations.
When --remove-relocations was added to objcopy with commit
d3e5f6c8f1
, objcopy lost the ability to remove dynamic relocation
sections such as .rela.plt from executables using the option
"--remove-section=.rela.plt". This patch reinstates that
functionality.
I thought it best to keep --remove-relocations as is, rather than
extending to handle dynamic relocations as per the patch in the PR,
because executables linked with --emit-relocs may have both dynamic
and non-dynamic relocations. In that case --remove-relocataions=* is
useful to remove all the non-dynamic relocations.
PR binutils/23611
* objcopy.c (handle_remove_section_option): Consider .rela and
.rel sections for stripping directly as well as attached to the
associated section they relocate.
* doc/binutils.texi (remove-relocations): Specify that this
option removes non-dynamic relocation sections.
* testsuite/binutils-all/objcopy.exp
(objcopy_remove_relocations_from_executable): New test.
This commit is contained in:
parent
78f8307c93
commit
f9853190c8
4 changed files with 59 additions and 14 deletions
|
@ -1223,3 +1223,36 @@ proc objcopy_test_without_global_symbol { } {
|
|||
setup_xfail aarch64*-*-* arm*-*-*
|
||||
|
||||
objcopy_test_without_global_symbol
|
||||
|
||||
# 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"]
|
||||
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
|
||||
}
|
||||
|
||||
objcopy_remove_relocations_from_executable
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue