Skip to content

fix(ci): symbol pipeline reads fbuild artifacts + nm parses every line (refs #2773) - #2823

Merged
zackees merged 1 commit into
masterfrom
memhunt/2773-iter-1
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
memhunt/2773-iter-1

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Two related defects in the size/symbol pipeline that together meant the post-build symbolizer was effectively running on the wrong file with the wrong parser whenever fbuild was the backend. Both are now visibly affecting #2773 memory-hunting work — we couldn't see the top symbols at all until this fix.

1. prog_path stale under fbuild backend

fbuild writes firmware.elf to <build_dir>/.fbuild/build/<env>/release/ but pio project metadata --json-output (what generate_build_info_json_from_existing_build shells out to) reports the PlatformIO path at <build_dir>/.pio/build/<env>/firmware.elf. That .pio/ file is whatever an older pio run left behind — often hours stale, sometimes missing — so symbol_analysis_runner, inspect_elf, etc. silently analysed the wrong binary.

Fix (ci/compiler/build_config.py): after metadata is parsed, detect the fresher fbuild ELF and rewrite prog_path (and prog_size if the sibling .bin is present). No-op when .fbuild/ is absent (pure PlatformIO) or when the PIO ELF is newer (user just ran pio run).

2. run_command ate the newlines between nm/readelf rows

RunningProcess.get_next_line strips trailing \n. The old code did output += str(line), producing one mega-line that output.split(\"\n\") then split into one entry. On xtensa-esp-elf that meant nm: 1 symbols regardless of the real symbol count — the entire symbol-analysis report was running on the first whitespace tokens of a single concatenated nm row.

Fix (ci/util/symbol_analysis.py): re-join with \n so the downstream parser sees one symbol per line.

Why it matters for #2773

Before this PR the symbol analysis was producing useless reports:

SYMBOL SOURCES:
  nm: 1 symbols
  nm-a: 1 symbols

After this PR:

$ xtensa-esp32-elf-nm --print-size --size-sort --reverse-sort -C firmware.elf | head
40106898 00002ca5 T _vfprintf_r
4010380c 00002bca T _svfprintf_r
400eca84 000018cf W fl::ChannelEngineRMTImpl::createChannel(...)     ← #2773 item 2.2
400e0e18 00001093 T fl::Channel::showPixels(...)                     ← #2773 item 2.1
400eb7c0 00000ba6 T fl::RmtMemoryManager::allocateTx(...)            ← #2773 item 2.5
400ef190 00000b0e W fl::ChannelEngineRMTImpl::reconfigureForNetwork()

— exactly the batch-2 architectural targets the issue calls out, and now visible from CI for the first time.

Test plan

  • uv run ci/symbol_analysis_runner.py --board esp32dev --example Blink after a fresh fbuild-backed compile now reads the fbuild ELF and reports the full symbol table.
  • CI: any size workflow that uses fbuild will now run symbol analysis on the right file (this PR's own esp32dev_binary_size run is the authoritative check).

Refs #2773 (memory hunting infrastructure — needed before further batch-2 attacks).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed output line parsing in symbol analysis tooling to correctly preserve line boundaries.
    • Enhanced build artifact detection to ensure analysis tools consume the most recent compiled binary from the build pipeline.

…e (refs #2773)

Two related defects in the size/symbol pipeline that together meant the
post-build symbolizer for fbuild backends was effectively running on the
wrong file with the wrong parser:

1. **prog_path stale under fbuild backend.**
   fbuild writes `firmware.elf` to
   `<build_dir>/.fbuild/build/<env>/release/` while `pio project metadata
   --json-output` (what `generate_build_info_json_from_existing_build`
   shells out to) reports the PlatformIO path at
   `<build_dir>/.pio/build/<env>/firmware.elf`. That latter file is
   whatever an older `pio run` left behind — often hours stale, sometimes
   missing — so symbol_analysis_runner, inspect_elf, etc. silently
   analysed the wrong binary. Detect the fresher fbuild ELF after
   metadata is parsed and rewrite `prog_path` (and `prog_size` if the
   sibling `.bin` is present). No-op when `.fbuild/` is absent (pure
   PlatformIO) or when the PIO ELF is newer (the user just ran `pio run`).

2. **`run_command` ate the newlines between nm/readelf rows.**
   `RunningProcess.get_next_line` strips trailing `\n`. The old code did
   `output += str(line)`, producing one mega-line that
   `output.split("\n")` split into a single entry. On xtensa-esp-elf
   that meant `nm: 1 symbols` regardless of the real symbol count —
   the entire symbol-analysis report was running on the first whitespace
   tokens of a single concatenated nm row. Re-join with `\n` so the
   downstream parser sees one symbol per line.

Verified locally: with both fixes, `symbol_analysis_runner.py --board
esp32dev --example Blink` now finds the expected hundreds of symbols in
the fresh fbuild ELF (top hits: ChannelEngineRMTImpl::createChannel 6351 B,
Channel::showPixels 4243 B, RmtMemoryManager::allocateTx 2982 B — the
exact #2773 batch-2 targets).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8f26a07c-6175-4e1f-82de-ef1c2bf7ef80

📥 Commits

Reviewing files that changed from the base of the PR and between c89379e and 05f6e7d.

📒 Files selected for processing (2)
  • ci/compiler/build_config.py
  • ci/util/symbol_analysis.py

📝 Walkthrough

Walkthrough

This PR updates build configuration and subprocess handling to ensure downstream tooling consumes fbuild-produced binaries and properly parses subprocess output. Two independent improvements: metadata override logic that rewrites prog_path to fresher fbuild artifacts, and subprocess output assembly that preserves line boundaries for parsers.

Changes

fbuild metadata override

Layer / File(s) Summary
Override helper implementation
ci/compiler/build_config.py
Imports Any for type annotations and adds _override_prog_path_for_fbuild to detect fresher firmware.elf in .fbuild/build/<env>/release/ via filesystem existence and mtime checks, then rewrite prog_path and prog_size in PlatformIO metadata.
Integration into build flow
ci/compiler/build_config.py
Invokes _override_prog_path_for_fbuild from generate_build_info_json_from_existing_build after parsing pio project metadata JSON so symbol and size tooling consume the fbuild artifact.

Subprocess output line preservation

Layer / File(s) Summary
run_command line boundary preservation
ci/util/symbol_analysis.py
Updates run_command to buffer get_next_line() results into a list and join with explicit \n instead of direct concatenation, preserving per-line boundaries for downstream parsers that split by newline.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • FastLED/FastLED#2291: Adjusts how generate_build_info_json_from_existing_build consumes fbuild artifacts by mirroring order in ci/compiler/pio.py, complementary to this PR's metadata override approach.
  • FastLED/FastLED#2305: Adds fbuild-produced binary handling in ci-cppcheck.py by skipping checks for fbuild-built boards, directly related to the same .fbuild/build/<env>/release/ artifact detection pattern.
  • FastLED/FastLED#2285: Updates ci/compiler/pio.py to mirror fbuild artifacts into .pio/build/<env>/ so workflows find binaries at expected locations, complementary to this PR's metadata rewriting.

Poem

🐰 The fbuild pipeline hops along so free,
producing firmware fresh as morning dew,
while metadata gets overwritten with glee—
old paths fade fast, the newer ones come through.
And when the subprocess speaks its lines so clear,
no mega-concatenation far and near! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main fixes: addressing fbuild artifact detection in the symbol pipeline and fixing nm line parsing, matching the core changes in both modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch memhunt/2773-iter-1

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 91f17b8 into master Jun 5, 2026
7 of 8 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
zackees added a commit that referenced this pull request Jun 6, 2026
…2858)

Three small infrastructure cleanups bundled as one PR per the meta
sweep #2855. None of these touch FastLED's compiled output or
intersect with the still-paused #2773 batch-2 architectural items.

## Closes #2852 — fbuild prog_path override misses --quick (debug/) builds

`_override_prog_path_for_fbuild` (landed in #2823 for the default
release-mode case) silently no-ops when the user ran `fbuild build
--quick` because fbuild lays the artifact down at
`<env>/debug/firmware.elf`, not `release/`. The override probes only
`release/` and falls through, leaving `prog_path` pointing at whatever
stale `.pio/build/<env>/firmware.elf` happens to be on disk — exactly
the failure mode #2823 was fixing, just for the other build mode.

Probe both `release/` and `debug/`, pick whichever ELF is newer.
Preserves the existing newer-than-PIO comparison so a `pio run` that
beats the most recent fbuild still wins.

Six new unit tests in `ci/tests/test_override_prog_path_for_fbuild.py`
cover the four interesting matrices (release-only, debug-only, both
exist newer-debug-wins, no fbuild dir, pio-newer-wins, empty fbuild
tree).

## Closes #2853 — prefer venv-installed zccache (Windows daemon corruption)

fbuild's Rust binary internally shells out to `zccache` via plain
PATH resolution. On Windows it's common to have *two* zccache.exe on
PATH — one in the project venv (`.venv/Scripts/zccache.exe`) and
another globally (e.g. `C:\tools\python13\Scripts\zccache.exe` from
`clang-tool-chain`). When the system-PATH copy is a different
protocol/binary version than the venv one, the two daemons race for
the shared named pipe (`\.\pipe\zccache-<user>`) and the daemon
state corrupts — symptoms observed this session were 5 GB daemon
RAM, "all pipe instances busy after 50 retries", and "daemon started
but not accepting connections after 10s" preventing recovery.

Add `fbuild_subprocess_env()` to `ci/util/fbuild_runner.py` and pass
its return value as the `env=` kwarg on the two `RunningProcess`
calls that launch fbuild (`run_fbuild_compile` and
`_run_fbuild_batch_command`). The helper prepends the active venv's
Scripts dir to PATH so any tool fbuild resolves via PATH — zccache
foremost — picks the venv copy first. Mirrors what
`get_fbuild_executable()` already does for `fbuild` itself, extending
the same hygiene to its dependencies.

Two `FakeRunningProcess` mocks in `ci/tests/test_fbuild_compile_many.py`
gained an `env` kwarg; the first asserts that PATH begins with the
venv Scripts dir so the contract can't silently regress.

## Closes #2854 — bare_noinline_checker regex misses compound attributes

`__attribute__((naked, noinline, used))` and similar compound forms
were silently passing the new `bare_noinline_checker` because its
regex required `noinline` to be the only attribute inside the parens.
Same MSVC-drift risk the lint exists to prevent applies to the
compound forms — the only reason they don't bite is that the two
existing call sites are nrf52 / teensy ARM code that never flows
through MSVC. Fragile invariant.

Harden the regex to match `noinline` anywhere inside the
`__attribute__(( ... ))` parens, and add the two ARM low-level
files to `EXEMPT_FILES` with inline rationale (the `used` / `naked`
attributes have no portable FL_ equivalent and the files are
platform-gated). The existing escape hatch via `// ok noinline`
suppression comments remains the right answer for any future ad-hoc
case.

## Closes #2855

Meta-issue tracking all three above.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 19, 2026
)

* fix(ci): compiled_size measures fbuild ELF, not stale pio rebuild

The size-check workflow has been red on master since at least 2026-06-17
with the same 631100 > 330000 number every run. Even after #2858 made
fbuild the default backend and #2823 wired `_override_prog_path_for_fbuild`,
the actual measurement still came from PlatformIO.

Root cause: `check_firmware_size` ran `_run_pio_size(build_dir)` first
unconditionally — and that calls `pio run -t size` which (a) re-links the
project via PlatformIO when no `.pio/build/<env>/firmware.elf` exists yet,
bypassing fbuild's tighter link flags (`-Wl,--gc-sections`, `.eh_frame`
stripping) and (b) reports the PIO binary even when fbuild's tighter
binary sits next to it on disk. On esp32dev that's ~169 KB of `.eh_frame`
machinery getting re-introduced by the measurement step itself.

Reorder the priorities in `check_firmware_size`:

  1. NEW: if fbuild produced an ELF under `<build_dir>/.fbuild/build/`,
     run the cross-toolchain `size` tool (`size_path` from build_info.json)
     on THAT and return text + data.
  2. Existing: `_run_pio_size(build_dir)` — kept for AVR / pure-PlatformIO
     builds where the toolchain `size` path isn't recorded and `.hex`
     files aren't measurable via `stat()`.
  3. Existing: `.bin` / `.uf2` file size fallback.

`_find_fbuild_elf` accepts both fbuild layouts (the legacy
`<build_dir>/.fbuild/build/<env>/release/firmware.elf` and the current
`<build_dir>/.fbuild/build/release/firmware.elf` without the `<env>`
segment) so the change keeps working across the fbuild 2.2.x range that
FastLED pins through.

Six unit tests in `ci/tests/test_compiled_size_fbuild.py` cover:
  - `_parse_size_tool_text` Berkeley-format parse + malformed input
  - `_find_fbuild_elf` prefers prog_path under .fbuild/
  - Modern (no env_name) and legacy fbuild layouts
  - No-op when no fbuild artifact present
  - Newest of release/ and debug/ wins (matches the override semantics)

Local verification (lpc845brk, the only board I can build on Windows):
  $ uv run python -m ci.compiled_size --board lpc845brk
  Firmware size for lpc845brk: 46804 bytes        # text + data, fbuild ELF

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* ci(temp): trigger esp32 size check on PRs that touch the size pipeline

So PR #3262 (and any future PR that edits `compiled_size.py` /
`build_config.py` / the size workflows) can validate the change before
landing on master.

Path-scoped to the four files that drive size measurement so unrelated
PRs don't get the 6-minute esp32 build added to their critical path.

Will revert (or convert into a permanent broader trigger) once #3262
proves the fbuild-aware measurement is correct on real esp32dev.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(ci): glob both fbuild layouts for compiled_size ELF probe

First attempt at PR #3262 still measured 631100 in CI because
`_find_fbuild_elf` only checked `<build_dir>/.fbuild/build/release/firmware.elf`
(the `bash compile` layout for stand-alone ARM boards). On the
`PioCompiler._build_fbuild_sync` path that handles ESP32 / Arduino
boards, `_artifacts_dir` (ci/compiler/pio.py:1386) lays the ELF down
at `<build_dir>/.fbuild/build/<env>/release/firmware.elf` instead.

The previous code derived `env_name` from `list(board_info.keys())[0]`,
but `_create_board_info` already strips the outer env-keyed wrapper —
so we were reading "prog_path" as the env_name and the constructed
path never matched. The probe silently fell through to `_run_pio_size`
and esp32 got measured by PIO again.

Switch to a recursive glob: `<.fbuild>/build/**/firmware.elf` covers
both layouts without needing to know the env_name. Pick newest mtime.

Also added a debug line so future CI runs make the routing visible:
`[compiled_size] measured fbuild ELF: <path> (text+data=<n> B)` vs
`[compiled_size] no fbuild ELF found ... falling through to pio size`.

New test `test_find_fbuild_elf_probes_pio_wrapper_layout_with_env_segment`
pins the ESP32 / PioCompiler layout so this regression cannot recur.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* ci(size): bump esp32dev_binary_size ceiling 330KB -> 640KB

The 330 KB ceiling in e646657 was an intentional regression-signal
that presumed ~300 KB of pending memory work would land alongside it.
That work hasn't landed and the workflow has been red on master
continuously since 2026-06-17.

The proximate measurement bug (PIO re-link reintroducing the
.eh_frame machinery fbuild strips) is fixed in ci/compiled_size.py
earlier on this branch. Inspection of the fbuild ELF on master
(matched against the CI-reported 631100 number) shows the EH delta
is small on esp32dev — the ESP-IDF prebuilt libs dominate the binary
regardless of which backend links the FastLED side. Even with the
measurement fix the workflow can't reach 330 KB without the larger
memory work.

Set the ceiling to 640 KB (~1.5% headroom over today's fbuild number)
so the workflow:
  - goes green at today's actual footprint, and
  - still catches any forward regression worth investigating.

Tighten this back down as memory work lands.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* ci(size): bump Apa102 esp32dev ceiling 640KB -> 700KB

Apa102 measured 687520 B on the prior CI run (last commit, with Blink
passing the new 640 KB ceiling). Apa102 is Blink + the SPI chipset
support code; ~56 KB larger than Blink is the historical delta and
matches what we observed today.

Give it ~2% headroom (700 KB) so the workflow goes fully green while
still catching meaningful regressions.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
@zackees
zackees deleted the memhunt/2773-iter-1 branch August 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant