This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] -O binary: align sh_offset for section changed from SHT_NOBITS
ClosedPublic

Authored by MaskRay on Jun 30 2022, 9:41 PM.

Details

Summary

For a SHT_NOBITS section like .bss, its sh_offset is typically not
aligned by sh_addralign. If it is converted to SHT_PROGBITS by
--set-section-flags .bss=alloc,contents, we should conceptually align
it when computing the output size for -O binary. Otherwise the output
size may be smaller than GNU objcopy produced output.

  • binary-no-paddr.test has a case with non-sensical p_paddr=1 which has a changed behavior. Update it.

Close https://github.com/llvm/llvm-project/issues/55246

Diff Detail

Event Timeline

MaskRay created this revision.Jun 30 2022, 9:41 PM
MaskRay requested review of this revision.Jun 30 2022, 9:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2022, 9:41 PM
MaskRay updated this revision to Diff 441585.Jun 30 2022, 9:42 PM

use -NEXT:

MaskRay added inline comments.Jun 30 2022, 9:44 PM
llvm/test/tools/llvm-objcopy/ELF/binary-no-paddr.test
9

WIll change to:

For the p_paddr=0 case: .text and .data are rewritten to the same place. The size is 4.

jhenderson accepted this revision.Jul 3 2022, 11:37 PM

LGTM, I think (took me a while to wrap my head around it, but the behaviour matches GNU, so that's a win in my book).

This revision is now accepted and ready to land.Jul 3 2022, 11:37 PM
This revision was landed with ongoing or failed builds.Jul 4 2022, 9:45 PM
This revision was automatically updated to reflect the committed changes.