Repository navigation
fix(size): count RAM by PlatformIO's SIZEDATAREGEXP section set (#2027) - #2052
Merged
Merged
Conversation
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]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This was referenced Nov 17, 2026
14 of 17 tasks
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.
Fixes #2027. Part of #2035.
Problem
LinkerBase::report_size→SizeInfo::from_elf_sectionscounted every allocated writable section as RAM (writable with contents →data, writableSHT_NOBITS→bss). Flags can't tell static data from a heap or stack reservation, because both are writable NOBITS. The Adafruit nRF52nrf52_common.ldgrows a writable.heapup to__StackLimit, so every nRF52 sketch reported 235,520 bytes of RAM.Rule chosen: PlatformIO's
SIZEDATAREGEXPsection set, by exact nameRAM is now the allocated sections whose names are in the platform's PlatformIO
SIZEDATAREGEXP. Names match exactly, the way PlatformIO's anchored regex matches oversize -A. Flash is unchanged: every allocated section with contents (#2012).PlatformIO evidence (
builder/main.py, develop branches):SIZEDATAREGEXP^(?:\.data|\.bss|\.noinit)\s+(\d+)fbuild_core::PLATFORMIO_RAM_SECTIONS(default).usbdescriptortable|.dmabuffers|.usbbuffers|.data|.bss|.noinit|.text.itcm|.text.itcm.paddingTEENSY_RAM_SECTIONS.data|.rodata|.bssESP8266_RAM_SECTIONS.data|.bss|.noinit|.loadcode|.highcode|.stackCH32V_RAM_SECTIONS.dram0.data|.dram0.bss|.noinitDRAM_SECTIONS, #2023)I chose this over option (b), excluding known reservation names from the flag rule, for three reasons:
.heap,._user_heap_stack,.stack_dummy,.stack1_dummy,.vector_table,.fsp_dtc_vector_table,.ram_vector_table, ....datais flaggedAXand 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_sectionscall the new sharedSizeInfo::from_elf_sections_with_raminstead of its own copy of the loop. That commit is a refactor only, and the existingsize_report_testspin the ESP32 figures.RAM before / after
E2E: clean
FBUILD_DEV_MODE=1 fbuild build --cleanof 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..heap(226,936) dropped.data(AX) now counted;.ota,.partition,.ram_vector_table,.stack1_dummydropped (#2041's case)._user_heap_stackdropped.heap,.stack_dummy,.vector_tabledropped.text.itcm+.data+.bss); flash.text.headersand DMAMEM.bss.dmano longer counted.rodatacounted;.noinitnot (PlatformIO espressif8266).init_array(4 B) dropped;.stackkeptReal 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.eepromsection (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_fatalistrueonly for AVR. AVR's figure (.data+.bss+.noinit) is unchanged apart from.eeprom, so its fatal check still sees the same RAM.._user_heap_stackis placed> RAM, and the Adafruit nRF52 scriptASSERTs__StackLimit >= __HeapLimit. In both caseslditself fails the link when the heap/stack reservation doesn't fit (the existinglink_overflowenrichment 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:
report_size. There is no per-ELF size cache.size_infois keyed bystable_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.SIZE_REPORT_VERSIONcache is unaffected because its classification is unchanged.I tried bumping
BUILD_FINGERPRINT_VERSION. It also invalidates ESP32's firmware.bin caches and collides withSIZE_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/.partitionare not. The existing RP2040 fixture test infbuild-corenow 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:.data820 +.bss17,844,.heap216,856 → 18,664), STM32._user_heap_stack, RP2040, Renesasfsp.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 withobjectthat has a writable NOBITS.heap, sized throughLinkerBase::report_sizeandreport_size_with_ram.Validation
soldr cargo fmt --allsoldr cargo clippy --workspace --all-targets -- -D warningsbash test -pfor fbuild-core, fbuild-build-engine, fbuild-build-arm, fbuild-build-esp and fbuild-build-mcuci/run_dylint.py --packagefor the same five cratesAll passed.