Skip to content

fix(esp32): size report from ELF section headers; drop .dram0.dummy from RAM and flash (#2013) - #2023

Merged
zackees merged 2 commits into
mainfrom
fix/esp32-size-dram0-dummy-2013
Nov 16, 2026
Merged

zackees merged 2 commits into
mainfrom
fix/esp32-size-dram0-dummy-2013

Conversation

@zackees

@zackees zackees commented Nov 16, 2026

Copy link
Copy Markdown
Member

Root cause

parse_esp32_size_sysv (crates/fbuild-build-esp/src/esp32/size_report.rs) classified size -A rows by name and counted every .dram0.* section as RAM. The ESP32-S3/C3 linker scripts emit .dram0.dummy, a NOBITS placeholder for the IRAM half of the shared DIRAM region (41–47 KB). It went into data, so it showed up in RAM and again in total_flash = flash + data. The same name rules also counted the NOBITS .iram0.text_end as flash, and they left out .eh_frame and .rtc.force_slow, which are part of the image.

Fix

I replaced the size -A text 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.

  • Flash is every allocated section with contents. This reuses the generic rule in SizeInfo::from_elf_sections instead of copying it. The result is the firmware.bin payload: DROM/IROM plus the initialised RAM images that are copied from flash (.iram0.*, .dram0.data, .rtc.*), plus .eh_frame. NOBITS placeholders (.dram0.dummy, .flash_rodata_dummy, .ext_ram.dummy, .iram0.text_end) carry no bytes.
  • RAM is .dram0.data + .dram0.bss + .noinit, matched by exact name. This is the same set as PlatformIO espressif32's SIZEDATAREGEXP. The flags-only classifier can't be used for RAM here: .dram0.dummy is NOBITS WA exactly like .dram0.bss, and .flash.rodata is WA on Xtensa.
  • IRAM code is not counted as RAM. The previous fbuild report didn't count it and neither does PlatformIO; idf_size reports it on a separate IRAM line.
  • .noinit is new in the RAM total. It is a few bytes (2–3 in the builds below) and matches PlatformIO.

Refactor commit (no behaviour change): ElfSectionSize now 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 on BUILD_FINGERPRINT_VERSION (2) and the size tool. 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, the size tool 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):
    • The issue's S3 table: RAM 21,436, and flash is every PROGBITS section, within 256 B of the 278,144-byte firmware.bin.
    • A real C3 table (readelf -S of an Arduino-ESP32 3.3.12 build), including .eh_frame.
    • A real classic esp32dev table, to check that RAM stays at data + bss.
    • .noinit.
    • The non-ESP → None case.
    • A tempfile ELF written with object: checks that a NOBITS .dram0.dummy is 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).
  • End to end with fbuild build on an empty Arduino sketch (Arduino-ESP32 3.3.12 / IDF 5.5.5, Linux). Before = the same ELFs sized by the pre-fix daemon.
env before flash / RAM after flash / RAM firmware.bin .dram0.data+.dram0.bss+.noinit
esp32-s3-devkitc-1 306,042 / 64,206 266,769 / 21,712 266,880 21,712
esp32-c3-devkitm-1 309,096 / 60,934 272,292 / 13,320 272,416 13,320
esp32dev 258,165 / 22,241 261,512 / 22,244 261,632 22,244

Flash is now within about 120 bytes of firmware.bin on 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

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
@coderabbitai

coderabbitai Bot commented Nov 16, 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

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.

ESP32-S3/C3: size report counts .dram0.dummy as RAM and again as flash (2.5.51)

1 participant