[SOL] Set max page size for program header alignment #118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The LLVM PR anza-xyz/llvm-project#129 changed the
defaultMaxPageSize
for the SBF target to 8. This number is used for aligning sections and program headers. It decreases program size, specifically for SBPFv3.In SBPFv0, v1, v2, the compiler outputs correct binaries, but a further usage of
llvm-objcopy --strip-all
, included in thecargo-build-sbf
build pipeline utilizes the segments alignment for calculating the correct offset for the sections it shrinks. When we use the alignment 8, the virtual address and the offset will mismatch, causing the binary to be rejected by the loader.This is not a problem for SBPFv3, which allows section virtual addresses and offset to diverge.
Solution
I'll add
-z max-page-size=4096
as another linker argument when the SBPF version is not v3. This will cause the program header entry to be aligned at 4096 as it was before the anza-xyz/llvm-project#129 change. See:https://github.com/anza-xyz/llvm-project/blob/6b28be55793bd51260d7ec07c20de483f12383a6/lld/ELF/Writer.h#L28