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.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Few nits/questions from me.
test/tools/llvm-objcopy/ELF/copy-after-strip-sections.test | ||
---|---|---|
24 | Is this field important? | |
29 | Do you need PAddr for this test? | |
tools/llvm-objcopy/ELF/Object.cpp | ||
1566 | size is a bit strange helper. I do not think it is common to use it instead of .size() call | |
tools/llvm-objcopy/ELF/Object.h | ||
234 | Up to you perhaps, but I would suggest to move it out to the constructor body. |
test/tools/llvm-objcopy/ELF/copy-after-strip-sections.test | ||
---|---|---|
24 | Not massively, no. But it does force the section to appear at offset 0x1000. I was originally going to check the contents, but I decided not to do that, so I can get rid of it and the Address below. | |
29 | It's not important. Most of our tests just have both. I can remove it and VAddr too, given the other changes. |
tools/llvm-objcopy/ELF/Object.cpp | ||
---|---|---|
1566 | The underlying container doesn't currently have a size() method. There are quite a few places in this file that seem to use this helper, so perhaps it should be a different change? |
tools/llvm-objcopy/ELF/Object.cpp | ||
---|---|---|
1566 | Oh, I thought it has. I have no objections then. |
tools/llvm-objcopy/ELF/Object.h | ||
---|---|---|
235 | Slightly simpler: ELFWriter(Object &Obj, Buffer &Buf, bool WSH) : Writer(Obj, Buf), WriteSectionHeaders(WSH && Obj.HadShdrs) {} |
Rebase and address comment.
Unfortunately, this build fails on Linux. Somehow MSVC is able to handle the incomplete type of Object in the ELFWriter constructor, whereas the version of GCC that I'm using doesn't. The Writer classes aren't really part of the Object interface, so I'm going to move them into a separate header.
Is this field important?