Skip to content

fix(size): count RAM by PlatformIO's SIZEDATAREGEXP section set (#2027) - #2052

Merged
zackees merged 2 commits into
mainfrom
fix/ram-excludes-reservations-2027
Nov 17, 2026
Merged

zackees merged 2 commits into
mainfrom
fix/ram-excludes-reservations-2027

Conversation

@zackees

@zackees zackees commented Nov 17, 2026

Copy link
Copy Markdown
Member

Fixes #2027. Part of #2035.

Problem

LinkerBase::report_size → SizeInfo::from_elf_sections counted every allocated writable section as RAM (writable with contents → data, writable SHT_NOBITS → bss). Flags can't tell static data from a heap or stack reservation, because both are writable NOBITS. The Adafruit nRF52 nrf52_common.ld grows a writable .heap up to __StackLimit, so every nRF52 sketch reported 235,520 bytes of RAM.

Rule chosen: PlatformIO's SIZEDATAREGEXP section set, by exact name

RAM is now the allocated sections whose names are in the platform's PlatformIO SIZEDATAREGEXP. Names match exactly, the way PlatformIO's anchored regex matches over size -A. Flash is unchanged: every allocated section with contents (#2012).

PlatformIO evidence (builder/main.py, develop branches):

PlatformIO platform SIZEDATAREGEXP fbuild set
atmelavr, atmelsam, nordicnrf51, nordicnrf52, raspberrypi (+ maxgerhardt fork), renesas-ra, siliconlabsefm32, ststm32, nxplpc ^(?:\.data|\.bss|\.noinit)\s+(\d+) fbuild_core::PLATFORMIO_RAM_SECTIONS (default)
teensy .usbdescriptortable|.dmabuffers|.usbbuffers|.data|.bss|.noinit|.text.itcm|.text.itcm.padding TEENSY_RAM_SECTIONS
espressif8266 .data|.rodata|.bss ESP8266_RAM_SECTIONS
ch32v .data|.bss|.noinit|.loadcode|.highcode|.stack CH32V_RAM_SECTIONS
espressif32 .dram0.data|.dram0.bss|.noinit unchanged (DRAM_SECTIONS, #2023)

I chose this over option (b), excluding known reservation names from the flag rule, for three reasons:

  • It matches PlatformIO exactly rather than approximately.
  • It doesn't depend on a deny-list. Each core names its reservations differently: .heap, ._user_heap_stack, .stack_dummy, .stack1_dummy, .vector_table, .fsp_dtc_vector_table, .ram_vector_table, ...
  • It also fixes the cases where flags are wrong in the other direction. RP2040's RAM-resident .data is flagged AX and was missed. Flash-resident writable sections (.ota, .partition, Teensy's .text.headers, .init_array, AVR .eeprom) were counted as RAM.

ESP32 already used this pattern (#2023). The second commit makes esp32_size_from_sections call the new shared SizeInfo::from_elf_sections_with_ram instead of its own copy of the loop. That commit is a refactor only, and the existing size_report_tests pin the ESP32 figures.

RAM before / after

E2E: clean FBUILD_DEV_MODE=1 fbuild build --clean of a blink sketch with the new CLI/daemon. "After" is the reported figure. "Before" applies the old flag rule to the same ELF's section headers; the old rule depends only on those headers.

board before after why
nrf52840_dk (Adafruit) 235,520 8,584 writable .heap (226,936) dropped
uno 9 9 unchanged
pico (earlephilhower) 19,396 9,788 .data (AX) now counted; .ota, .partition, .ram_vector_table, .stack1_dummy dropped (#2041's case)
bluepill_f103c8 2,792 1,252 ._user_heap_stack dropped
uno_r4_minima 13,612 4,140 .heap, .stack_dummy, .vector_table dropped
teensy41 22,976 14,064 RAM1 (.text.itcm + .data + .bss); flash .text.headers and DMAMEM .bss.dma no longer counted
esp8266 (nodemcuv2) 27,240 28,104 DRAM .rodata counted; .noinit not (PlatformIO espressif8266)
ch32v003 1,180 1,176 flash-resident writable .init_array (4 B) dropped; .stack kept

Real FastLED ELFs, same comparison: stm32f103c8 3,528 → 1,992; rp2040 20,824 → 9,844; teensy41 27,104 → 38,336 (that build has 28,800 B of ITCM code, which PlatformIO counts and the flag rule missed); esp8266 27,792 → 28,684; uno/attiny85/nano_every unchanged.

The only deliberate change on AVR is that an EEMEM .eeprom section (EEPROM at 0x810000, writable with contents) no longer counts as RAM. Before this change it could trip AVR's fatal RAM overflow check.

Overflow guards

  • ram_overflow_is_fatal is true only for AVR. AVR's figure (.data + .bss + .noinit) is unchanged apart from .eeprom, so its fatal check still sees the same RAM.
  • STM32 ._user_heap_stack is placed > RAM, and the Adafruit nRF52 script ASSERTs __StackLimit >= __HeapLimit. In both cases ld itself fails the link when the heap/stack reservation doesn't fit (the existing link_overflow enrichment reports it). fbuild's static-RAM figure is not the guard, so dropping the reservation from it removes no check. PlatformIO's figure works the same way.

Cache versioning

No version bump was needed:

  • Non-ESP platforms read the ELF on every report_size. There is no per-ELF size cache.
  • The no-op fast path's persisted size_info is keyed by stable_hash_with_build_config. Since fix(build): key the no-op fingerprint on the fbuild build identity (#2036) #2046 that hash includes the fbuild build identity (version + commit), which every orchestrator uses, so any new fbuild build misses it and recomputes the size.
  • ESP32's SIZE_REPORT_VERSION cache is unaffected because its classification is unchanged.

I tried bumping BUILD_FINGERPRINT_VERSION. It also invalidates ESP32's firmware.bin caches and collides with SIZE_REPORT_VERSION's history, so I reverted it.

#2041

This rule also produces the PlatformIO figure for #2041's RP2040 case: .data (AX) is counted, and .ota/.partition are not. The existing RP2040 fixture test in fbuild-core now pins RAM at 9,736 (was 19,360). #2041 stays open for its own RP2040 tests.

Tests

  • fbuild-core/src/elf_size.rs: nRF52 (issue table: .data 820 + .bss 17,844, .heap 216,856 → 18,664), STM32 ._user_heap_stack, RP2040, Renesas fsp.ld, AVR unchanged, AVR .eeprom, exact-name matching with an explicit set, unallocated sections ignored.
  • fbuild-build-engine/src/elf_size.rs: a real ELF written with object that has a writable NOBITS .heap, sized through LinkerBase::report_size and report_size_with_ram.
  • Platform sets: Teensy 4.1 (real section table), Teensy 3 buffers, ESP8266 (real table), CH32V003 (real table).

Validation

  • soldr cargo fmt --all
  • soldr cargo clippy --workspace --all-targets -- -D warnings
  • bash test -p for fbuild-core, fbuild-build-engine, fbuild-build-arm, fbuild-build-esp and fbuild-build-mcu
  • ci/run_dylint.py --package for the same five crates

All passed.

zackees and others added 2 commits November 17, 2026 02:37
RAM was every allocated writable section (writable contents -> data,
writable NOBITS -> bss). Flags cannot tell static data from a heap or
stack reservation, so Adafruit nRF52's writable `.heap`, which grows to
`__StackLimit`, made every sketch report 235,520 bytes of RAM.

RAM is now the allocated sections named in PlatformIO's SIZEDATAREGEXP
for the platform, matched by exact name, as PlatformIO's anchored regex
over `size -A` does:

- default (atmelavr, atmelsam, nordicnrf51/52, raspberrypi, renesas-ra,
  siliconlabsefm32, ststm32, nxplpc): .data .bss .noinit
  (fbuild_core::PLATFORMIO_RAM_SECTIONS)
- teensy: + .usbdescriptortable .dmabuffers .usbbuffers .text.itcm
  .text.itcm.padding
- espressif8266: .data .rodata .bss
- ch32v: + .loadcode .highcode .stack

Flash is unchanged: every allocated section with contents.

Effect on real section tables: nRF52 235,520 -> 8,584 for a blink;
STM32 drops `._user_heap_stack`; Renesas drops .heap/.stack_dummy/
.vector_table; RP2040 counts the AX `.data` and drops .ota/.partition/
.ram_vector_table/.stack1_dummy (#2041's case); Teensy 4.1 counts RAM1
(ITCM + .data + .bss) instead of the flash `.text.headers` and DMAMEM
`.bss.dma`; ESP8266 counts DRAM `.rodata` instead of `.noinit`; AVR
stops counting EEMEM `.eeprom` (EEPROM, not SRAM) and is otherwise
unchanged; CH32V stops counting the flash-resident writable
`.init_array` (4 bytes) and is otherwise unchanged. The linker
scripts' own `> RAM` regions and ASSERTs still fail a link whose
heap/stack reservation does not fit.

Fixes #2027

Co-Authored-By: Claude <[email protected]>
esp32_size_from_sections repeated the generic classifier: flash from
every allocated section with contents, RAM from DRAM_SECTIONS by exact
name, text = flash - data. Call SizeInfo::from_elf_sections_with_ram
with DRAM_SECTIONS instead. No behaviour change; the existing
size_report_tests pin the figures.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees
zackees added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 87db92c Nov 17, 2026
56 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

nRF52 size report counts the .heap reservation as RAM (235,520 bytes for every sketch)

1 participant