[llvm-objcopy][llvm-strip] Add switch to allow removing referenced sections
authorJames Henderson <jh7370@my.bristol.ac.uk>
Thu, 18 Apr 2019 09:13:30 +0000 (09:13 +0000)
committerJames Henderson <jh7370@my.bristol.ac.uk>
Thu, 18 Apr 2019 09:13:30 +0000 (09:13 +0000)
commit66a9d0f8c6c90d4235d23d190be5494f06763c57
tree3fd82196841a8e8156164207e55f37e3ff56e412
parent4c994120c7cfeb011d4811b9bbe81235295f34e1
[llvm-objcopy][llvm-strip] Add switch to allow removing referenced sections

llvm-objcopy currently emits an error if a section to be removed is
referenced by another section. This is a reasonable thing to do, but is
different to GNU objcopy. We should allow users who know what they are
doing to have a way to produce the invalid ELF. This change adds a new
switch --allow-broken-links to both llvm-strip and llvm-objcopy to do
precisely that. The corresponding sh_link field is then set to 0 instead
of an error being emitted.

I cannot use llvm-readelf/readobj to test the link fields because they
emit an error if any sections, like the .dynsym, cannot be properly
loaded.

Reviewed by: rupprecht, grimar

Differential Revision: https://reviews.llvm.org/D60324

llvm-svn: 358649
12 files changed:
llvm/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test
llvm/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test
llvm/test/tools/llvm-objcopy/ELF/remove-linked-section.test [new file with mode: 0644]
llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
llvm/tools/llvm-objcopy/CopyConfig.cpp
llvm/tools/llvm-objcopy/CopyConfig.h
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
llvm/tools/llvm-objcopy/ELF/Object.cpp
llvm/tools/llvm-objcopy/ELF/Object.h
llvm/tools/llvm-objcopy/ObjcopyOpts.td
llvm/tools/llvm-objcopy/StripOpts.td