Skip to content

fbuild bloat: emit and preserve firmware.map automatically #491

Description

@zackees

Problem

fbuild bloat / fbuild symbols produces a useful per-symbol table from nm, but the archive / object / section columns come from the linker map (firmware.map). On a fresh fbuild build, no map file is emitted, so those columns are all - and bloat lookup cannot show callers, referencers, or per-archive rollups.

Repro on this branch (Windows, esp32s3 sketch):

fbuild build tests/platform/esp32s3 -e esp32s3
fbuild symbols tests/platform/esp32s3 --top 50
# → all ARCHIVE/OBJECT/SECTION columns are "-"
# → "Flash bytes by archive" rolls everything up under "(unattributed)"

find tests/platform/esp32s3/.fbuild -name '*.map'    # → no results
find tests/platform/esp32s3/.fbuild -name 'build_info*.json'  # → no results

The map is the difference between a generic top-N report and an actionable one (e.g. "12% of flash is libc.a/lib_a-vfprintf.o").

Proposed fix

When fbuild bloat (today: fbuild symbols) runs against a project directory, if no map sits next to the ELF:

  1. Re-link with -Wl,-Map=firmware.map automatically (or pass it on every link by default during fbuild build — the cost is a few hundred KB of disk).
  2. Likewise emit build_info.json (toolchain nm / c++filt paths) next to the ELF so --nm / --cppfilt don't have to be passed manually.

Option 1 (always emit during link) is cleaner and matches what PlatformIO / Arduino IDE do today — the map is a normal build product. Option 2 (lazy re-link on demand from fbuild bloat) avoids the disk cost but makes the first invocation slow and surprising.

Acceptance

  • After fbuild build tests/platform/esp32s3 -e esp32s3, firmware.map and build_info.json exist beside firmware.elf.
  • fbuild symbols tests/platform/esp32s3 fills the ARCHIVE / OBJECT / SECTION columns.
  • "Flash bytes by archive" shows real archive names (libc.a, libfreertos.a, etc.), not (unattributed).
  • fbuild bloat lookup <symbol> reports per-symbol callers / TU-level referencers.

Related

  • Found while investigating ~26 KB of newlib printf bloat on an esp32s3 firmware. Without archive attribution the report didn't even confirm the printf symbols come from libc.a — had to infer from the _r suffix and _dtoa_r signature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions