[PATCH] D67090: [llvm-objcopy] Add a new file offset assignment algorithm and support --only-keep-debug

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 09:18:15 PDT 2019


MaskRay added a comment.

  [ 1] foo               PROGBITS        0000000000002000 002000 000004 00      0   0  0
  [ 2] bar               PROGBITS        0000000000002004 002004 000004 00      0   0  0

GNU objcopy (and this patch) can rewrite sh_offset to smaller addresses starting from 0x900 (assuming sizeof(ehdr)+sizeof(phdr) = 0x900)

  [ 1] foo               PROGBITS        0000000000002000 000900 000004 00      0   0  0
  [ 2] bar               PROGBITS        0000000000002004 000904 000004 00      0   0  0

If we think this behavior is too subtle, and want segments as immutable as possible (e.g. PR41005),
we can enable the new layout algorithm only when --only-keep-debug is specified. You can find more info in the description of D64906 <https://reviews.llvm.org/D64906>.
My feeling is that such optimization probably only makes sense in the linker. So, it is my mistake to implement it in llvm-objcopy.
(This process is still enlightening

To make things easier, we can diverge from GNU objcopy further:
let --only-keep-debug delete all sections except SHT_NOTE and .debug*, and also delete all segments.
Then we can use a very simple layout algorithm:

  off = 0
  for each note section sec
    off = alignTo(off, sec->align)
    off += sec->size
  for each debug section sec
    off = alignTo(off, sec->align)
    off += sec->size

If this scheme looks good, I'll check if debuggers are still happy without phdr and try fixing segment-shift.test with a simpler approach.


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