aboutsummaryrefslogtreecommitdiff
path: root/binutils/testsuite/binutils-all/objcopy.exp
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2015-08-21 20:08:26 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2016-07-14 11:34:10 +0100
commitd3e5f6c8f1e58e86689909019a3756d4308b66eb (patch)
tree9a3ca06fe702efd4d768389edb7c3074ec9af020 /binutils/testsuite/binutils-all/objcopy.exp
parente511c9b19faec4d21aef49d12224316dea3d51eb (diff)
downloadgdb-d3e5f6c8f1e58e86689909019a3756d4308b66eb.zip
gdb-d3e5f6c8f1e58e86689909019a3756d4308b66eb.tar.gz
gdb-d3e5f6c8f1e58e86689909019a3756d4308b66eb.tar.bz2
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.
Diffstat (limited to 'binutils/testsuite/binutils-all/objcopy.exp')
-rw-r--r--binutils/testsuite/binutils-all/objcopy.exp8
1 files changed, 8 insertions, 0 deletions
diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index be8a7d2..76d0b67 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -1121,6 +1121,14 @@ if [is_elf_format] {
run_dump_test "only-section-01"
run_dump_test "remove-section-01"
+
+ # 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]
+ }
}
run_dump_test "localize-hidden-2"