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

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 03:15:56 PDT 2019


MaskRay added a comment.

In D67090#1657187 <https://reviews.llvm.org/D67090#1657187>, @manojgupta wrote:

> Thanks for working on it. Have you tested if Linux perf can symbolize the perf traces using the split debug files especially with large binaries?
>
> Meanwhile, I'll try the patch on Chrome OS to verify that gdb and perf still work.


I've learned that @manojgupta actually has a different use case: symbolization without requiring access to the stripped binary. To support that use case, stripping program headers + simple section layout:

  +static uint64_t layoutSectionsForOnlyKeepDebug(Object &Obj, uint64_t Off) {
  +  uint32_t Index = 1;
  +  for (SectionBase &Sec : Obj.sections()) {
  +    Sec.Index = Index++;
  +    Sec.Offset = alignTo(Off, Sec.Align ? Sec.Align : 1);
  +    if (Sec.Type != SHT_NOBITS)
  +      Off = Sec.Offset + Sec.Size;
  +  }
  +  return Off;
  +}

cannot be used. We'll need a full-fledged layout algorithm that rewrites p_offset/p_filesz as well as sh_offset - much like the one used in lld/ELF/Writer.cpp (https://reviews.llvm.org/D67137). The problem will be conflicting sources of information.

@jakehehrlich may have a similar use case:

> We should certainly check perf. I'd also like to wait on this until Roland gets back in order for him to chime in since he had specific examples of use cases where program headers are required as I recall. Specifically the section virtual addresses are not sufficient in the arcane case of prelinking but prelinking isn't really something I know very much about.

I think going the program header rewriting route needs more thoughts. It should be a separate change. It is also fairly difficult to validate because an end-to-end test going through their symbolization pipeline is likely required.



================
Comment at: test/tools/llvm-objcopy/ELF/only-keep-debug.test:53
+    Flags:        [ SHF_ALLOC ]
+    Address:      0x480           # Ensure Address=Offset
+    Content:      01
----------------
jhenderson wrote:
> 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```
It works for the first section but not for subsequent sections which are in different PT_LOAD segments.

I want to teach yaml2obj to write section headers at the end so that the offsets will not change when we add/delete sections.


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