Repository navigation
fix(esp32): size report from ELF section headers; drop .dram0.dummy from RAM and flash (#2013) - #2023
Merged
Merged
Conversation
The ESP32 size report needs section names (.dram0.data vs the .dram0.dummy placeholder) on top of the header flags. The shared reader now fills them from .shstrtab; no classification changes. Refs #2013
…2013) parse_esp32_size_sysv counted every .dram0.* section as RAM. On the ESP32-S3/C3 the linker script's .dram0.dummy is a NOBITS placeholder for the IRAM half of the shared DIRAM region (41-47 KB), so it landed in RAM and, through total_flash = flash + data, in flash too. The same name heuristics counted the NOBITS .iram0.text_end as flash and dropped .eh_frame / .rtc.force_slow, which are in the image. The ESP32 linker now reads the section headers in-process with the shared reader from #2012: - flash = every allocated section with contents (the generic rule of SizeInfo::from_elf_sections), i.e. the firmware.bin payload; - RAM = .dram0.data + .dram0.bss + .noinit, PlatformIO espressif32's SIZEDATAREGEXP set. IRAM code stays out of RAM, as before and as in PlatformIO. Both size-report caches are keyed on a new SIZE_REPORT_VERSION so a report from the old classifier is not served for an unchanged ELF. Empty Arduino sketch, Arduino-ESP32 3.3.12 (flash / RAM, firmware.bin): - esp32-s3-devkitc-1: 306,042 / 64,206 -> 266,769 / 21,712 (bin 266,880) - esp32-c3-devkitm-1: 309,096 / 60,934 -> 272,292 / 13,320 (bin 272,416) - esp32dev: 258,165 / 22,241 -> 261,512 / 22,244 (bin 261,632) Fixes #2013
|
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
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
parse_esp32_size_sysv(crates/fbuild-build-esp/src/esp32/size_report.rs) classifiedsize -Arows by name and counted every.dram0.*section as RAM. The ESP32-S3/C3 linker scripts emit.dram0.dummy, aNOBITSplaceholder for the IRAM half of the shared DIRAM region (41–47 KB). It went intodata, so it showed up in RAM and again intotal_flash = flash + data. The same name rules also counted theNOBITS.iram0.text_endas flash, and they left out.eh_frameand.rtc.force_slow, which are part of the image.Fix
I replaced the
size -Atext parser with the in-process ELF section-header reader that #2012 / #2021 added (fbuild_build_engine::elf_size::read_elf_section_sizes). I did not add more name heuristics.SizeInfo::from_elf_sectionsinstead of copying it. The result is thefirmware.binpayload: DROM/IROM plus the initialised RAM images that are copied from flash (.iram0.*,.dram0.data,.rtc.*), plus.eh_frame.NOBITSplaceholders (.dram0.dummy,.flash_rodata_dummy,.ext_ram.dummy,.iram0.text_end) carry no bytes..dram0.data+.dram0.bss+.noinit, matched by exact name. This is the same set as PlatformIO espressif32'sSIZEDATAREGEXP. The flags-only classifier can't be used for RAM here:.dram0.dummyisNOBITS WAexactly like.dram0.bss, and.flash.rodataisWAon Xtensa.idf_sizereports it on a separate IRAM line..noinitis new in the RAM total. It is a few bytes (2–3 in the builds below) and matches PlatformIO.Refactor commit (no behaviour change):
ElfSectionSizenow carries the section name, which the shared reader fills from.shstrtab.Caches: both ESP32 size-report caches, the per-project one and the cross-project one (#1894), now key on a new
SIZE_REPORT_VERSION(3). Before, they keyed onBUILD_FINGERPRINT_VERSION(2) and thesizetool. Without the new key, an unchanged ELF would keep getting the old wrong numbers after an upgrade. Since the report is now computed in-process, thesizetool no longer affects the key.ESP8266 does not share this parser. It already uses
LinkerBase::report_size, the generic header classifier.Tests
size_report_tests.rs(new):firmware.bin.readelf -Sof an Arduino-ESP32 3.3.12 build), including.eh_frame.esp32devtable, to check that RAM stays at data + bss..noinit.Nonecase.object: checks that aNOBITS.dram0.dummyis excluded end to end, and that a non-ELF input is rejected.esp32_linker_tests.rs:fbuild-build-engine::elf_size: the reader reports section names.Validation
soldr cargo fmt --all: clean.soldr cargo clippy --workspace --all-targets -- -D warnings: passes.bash test -p fbuild-core(384 passed),bash test -p fbuild-build-engine(567 passed),bash test -p fbuild-build-esp(259 passed).fbuild buildon an empty Arduino sketch (Arduino-ESP32 3.3.12 / IDF 5.5.5, Linux). Before = the same ELFs sized by the pre-fix daemon.firmware.bin.dram0.data+.dram0.bss+.noinitFlash is now within about 120 bytes of
firmware.binon all three; the difference is image headers, padding and the checksum.Possible follow-up, not done here: the cross-project size cache (#1894) hashes the whole ELF to build its key, which probably costs at least as much as reading the section headers now does. It may be worth deleting.
Fixes #2013