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

[SOL] Set max page size for program header alignment #118

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

LucasSte
Copy link
Collaborator

@LucasSte LucasSte commented Mar 6, 2025

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 the cargo-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

@LucasSte LucasSte merged commit 88c5b91 into anza-xyz:solana-1.79.0 Mar 6, 2025
18 checks passed
@LucasSte LucasSte deleted the fix-linker branch March 6, 2025 20:32
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.

2 participants