Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-objcopy] Add --gap-fill and --pad-to options #65515

Closed
wants to merge 2 commits into from

Conversation

quic-akaryaki
Copy link
Contributor

--gap-fill <value> fills the gaps between sections with a specified 8-bit value, instead of zero.
--pad-to <address> pads the output binary up to the specified load address, using the 8-bit value from --gap-fill or zero.

These options are only supported for ELF inputs and binary outputs.

`--gap-fill <value>` fills the gaps between sections with a specified
8-bit value, instead of zero.
`--pad-to <address>` pads the output binary up to the specified load
address, using the 8-bit value from `--gap-fill` or zero.

These options are only supported for ELF inputs and binary outputs.
@quic-akaryaki
Copy link
Contributor Author

This is an implementation of section padding with a more limited scope than was attempted in https://reviews.llvm.org/D67689.
Only binary outputs are supported, but ELF and IHEX are not. The main motivation for taking this approach was to support the clear use case of building padded ROM images without figuring all the murky details of the general ELF case.
After reviewing https://reviews.llvm.org/D67689, it seems the main problem was with how the section content is updated for padding. The SectionBase::OriginalData was modified, which is incorrect. However, I think the bigger problem is that there are multiple section types that represent their data differently (SectionBase::OriginalData, OwnedDataSection::Data, compressed sections, etc). In binutils, sections are represented uniformly and resizing them in one location is sufficient. I don't know if a similar simple solution is possible in llvm-objdump. Therefore, I think it would make sense to handle padding in the output stage.
I think which approach is better going forward ultimately depends on whether section padding is a valuable use case for ELF and IHEX outputs. I am not aware of such use cases, but suggestions are welcome. Talking about ROM images, it is possible in some platforms to directly flash an ihex. However, since ihex contains addresses, it supports gaps naturally and does not have to store all the padding bytes. During the flashing, the gaps are skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant