forked fromzephyrproject-rtos/arduino-core-zephyr
Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34
misc: Implement two-pass linking to separate rodata sections.#245
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
iabdalkader wants to merge1 commit intoarduino:mainChoose a base branch fromiabdalkader:split_rodata
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This patch changes the build to perform two-pass linking to separate rodatawith relocations (copied to RAM) from rodata with no relocations (pure data)that can be kept in flash by llext.For dynamic linking mode:- First pass: Link with build-dynamic.ld to create temp ELF (unchanged).- Analyze the elf and extract, sort and write out the sections: - .rodata: sections WITH relocations → copied to RAM (LLEXT_MEM_RODATA) - .rodata_noreloc: sections WITHOUT relocations → kept in flash (LLEXT_MEM_RODATA_NO_RELOC)- Second pass: Link with generated rodata_split.ld + build-dynamic.ld.For static linking mode:- Generates empty rodata_split.ld (no section separation needed)Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
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.
Uh oh!
There was an error while loading.Please reload this page.
This patch changes the build to perform two-pass linking to separate rodata with relocations (copied to RAM) from rodata with no relocations (pure const data) that can be kept in flash by llext.
For dynamic linking mode:
For static linking mode:
Output from readelf on an example sketch that includes ~64KBs CA certs blob. Before the patch:
After:
Alternatives considered and tested:
This is by far the simplest and safest approach since it relies on the toolchain to do all the magic so we can trust it Not to break the elf. That said, I implemented and tested two more solutions:
1- Patch elf to set custom flags and/or section type: first attempt, using a custom Python/Go script, can set special section flags or section type, to mark rodata sections with no relocations, but this required more modifications to llext and using section attributes.
2- Reorder sections: using a custom Python/Go script, reorder elf sections such that all rodata with relocs come first (or last, doesn't matter). llext doesn't support non-contiguous regions, so if we just reorder them, plus my patch above, things work out. While this fixes the issue in one pass, it doesn't merge the sections, so final elf will have many rodata and rodata.noreloc sections. This can be fixed by merging the sections, but the relocations will have to be fixed. Doable, but tricky and risky.