build(lto): enable link time optimization for F051#12
Open
dakejahl wants to merge 1 commit into
Open
Conversation
Compile and link the F051 firmware with -flto. The whole firmware is built in a single compiler invocation, so cross translation-unit inlining needs no other build changes, and it matters most on the cortex-m0 where call overhead is high and flash is tight. Scoped to F051 only for now (LTO_FLAGS_F051) rather than firmware-wide: F051 is the target that needs it, and keeping LTO off the other MCUs avoids widening the test surface while it is evaluated on hardware. Other targets can opt in with LTO_FLAGS_<MCU> := -flto. The filename string gets __attribute__((used)) so LTO cannot drop it from its section. A defensive CAN guard keeps LTO off any future DroneCAN F051 build (none exists today).
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
Compile and link the F051 firmware with
-flto. Scoped to F051 only viaLTO_FLAGS_F051; all other MCUs are unchanged (verified: G431 flash is unaffected apart from +4 B for theusedattribute below). Should merge after thevolatilePR so cross-TU inlining is safe.Problem
F051 is the most CPU-constrained target. Without LTO the compiler cannot inline across translation units, leaving call overhead in the hot commutation and PWM paths on the Cortex-M0.
Solution
Enable
-fltofor F051 only — the whole firmware is built in a single compiler invocation, so this needs no other build changes. Thefilenamestring gets__attribute__((used))so LTO does not drop it from its section. A defensive CAN guard keeps LTO off any future DroneCAN F051 build (none exists today).-O3, LTO inlining grows F051 flash from 22200 B (81%) to 26680 B (97.3%, 744 B free) on its own, while cutting RAM (3688 → 2824 B via dead-code elimination). It fits, but standalone headroom is thin. It does not overflow when combined with the other F051 PRs — measured: LTO + the RAM-functions PR is 26024 B (94.9%), and the full F051 stack including the flash-reclaim PRs (gate custom tune, drop the SysTick handler) lands at 24980 B (91%). The thin standalone margin is the thing to watch; keep the reclaim PRs in the stack. Given 97.3% on its own, consider treating this as risk:4.