[PATCH] D67090: [llvm-objcopy][llvm-strip] Support --only-keep-debug

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 02:02:08 PDT 2019


jhenderson added a comment.

You'll need to update the llvm-objcopy and llvm-strip documentation too, since the --only-keep-debug switch is currently listed as "COFF specific".



================
Comment at: test/tools/llvm-objcopy/ELF/only-keep-debug.test:53
+    Flags:        [ SHF_ALLOC ]
+    Address:      0x480           # Ensure Address=Offset
+    Content:      01
----------------
Not sure if it works in this situation, but a trick I've used on a number of occasions is to set AddressAlign to some nice round number. yaml2obj then aligns the section offset in the file accordingly, and it's much less likely that the address looks like just a random number.

For example:

```- Name: .note
    Address: 0x400
    AddressAlign: 0x400```


================
Comment at: tools/llvm-objcopy/ELF/Object.cpp:1767
+    // may be taken by subsequent non-ALLOC sections.
+    if (Sec.ParentSegment == nullptr || !(Sec.Flags & SHF_ALLOC))
       Sec.accept(*SecWriter);
----------------
MaskRay wrote:
> jakehehrlich wrote:
> > @jhenderson I seem to recall you had a tricky non-allocated data in a segment case. Is this still kosher? Perhaps in that case the sections can write themselves and we don't have to worry about the interstitial data?
> preserve-segment-contents.test is the tricky test. For the new approach for --only-keep-debug, program headers are deleted and sections' sh_offset are rewritten, `writeSegmentData` should not be called.
My feeling is that with --only-keep-debug we don't need to do the segment content preservation. The examples I had were a) the section headers were stripped, leaving data in the segments, and b) arbitrary data written to gaps between sections in a segment (e.g. padding bytes). I think in both cases, they are not going to be to do with debugging, so --only-keep-debug can ignore it.

In the case of a section within a segment that is non-alloc, we'd need to write the data still, if we want to strictly conform to what GNU objcopy does (I do slightly question some of the decisions it makes though - why keep NOTEs and arbitrary non-debug PROGBITS sections for example?). An obvious example of this is non-alloc SHT_NOTE sections, but I have seen other examples of non-NOTE sections inside program headers before (particularly platform-specific program headers). However, in every case I know of (aside from the NOTE sections), there's no reason to keep that data.

Anyway, my understanding of the latest version of the code is that sections in segments will still have their data written, so much of this is moot.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67090/new/

https://reviews.llvm.org/D67090





More information about the llvm-commits mailing list