[llvm-objcopy] -O binary: align sh_offset for section changed from SHT_NOBITS
authorFangrui Song <i@maskray.me>
Tue, 5 Jul 2022 04:45:19 +0000 (21:45 -0700)
committerFangrui Song <i@maskray.me>
Tue, 5 Jul 2022 04:45:19 +0000 (21:45 -0700)
commit0c01f42fad413163320c24ab4e513fbd282e4168
treec942eecacc004380a1bcdf037c823fafcc9d1566
parent3610d5f5d4c21d514e2a900620ed8260b0d25ad8
[llvm-objcopy] -O binary: align sh_offset for section changed from SHT_NOBITS

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

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D128961
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/test/tools/llvm-objcopy/ELF/binary-no-paddr.test
llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test