This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] -O binary: do not align physical addresses
ClosedPublic

Authored by quic-akaryaki on May 10 2023, 8:52 AM.

Details

Summary

llvm-objcopy should not insert padding before a section if its
physical addresses is not aligned to section's alignment. This
behavior will match GNU objcopy and is important for embedded images
where the physical address is used to store the initial data image.
The loader typically will copy this image using a start symbol
created by the linker. If llvm-objcopy inserts padding before such a
section, the symbol address will not match the location in the image.

This commit refines the change in https://reviews.llvm.org/D128961
which intended to align sections which type changed from NOBITS and
their offset may not be aligned. However, it affected all sections.

Fix https://github.com/llvm/llvm-project/issues/62636

Diff Detail

Event Timeline

quic-akaryaki created this revision.May 10 2023, 8:52 AM
quic-akaryaki requested review of this revision.May 10 2023, 8:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 8:52 AM
quic-akaryaki edited the summary of this revision. (Show Details)
apazos added a subscriber: apazos.Jun 12 2023, 10:14 AM

Hello @MaskRay and @jhenderson - Can you help review this change? This looks like a bug and lack of compatibility with GNU tools.

MaskRay accepted this revision.Jun 12 2023, 6:59 PM

Your commit message has 4-space indentation. Please remove that. git log -1 --pretty=%B messages don't usually have indentation.

This issue causes the Differential summary to be rendered like a Markdown code block.

https://github.com/llvm/llvm-project/issues/62636

Fix https://github.com/llvm/llvm-project/issues/62636

llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
292

Add a comment.

## PAddr is not aligned by sh_addralign(.data).

309

Delete the symbols. They are unrelated to the test.

This revision is now accepted and ready to land.Jun 12 2023, 6:59 PM

is important for embedded images where the physical address is used to store the initial data image. The loader typically will copy this image using a start symbol created by the linker. If llvm-objcopy inserts padding before such a section, the symbol address will not match the location in the image.

Thank you. I don't have much experience with p_paddr. Unaligned p_offset seems a bit strange but I see that it may be used this way...

Apologies for not looking at this - I've had a pretty busy few weeks.

quic-akaryaki edited the summary of this revision. (Show Details)

Fixed the commit message, removed symbols from the test, and added a comment. Thanks, MaskRay.

quic-akaryaki marked 2 inline comments as done.Jun 13 2023, 9:28 AM
MaskRay accepted this revision.Jun 13 2023, 10:03 AM

LGTM, will be great to have a sign-up from @jhenderson

llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
258

I think the comment can be simplified.

" The loader typically will copy this image using a start symbol created by the linker. Since copying is
done by memcpy, the source alignment is not important but the symbol
address must match the initial image location." seems unnecessary to me.

Perhaps just use this:

Without converting the type of a NOBITS section, don't align the offset.
This matches GNU objcopy when the physical address of a section is not aligned.

310

Delete the trailing blank line.

jhenderson accepted this revision.Jun 14 2023, 1:30 AM

I'm not too familiar with the -O binary option and its use-cases, but the change seems reasonable to me. I'm happy to defer to @MaskRay.

quic-akaryaki marked 2 inline comments as done.Jun 15 2023, 3:00 PM
MaskRay accepted this revision.Jun 15 2023, 3:05 PM

Please someone on this review with commit rights commit this change. I don't see outstanding items to complete. Thank you!

Please someone on this review with commit rights commit this change. I don't see outstanding items to complete. Thank you!

Sure! Which git commit --amend --author=... command shall I use for this patch to give you credits?

@MaskRay --author="Alexey Karyakin <akaryaki@quicinc.com>" is fine. Thank you!

This revision was automatically updated to reflect the committed changes.

Fix the endianness issue, which broke big endian PPC tests.

quic-akaryaki reopened this revision.Jun 20 2023, 3:31 PM
This revision is now accepted and ready to land.Jun 20 2023, 3:31 PM
This revision was landed with ongoing or failed builds.Jun 20 2023, 3:46 PM
This revision was automatically updated to reflect the committed changes.