Repository navigation
fix(size): count only sections with contents as flash (#2012) - #2021
Merged
Merged
Conversation
The shared size report ran the toolchain's `size` tool in Berkeley format and parsed `text + data` as flash. GNU `size` files every read-only ALLOC section under `text`, including SHT_NOBITS ones, so Arduino-Pico's read-only NOLOAD `.heap` (252,216 bytes on RP2040, 513,528 on RP2350) was reported as flash: an empty Pico sketch showed 334,608 bytes against an 82,392-byte firmware.bin. LinkerBase::report_size now reads the ELF section headers directly and classifies them with the new SizeInfo::from_elf_sections: Berkeley rules, except that a SHT_NOBITS section is never text. A writable NOBITS section is still bss; a read-only NOBITS reservation is neither flash nor static RAM (Berkeley never counted it as RAM either). Flash is therefore exactly the bytes of every allocated section with contents, and the RAM figure is unchanged on every platform. All other sections classify exactly as before, so non-RP2040 numbers do not move. Fixes #2012
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
#2012) Move-only: ElfSectionSize and SizeInfo::from_elf_sections (fbuild-core) and read_elf_section_sizes (fbuild-build-engine), together with their tests, are moved into new elf_size modules, so neither lib.rs nor linker.rs goes over the 1000-line file limit. No behaviour change.
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
LinkerBase::report_sizeran the toolchainsizetool (Berkeley format) and reportedtext + dataas flash. GNUsizeputs every read-onlySHF_ALLOCsection undertext, includingSHT_NOBITSones. Arduino-Pico's linker script leaves the NOLOAD.heapreservation read-only, so its 252,216 bytes (513,528 on RP2350) were counted as flash. An empty Pico sketch reportedflash: 334608 bytesagainst an 82,392-bytefirmware.bin.Fix
fbuild-core: newElfSectionSizeandSizeInfo::from_elf_sections. It uses the Berkeley rules with one correction: aSHT_NOBITSsection is nevertext. Writable NOBITS is stillbss. A read-only NOBITS reservation counts as neither flash nor static RAM, and Berkeley never counted it as RAM either.fbuild-build-engine:LinkerBase::report_sizenow reads the ELF section headers directly (read_elf_section_sizes, viaobject) instead of spawningsize. It is now synchronous and no longer takes the size-tool path or label. The 9 callers (AVR, ESP8266, CH32V, generic ARM, nRF52, SAM, Silabs, Teensy, Renesas) were updated to match.Flash is now exactly the bytes of every allocated section with contents, which is the
firmware.binpayload. Every other section is classified exactly as Berkeley did, so non-RP2040 figures and all RAM figures stay the same.Out of scope: ESP32 has its own SysV
size -Aparser (fbuild-build-esp/src/esp32/size_report.rs), so this does not fix #2013. RP2040 RAM still uses Berkeley semantics, so.datais AX here and is not counted, while the flash-resident writable.ota/.partitionare. That is the existing behaviour, left unchanged on purpose and worth a follow-up.Tests
fbuild-core:size_info_from_elf_sections_excludes_nobits_from_flashuses the issue's exact section table. It was RED against Berkeley rules (334,608) and is GREEN now (82,392, RAM 19,360).size_info_from_elf_sections_matches_berkeley_for_classic_layoutchecks that the AVR-style layout is unchanged.fbuild-build-engine:report_size_does_not_count_read_only_nobits_heap_as_flashwrites a synthetic ELF with a read-only NOBITS.heap(tempfile +object::write).report_size_rejects_non_elfchecks that a non-ELF input returns an error.Validation
soldr cargo fmt --all --check: passedsoldr cargo clippy --workspace --all-targets -- -D warnings: passedbash test -p fbuild-core -p fbuild-build-engine -p fbuild-build-arm -p fbuild-build-mcu -p fbuild-build-esp: all passedboard_build.core = earlephilhower, which RP2040: default Arduino Mbed configuration enters Arduino-Pico backend and fails with ENOENT #1977 now requires):Flash: 326.77KB / 2.00MB (16.0%)…flash: 334608 bytes, ram: 19360 bytesFlash: 80.46KB / 2.00MB (3.9%)…flash: 82392 bytes, ram: 19360 bytes;firmware.binis 82,392 bytesFixes #2012