rp2: Link with nano.specs, add linker cref table#19299
Open
projectgus wants to merge 2 commits into
Open
Conversation
Useful to see why particular symbols have been pulled in. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Reduces binary, static RAM, and (probably) runtime memory usage. Signed-off-by: Angus Gratton <angus@redyak.com.au>
|
Code size report: |
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
Passes
--specs=nano.specson the linker command line for rp2, meaning newlib-nano is used instead of regular newlib. As mentioned by @Gadgetoid in #11143. This reduces both the binary size and (significantly) the static RAM usage. Should also save some RAM at runtime, particularly the stack footprint of libc printf.Includes a commit to add the
--creflinker argument, which adds a cross-reference table in the linker map file. This is useful to figure out how/why certain symbols are linked.The specific libc pieces which are linked in the default rp2 build seem to be malloc/free/realloc and some printf support.
pico_utilqueue.c and time.c, and operator new & delete (unclear why these are pulled in at all!) Can find via__wrap_freein the cross-reference table. This feels like with a small amount of work it could be removed, maybe...? Particularly as the default rp2 build has no C heap available.shared/readline, andshared/netutils. Can find via__wrap_snprintfin the cross-reference table. This feels like it'd be harder to remove the dependency for.I don't think any of these use cases require "full" newlib support.
The best description I know for gcc specs and nano vs normal newlib is https://metebalci.com/blog/demystifying-arm-gnu-toolchain-specs-nano-and-nosys/
Testing
Trade-offs and Alternatives
Generative AI
I did not use generative AI tools when creating this PR.