[PATCH] D39769: [llvm-objcopy] Add --strip-all option to remove all non-allocated sections but keep section header table

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 11:53:07 PST 2017


jakehehrlich added a comment.

In https://reviews.llvm.org/D39769#919087, @jhenderson wrote:

> I took a look at GNU objcopy's --strip-all behaviour and it is slightly different to what you have implemented here. I haven't been able to pin down the exact semantics yet, but I noticed that it kept the .comment section, for example. My suspicion is that it explicitly only strips the .debug and .symtab sections, along with the symbol string table, if it is not shared as the section header table.
>
> Otherwise, the code change looks fine to me.


My testing led me to think that it was just stripping non-allocated sections but you're right about .comment not being stripped; I didn't catch that. After a bunch more testing (using yaml2obj to generate various sections) the behavoir seems to be the following.

1. Remove relocation sections
2. Remove symbol table
3. Remove any section that starts with "debug_" (for instance all standard "debug_*" sections are removed but "debug_blarg" and "debug_foo" are also removed)

Everything else seems to be kept (.comment and .random_section_name are both kept for instance). In practice this only seems to differ for .comment but one can imagine this being an issue for other sorts of added information as well. --strip-all should most likely mirror this behavior for consistency sake I as well. I'll add this but I think I'll add --strip-non-allocated as well to do what this currently does.



================
Comment at: test/tools/llvm-objcopy/strip-all.test:1
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy --strip-all %t %t2
----------------
jhenderson wrote:
> This test should really have some other sections in it. What sections are actually being stripped here (I assume the symbol table is)? What about debug sections, which are also stripped by GNU objcopy --strip-all?
Debug sections aren't allocated so they'll be stripped. In this case .symtab, and .strtab are stripped but .shstrtab is not stripped. The maning behind this test was just to check that only the two allocated sections were kept and .shstrtab was kept since the section header table was kept. I could include more allocated and non-allocated sections I suppose but it seems a bit redundant. Now the fact that the .comment section is being kept is news to me, I'm not sure what rule I'm supposed to be following to make that happen.


Repository:
  rL LLVM

https://reviews.llvm.org/D39769





More information about the llvm-commits mailing list