Repository navigation
fix(nrf52): don't enable LTO for the Adafruit core (#2016) - #2028
Merged
Merged
Conversation
The nrf52840 release profile compiled and linked with -flto. The Adafruit nRF52 core's FreeRTOS port (cores/nRF5/freertos/portable/GCC/ nrf52/port.c) loads symbol addresses with `ldr rN, =symbol` in naked functions. When LTO emits the program as one unit, the literal pool lands out of range and the assembler fails with `offset out of range`. A blink fits; a FastLED sketch does not. The core's own platform.txt never uses -flto. LTO was not added for a size reason. It came from the bulk "add board support" commit (768e446), which reused the ARM release template, and -Wl,--undefined=vTaskSwitchContext was added later (37a29b2) only to stop LTO discarding a symbol that the port's inline asm references. - Drop -flto, -fno-fat-lto-objects, -fuse-linker-plugin and the LTO-only --undefined=vTaskSwitchContext from the release profile. - Delete the GCC 7-only LTO strip (for_registry_toolchain, is_gcc7_registry_toolchain, without_release_lto, without_flags). It is dead now that no toolchain gets LTO. - Test: no nrf52 profile enables LTO, and the resolved compile flags carry no -flto. Fixes #2016 Co-authored-by: Claude <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This was referenced Nov 16, 2026
Closed
This was referenced Nov 17, 2026
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.
Root cause
crates/fbuild-build-arm/src/nrf52/configs/nrf52840.jsoncompiled and linked the release profile with-flto -fno-fat-lto-objects/-flto -fuse-linker-plugin. The Adafruit nRF52 core's FreeRTOS port (cores/nRF5/freertos/portable/GCC/nrf52/port.c) has naked functions that load addresses withldr rN, =symbol. When LTO emits the whole program as one unit, the literal pool lands out of range, and the assembler rejects it withoffset out of range. A blink is small enough to link; a FastLED sketch is not. The core's ownplatform.txtnever uses-flto.Why
-fltowas there: not for size. It arrived in the bulk "add board support" commit (768e446), which reused fbuild's ARM release template.-Wl,--undefined=vTaskSwitchContextwas added later (37a29b2) only to stop LTO discarding a symbol that the port's inline asm calls. In #1515 the GCC 7 registry toolchain hit the sameoffset out of rangeerror, and the fix stripped LTO for that one toolchain (without_release_lto). GCC 15 has the same problem once the program is large enough.Fix
--undefined=vTaskSwitchContext. Without LTO, the inline asm'sbl vTaskSwitchContextis a real relocation, so--gc-sectionskeeps the symbol.for_registry_toolchain,is_gcc7_registry_toolchain,without_release_lto,without_flags) and its test.nrf52840.jsonis the only nrf52 config. nrf52832 boards are rejected byget_nrf52_config_for_mcu, and thenordicnrf52orchestrator only builds the Adafruit core, so no other framework shares these flags.Trade-off: flash grows without LTO. On a clean blink it goes from 27,856 to 47,308 bytes, which matches what the core's own (non-LTO) build produces. A firmware that links is worth more than a smaller one that fails at random sizes.
Tests
nrf52::mcu_config::tests::no_profile_enables_lto_by_default: no profile of any supported nrf52 MCU carries*lto*or-fuse-linker-plugin.nrf52_compiler::tests::test_common_flags_contain_optimizationnow asserts the resolved compile flags contain no-flto.Validation
soldr cargo fmt --all -- --check: cleansoldr cargo clippy --workspace --all-targets -- -D warnings: cleanbash test -p fbuild-build-arm: 284 passed, 0 failed, 2 ignoredEnd-to-end (Linux,
FBUILD_DEV_MODE=1, nrf52840_dk, toolchain arm-none-eabi-gcc 15.2.Rel1, FastLED from local checkout inlib/FastLED).lto-tmp/*.s:8860/8889/8920: Error: offset out of rangelto-wrapperRAM figure ("Also noticed")
ram: 235520is.data + .bss + .heap. The Adafruit linker script's.heapis a writable NOBITS section that grows to__StackLimit. In the FastLED build:.data820,.bss17,844,.heap216,856. The genericSizeInfo::from_elf_sectionscounts all writable NOBITS sections as RAM. Changing that is cross-platform, so it is tracked separately in #2027.Fixes #2016