Skip to content

nRF52840: -flto breaks the Adafruit core's FreeRTOS port, offset out of range (2.5.51) #2016

Open

Description

@stevenmunn312-tech

Summary

fbuild 2.5.51 compiles and links the Adafruit nRF52 core with link-time optimisation. The core is not written for it: its FreeRTOS port has naked functions that load a symbol's address with ldr rN, =symbol, and when LTO emits the whole program as one unit the literal pool lands too far away for the load. A blink is small enough to link. Anything larger, here a five-line FastLED sketch, fails at link with offset out of range.

The core's own platform.txt does not use -flto, so the flag is fbuild's (crates/fbuild-build-arm/src/nrf52/configs/nrf52840.json, release profile). build_unflags = -flto in the environment makes the same project build.

Reproduce

platformio.ini, with FastLED 3.10.9 in lib/FastLED:

[env:nrf52840_dk]
platform = nordicnrf52
board = nrf52840_dk
framework = arduino

src/main.cpp:

#include <Arduino.h>
#include <FastLED.h>
CRGB leds[16];
void setup() { FastLED.addLeds<WS2812B, 5, GRB>(leds, 16); }
void loop() { fill_solid(leds, 16, CRGB::Red); FastLED.show(); delay(20); }
$ fbuild <project> build -e nrf52840_dk -v --no-timestamp
build error: build failed: arm-none-eabi-gcc link failed:
...\release\.lto-tmp\ccsIIHTD.s:8866: Error: offset out of range
...\release\.lto-tmp\ccsIIHTD.s:8895: Error: offset out of range
...\release\.lto-tmp\ccsIIHTD.s:8926: Error: offset out of range
lto-wrapper.exe: fatal error: ...\15.2.Rel1\bin\arm-none-eabi-gcc.exe returned 1 exit status

adafruit_feather_nrf52840 fails the same way.

The rejected lines

fbuild removes .lto-tmp after the failure. Running the same LTO code generation by hand over the objects fbuild left (arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Os -flto -flto-partition=one -save-temps -nostdlib -r) reproduces the three errors and keeps the assembly. The lines are:

vPortStartFirstTask:
	@ Naked Function: prologue and epilogue provided by programmer.
	 ldr r0, =__isr_vector
...
	   ldr r3, =pxCurrentTCB
...
   ldr r3, =pxCurrentTCB

All three are in the core's cores/nRF5/freertos/portable/GCC/nrf52/port.c (framework arduinoadafruitnrf52 1.10601.0), not in the sketch or FastLED.

Controls

  • A blink in the same project links, with LTO on: build succeeded in 12.0s (flash: 27856 bytes, ram: 235520 bytes).
  • The FastLED sketch with build_unflags = -flto added links: build succeeded in 53.4s (flash: 65568 bytes, ram: 235520 bytes), with no lto-wrapper line in the log.

Suggested fix

Do not default -flto on for nordicnrf52 with the Adafruit core, as the core's own build does not. nrf52/orchestrator.rs already removes it for the GCC 7 registry toolchain (without_release_lto); the same looks right for every toolchain.

Also noticed

The RAM figure is 235,520 bytes of 256 KB for a blink and for the FastLED sketch alike, so it is not the sketch's static RAM.

Environment

  • fbuild 2.5.51+git.9b26affea5ad, Windows 11. The failure was rebuilt on 2026-11-14; the hand run and the two controls are from 2026-11-12. Toolchain: arm-none-eabi-gcc 15.2.1 (Arm GNU Toolchain 15.2.Rel1).
  • First seen on a GitHub windows-latest runner (2026-11-11).
  • nrf52840.json is unchanged on main at 00bfaeb.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions