qemu: Refactor Cortex-M and RISC-V linkerscripts. - #19522
#19522Open
agatti wants to merge 3 commits into
micropython:mastermicropython/micropython:masterfrom
agatti:qemu-linkerscript-refactoragatti/micropython:qemu-linkerscript-refactorCopy head branch name to clipboard
Open
qemu: Refactor Cortex-M and RISC-V linkerscripts.#19522agatti wants to merge 3 commits intomicropython:mastermicropython/micropython:masterfrom agatti:qemu-linkerscript-refactoragatti/micropython:qemu-linkerscript-refactorCopy head branch name to clipboard
agatti wants to merge 3 commits into
micropython:mastermicropython/micropython:masterfrom
agatti:qemu-linkerscript-refactoragatti/micropython:qemu-linkerscript-refactorCopy head branch name to clipboard
Conversation
This commit updates the QEMU port's makefile to preprocess a target's linkerscript through the C preprocessor first. That's required for a refactoring of the Arm Cortex-M and RISC-V targets' linkerscripts, as the linker does not allow the level of external customisation needed to generalise them the way it is required. Other ports are not affected, as the preprocessor will simply pass through its input without performing any modifications. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit extracts the parts in common across linkerscripts targeting Cortex-M processors after being made memory section-neutral, and adapts other linkerscripts to use the shared parts. All Cortex-M linkerscripts ended up having the same sections duplicated in their respective files, but with minimum changes. With these changes a new Cortex-M target can reuse all of the shared directives, so bring-up time is reduced. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit extracts the parts in common across linkerscripts targeting RISC-V processors for QEMU's VIRT target after being made register size independent, and adapts other linkerscripts to use the shared parts. All RISC-V linkerscripts present in this port ended up having the same sections duplicated in their respective files, but with minimum changes. With these changes a new RISC-V target can reuse all of the shared directives, so bring-up time is reduced. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
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
Sign up for free
to 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.
Summary
This PR extracts common directives found in linkerscripts targeting Cortex-M and RISC-V processors, and modifies affected linkerscripts in order to refer to the common directives rather than replicating them (even with very little modifications).
If additional targets will be added to QEMU that use those two processor families, then these changes should help in bringing the target up faster. In the case further flexibility is needed, more fine-grained directives reuse is still a possibility as the Makefile now unconditionally uses the C preprocessor to build the final linkerscript.
Testing
The test suite passed on all affected QEMU targets, along with them being built with usermodules support in the case of Cortex-M targets.
CI should also check some of this as well.
Trade-offs and Alternatives
Due to the limited external customisability of linkerscripts, the files have to go through the C preprocessor in order to build the final linkerscript. This had the side-effect of making the Makefile a bit more complex (an explicit rule to make the output directory had to be created), but I believe that's unavoidable in order to not let the linkerscript being recreated on each build.
I left the QEMU/SABRELITE linkerscript alone as there's extra directives in the
.textsection that need to be further looked at to see if they can be folded into the Cortex-M shared file (in which case it will be renamed toarm-common.ldor something along those lines).Generative AI
I did not use generative AI tools when creating this PR.