Skip to content

Force ELF delete before each measurement compile to defeat PIO link skip (#2886) #2940

Closed

Description

@zackees

Goal

Ensure tests/measure_esp32s3_opt_ins.py always produces the ELF that matches the current config's build_flags + sdkconfig, even when consecutive configs share build state. The smoke test on PR #2939 surfaced a case where running --config baseline after a prior stage3 run returned the prior config's ELF (280,738 B reported instead of the expected 339,962 B baseline).

Parent: #2886 — measurement-script hygiene.

Root cause hypothesis

PIO's build cache returns cached object files keyed on source content + compile flags. When the script switches between configs that share most object files (the entire FastLED library + Arduino-ESP32 framework), the link step pulls cached .o files and produces an ELF. If the script's call sequence (build → bloat) doesn't invalidate the previous ELF before the new build, the bash bloat esp32s3 step may run against the stale ELF if PIO's link decided no relink was needed.

Specifically: when transitioning stage3 → baseline, the only change is the sdkconfig overlay (which affects ESP-IDF compilation, not FastLED). PIO's PSRAM-aware build may decide the ELF is up-to-date and skip the relink, leaving the stage3 ELF in place even though the sdkconfig path changed.

Deliverable

tests/measure_esp32s3_opt_ins.py — force-delete the prior ELF before each compile

 def measure_one(cfg: OptInConfig, example: str) -> int | None:
     print(f"\n=== measure-opt-ins: config {cfg.name} ({cfg.label}) ===", flush=True)
     restore_platformio_ini(keep_backup=True)
     patch_platformio_ini(cfg)
+    # Force PIO to relink even if no source-file timestamps changed.
+    # The sdkconfig overlay switch (stage3 ↔ baseline) doesn't always
+    # propagate to PIO's link-decision logic, so without an explicit
+    # ELF delete the bloat step may measure the previous config's
+    # binary. See #2940.
+    elf_path = PROJECT_ROOT / ".build" / "pio" / "esp32s3" / ".pio" / "build" / "esp32s3" / "firmware.elf"
+    if elf_path.is_file():
+        elf_path.unlink()
     if not run_compile(example, cfg.name):

Deleting the ELF before each compile forces PIO's link step to actually run, even if all object files are cached. The objects are still cache-hit (so the compile is fast), but the link uses the current platformio.ini's link order and sdkconfig.

Optional follow-up: snapshot platformio.ini per config

If the cache invalidation alone doesn't fix the smoke-test discrepancy, save a copy of the patched platformio.ini to .build/measure-logs/<config>-platformio.ini for diagnostic purposes. Defer until after the primary fix.

Acceptance

  1. tests/measure_esp32s3_opt_ins.py --config baseline produces 339,962 B (the pinned baseline from tests/data/esp32s3_bloat_baseline.txt).
  2. Running baseline after a successful stage3 run produces the baseline number, not stage3's 280,738 B.
  3. bash lint passes.

Out of scope

  • Reworking the entire script to compute total_flash from .build/symbols/esp32s3/report.json for the just-built ELF rather than the latest-on-disk ELF. The current per-config archival to report.<config>.json is sufficient for post-hoc analysis.
  • Migrating away from bash compile's PIO cache. The PIO cache is the right speed/correctness trade-off; we just need to invalidate the link step.

Related

🤖 Generated with Claude Code

Activity

  1. moved this from Triage to Done in FastLED Trackeron Jun 7, 2026
  2. added a commit that references this issue on Jun 7, 2026
    e518aeb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions