[llvm-objcopy]Allow llvm-objcopy to be used on an ELF file with no section headers
authorJames Henderson <jh7370@my.bristol.ac.uk>
Tue, 2 Apr 2019 14:11:13 +0000 (14:11 +0000)
committerJames Henderson <jh7370@my.bristol.ac.uk>
Tue, 2 Apr 2019 14:11:13 +0000 (14:11 +0000)
commit38cb238f752cefe5fde8bf6cb73dacc3fec8f89d
tree44472d3158aeffed95ebcef7854b3c1ef93960ed
parent68ad5c34e076475cf5691ead29c1ae6515272b75
[llvm-objcopy]Allow llvm-objcopy to be used on an ELF file with no section headers

This patch fixes https://bugs.llvm.org/show_bug.cgi?id=41293 and
https://bugs.llvm.org/show_bug.cgi?id=41045. llvm-objcopy assumed that
it could always read a section header string table. This isn't the case
when the sections were previously all stripped, and the e_shstrndx field
was set to 0. This patch fixes this. It also fixes a double space in an
error message relating to this issue, and prevents llvm-objcopy from
adding extra space for non-existent section headers, meaning that
--strip-sections on the output of a previous --strip-sections run
produces identical output, simplifying the test.

Reviewed by: rupprecht, grimar

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

llvm-svn: 357475
llvm/test/tools/llvm-objcopy/ELF/copy-after-strip-sections.test [new file with mode: 0644]
llvm/tools/llvm-objcopy/ELF/Object.cpp
llvm/tools/llvm-objcopy/ELF/Object.h