[PATCH] D38335: [llvm-objcopy] Add support for --strip-sections to remove all section headers leaving only program headers and loadable segment data

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 05:29:13 PDT 2017


jhenderson added a comment.

In https://reviews.llvm.org/D38335#887684, @jakehehrlich wrote:

> An interesting option from there might be to implement a flag to toggle weather or not the section table is output from there. "llvm-objcopy --strip-sections" would then become equivalent to "llvm-objcopy --no-section-headers -R *" if we were implement globs for section names in section removal.


I would have no problem with this.



================
Comment at: test/tools/llvm-objcopy/strip-sections.test:1
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy --strip-sections %t %t2
----------------
jhenderson wrote:
> This test needs to test the ELF header fields as well.
For clarity, I mean the e_shnum, e_shoff, and e_shstrndx fields.


================
Comment at: tools/llvm-objcopy/Object.cpp:743
 
   Offset = alignTo(Offset, sizeof(typename ELFT::Addr));
   this->SHOffset = Offset;
----------------
We don't need to do this if there is no section header table.


================
Comment at: tools/llvm-objcopy/llvm-objcopy.cpp:79-86
+  SectionPred RemovePred = [](const SectionBase &) { return false; };
+
   if (!ToRemove.empty()) {
     Obj->removeSections([&](const SectionBase &Sec) {
       return std::find(std::begin(ToRemove), std::end(ToRemove), Sec.Name) !=
              std::end(ToRemove);
     });
----------------
It feels like there's a lot of overlap here. Would it be possible to fold the two cases together for this bit? I.e. the predicate becomes "if StripSections or in ToRemove list".


Repository:
  rL LLVM

https://reviews.llvm.org/D38335





More information about the llvm-commits mailing list