py/py.mk: Build some core C files as single compilation units. #12714
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.
(Reviewing #12644 reminded me that I meant to try this experiment.)
Motivation
Building some source files as single compilation units allows the compiler to do some whole-of-source-file optimizations that aren't possible with
-fgc-sections
, or to emit slightly tighter assembly (even after linker relaxations are applied.)LTO provides very similar benefits, but is not enabled by default in most builds (and not possible at all for some ports like
esp32
).Method
Looking at the "Discarded input sections" of firmware.map for a build with
-fgc-sections
shows a lot of entries like this:From the above you can see that all symbols from
emitglue.o
were linked to the final binary, but bothpersistentcode.o
andruntime.o
contained symbols not referenced in the final binary that could be removed by the GC linker pass.Code Size
PYBV11 binary size (without cache):
py/
directory was built without-ffunction-sections -fdata-sections
Performance
Performance of this PR versus master (cache disabled):
Remaining Work
Currently this is a quick PoC based on PYBV11 only. If the approach seems worthwhile, the next step would be to identify more closely which core files are always 100% linked to the build (or linked depending on make-level options). And/or the cases where some functions can be
#ifdef
-ed out to make this true for a file.This work was funded through GitHub Sponsors.