Skip to content

feat(fl/stl): add FL_NO_UNWIND macros, apply to ESP32 unity headers - #2423

Merged
zackees merged 1 commit into
masterfrom
feat/no-unwind-esp32-2421
May 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/no-unwind-esp32-2421

Conversation

@zackees

@zackees zackees commented May 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds FL_NO_UNWIND / FL_NO_UNWIND_BEGIN / FL_NO_UNWIND_END macros and applies the TU-level pair to both ESP32 unity-build headers. Targets the binary-size half of #2421 by suppressing GCC unwind-table emission for the FastLED ESP32 driver code, with a debug-aware gate so panic backtraces stay intact in development builds.

Closes part of #2421. Related: #2420.

Why

Symbol-level analysis of @nomakewan's reproducer build (master#ea5d8ec, ESP32-S3, NEOPIXEL, 35 LEDs) showed libFastLED.a contributing 180 KB of .eh_frame — half of the entire .flash.rodata section. A direct count of FDE entries showed:

  • 16,773 total FDEs in the binary
  • 13,272 (79.1%) are orphan FDEs covering zero-byte ranges — left behind by GNU LD when --gc-sections strips dead virtual-dispatch code but fails to cull the corresponding .eh_frame entry
  • Only 21% point to live code

Full breakdown: #2421 (comment)

FL_NOEXCEPT does not suppress this — noexcept is a language contract, .eh_frame is a codegen artifact controlled by -fasynchronous-unwind-tables (default ON in GCC, used by panic handlers / debuggers / profilers, not just C++ exceptions).

What changed

  • src/fl/stl/compiler_control.h (+89): three new macros following the same pattern as the existing FL_DISABLE_WARNING_PUSH/POP and FL_BEGIN_OPTIMIZE_FOR_EXACT_TIMING blocks
  • src/platforms/esp/32/_build.cpp.hpp (+5): wrap entire unity TU with FL_NO_UNWIND_BEGIN/_END
  • src/platforms/esp/32/drivers/_build.cpp.hpp (+5): same

Gating logic — preserves backtraces by default

The macros are no-ops (preserve .eh_frame) whenever any of these are set:

FastLED debug indicators: !RELEASE, FASTLED_TESTING, FASTLED_FORCE_DBG, FASTLED_DEBUG, FL_DEBUG, !NDEBUG

ESP32 sdkconfig (only when FL_IS_ESP32 is defined):

  • CONFIG_ESP_SYSTEM_PANIC_PRINT_BACKTRACE (ESP-IDF default ON)
  • CONFIG_ESP_SYSTEM_PANIC_GDBSTUB
  • CONFIG_ESP_DEBUG_OCDAWARE
  • CONFIG_COMPILER_OPTIMIZATION_DEBUG / CONFIG_COMPILER_OPTIMIZATION_NONE

Arduino-ESP32 verbosity: CORE_DEBUG_LEVEL >= 3

User overrides (last word): FASTLED_FORCE_UNWIND_TABLES (force-keep) / FASTLED_FORCE_NO_UNWIND_TABLES (force-strip)

This means the size win has to be opted into with -DFASTLED_FORCE_NO_UNWIND_TABLES in build_flags. The default behavior on the reporter's exact build (CORE_DEBUG_LEVEL=3 + ESP-IDF default panic backtrace) is no change — backtraces are preserved, binary size is unchanged from current master. Users who want the ~180 KB win pay for it explicitly.

Why opt-in is the right default

A wrapped function shows ??? in esp32_exception_decoder output. For a release build of a single-purpose installation that just blinks LEDs, that's an acceptable trade for 180 KB; for a development build or a customer-facing product where crash diagnostics matter, it isn't. Defaulting to "preserve" is the conservative choice.

Why compiler_control.h and not a new codegen.h

The original spec proposed src/fl/stl/codegen.h, but src/fl/stl/compiler_control.h already hosts every other _Pragma-based macro pair in the codebase (FL_DISABLE_WARNING_PUSH/POP, FL_BEGIN_OPTIMIZE_FOR_EXACT_TIMING/_END, FL_OPTIMIZATION_LEVEL_O3_BEGIN/_END). Same shape, same conventions, same compiler-detection macros (FL_IS_GCC, FL_GCC_VERSION, FL_STRINGIFY) — so the natural home was here, not a parallel new file.

Why just optimize("no-unwind-tables") and not also no-asynchronous-unwind-tables

-fno-unwind-tables is the strictly stronger GCC flag and implies -fno-asynchronous-unwind-tables. The redundant pair is a common belt-and-suspenders pattern in tutorials but adds nothing on GCC. One flag is enough. (Discussion: #2421 (comment).)

Why the GCC-only gate (and not clang)

#pragma GCC optimize is accepted by clang but emits an "unknown pragma" warning at minimum, and clang's per-function optimize attribute support is uneven (well-known caveats with LTO and template instantiation). Restricting to FL_IS_GCC keeps clang builds clean.

Verification

  • bash lint — clean
  • bash test --cpp — 302/302 host tests pass (~107s)
  • bash compile esp32s3 --examples Blink — succeeds (~437s), produces 810.81 KB firmware.bin (default mode, backtraces preserved — exactly as designed)
  • Pragma compiles without warning under Xtensa GCC 13.2 from pioarduino's toolchain-xtensa-esp-elf

Test plan

  • Lint clean
  • Host tests (302/302) pass
  • ESP32-S3 default-mode compile succeeds, binary unchanged from current master
  • Need community verification: build with -DFASTLED_FORCE_NO_UNWIND_TABLES and confirm ~180 KB savings
  • Need community verification: panic-decode a forced crash inside Channel::showPixels in default mode (backtrace should be intact) and in opt-in mode (frame should show ???, downstream frames should still resolve)
  • @nomakewan if you're up for it, retest your [Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420 sketch with this branch + -DFASTLED_FORCE_NO_UNWIND_TABLES in build_flags and report the new binary size

What this does NOT fix

This PR addresses ONE half of #2421 (the binary bloat). It does NOT fix:

Those land in subsequent PRs against #2421.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Added build-time controls to optionally suppress unwind table emission on embedded builds, reducing binary size.
    • Applied those controls across platform unity-builds so the setting consistently affects aggregated implementation files.
    • Backtrace/debug builds automatically preserve unwind information; unsupported toolchains remain unaffected and can no-op the controls.
  • Tests

    • Added tests verifying the new unwind-control behavior and safe usage when the controls are no-ops.

@coderabbitai

coderabbitai Bot commented May 1, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a configurable "no unwind" macro family (FL_NO_UNWIND, FL_NO_UNWIND_BEGIN, FL_NO_UNWIND_END) that conditionally suppresses GCC DWARF unwind table emission and applies these macros around ESP32 unity-build include blocks; includes a test validating macro resolution and usage.

Changes

Cohort / File(s) Summary
Compiler control header
src/fl/stl/compiler_control.h
Adds FL_NO_UNWIND, FL_NO_UNWIND_BEGIN, FL_NO_UNWIND_END, and FL_NO_UNWIND_ACTIVE. Resolves activation via user overrides, backtrace/debug flags, and defaults; maps to __attribute__((optimize("no-unwind-tables"))) and GCC push/pop optimize pragmas on GCC, else no-ops.
ESP32 unity-build wrappers
src/platforms/esp/32/_build.cpp.hpp, src/platforms/esp/32/drivers/_build.cpp.hpp
Includes fl/stl/compiler_control.h and wraps unity-build include blocks with FL_NO_UNWIND_BEGIN / FL_NO_UNWIND_END to apply region-level unwind-table suppression.
Tests
tests/fl/stl/compiler_control.cpp
Adds test cases that assert FL_NO_UNWIND_ACTIVE and exercise per-function and TU-scoped FL_NO_UNWIND usages, including nested/noop scenarios to ensure compilation and runtime behavior remain correct.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble pragmas, soft and spry,
Quieting frames so binaries fly.
Macros tucked in stack and span,
A rabbit's wink in every plan. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: introducing FL_NO_UNWIND macros in compiler_control.h and applying them to ESP32 unity headers.
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 feat/no-unwind-esp32-2421

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/fl/stl/compiler_control.h (1)

252-270: 💤 Low value

Consider using #ifndef guards to avoid potential macro redefinition warnings.

Multiple conditions can define _FL_BUILD_WANTS_BACKTRACE to 1, which works but may trigger -Wmacro-redefined warnings on strict compiler settings. Using #ifndef guards would be cleaner:

 `#if` !defined(RELEASE)
+  `#ifndef` _FL_BUILD_WANTS_BACKTRACE
   `#define` _FL_BUILD_WANTS_BACKTRACE 1
+  `#endif`
 `#endif`

However, since all definitions use the same value (1) and this is an internal macro, most compilers will silently accept this. This is a minor stylistic suggestion.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fl/stl/compiler_control.h` around lines 252 - 270, The multiple
conditional blocks repeatedly define _FL_BUILD_WANTS_BACKTRACE which can trigger
-Wmacro-redefined; modify the checks so you only define it once using an `#ifndef`
guard around the definition (e.g., when any of the debug conditions are true,
test if _FL_BUILD_WANTS_BACKTRACE is not already defined before doing `#define`
_FL_BUILD_WANTS_BACKTRACE 1); update the blocks that mention FASTLED_TESTING,
FASTLED_FORCE_DBG, FASTLED_DEBUG, FL_DEBUG, RELEASE, and NDEBUG so they either
funnel into a single conditional that then uses `#ifndef`
_FL_BUILD_WANTS_BACKTRACE or each conditional does a prior `#ifndef` check to
avoid redefinitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/fl/stl/compiler_control.h`:
- Around line 252-270: The multiple conditional blocks repeatedly define
_FL_BUILD_WANTS_BACKTRACE which can trigger -Wmacro-redefined; modify the checks
so you only define it once using an `#ifndef` guard around the definition (e.g.,
when any of the debug conditions are true, test if _FL_BUILD_WANTS_BACKTRACE is
not already defined before doing `#define` _FL_BUILD_WANTS_BACKTRACE 1); update
the blocks that mention FASTLED_TESTING, FASTLED_FORCE_DBG, FASTLED_DEBUG,
FL_DEBUG, RELEASE, and NDEBUG so they either funnel into a single conditional
that then uses `#ifndef` _FL_BUILD_WANTS_BACKTRACE or each conditional does a
prior `#ifndef` check to avoid redefinitions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5b37b95f-c0dc-4f5f-bdad-4f11f5a133bf

📥 Commits

Reviewing files that changed from the base of the PR and between ea5d8ec and d9ebddd.

📒 Files selected for processing (3)
  • src/fl/stl/compiler_control.h
  • src/platforms/esp/32/_build.cpp.hpp
  • src/platforms/esp/32/drivers/_build.cpp.hpp

@zackees
zackees force-pushed the feat/no-unwind-esp32-2421 branch from d9ebddd to 9c70fda Compare May 1, 2026 16:34
@nomakewan

Copy link
Copy Markdown
Contributor

The new binary size for the example code from #2420 with -D "FASTLED_FORCE_NO_UNWIND_TABLES" in build_flags and targeting this branch is 770 KB if -D "CORE_DEBUG_LEVEL=0" and 784 KB if -D "CORE_DEBUG_LEVEL=3".

Suppresses .eh_frame generation for the ESP32 unity-build TUs to
eliminate ~180KB of orphan FDEs left behind after --gc-sections strips
dead virtual-dispatch code. Gated to no-op on debug builds and on
builds that have explicitly enabled ESP-IDF backtrace printing
(CONFIG_ESP_SYSTEM_PANIC_PRINT_BACKTRACE, CORE_DEBUG_LEVEL>=3, etc.).

Refs #2421, #2420.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees force-pushed the feat/no-unwind-esp32-2421 branch from 9c70fda to 21a71a3 Compare May 1, 2026 18:57
@zackees

zackees commented May 1, 2026

Copy link
Copy Markdown
Member Author

Refactored macro structure for robustness + user override

Force-pushed (PR still one commit, 21a71a3b02). Changes from prior version:

What's new

  1. User can pre-define any of the macros directly. Each FL_NO_UNWIND / FL_NO_UNWIND_BEGIN / FL_NO_UNWIND_END is now guarded with #ifndef, so a user can pre-define their own (e.g. a custom pragma combo) before including fl/stl/compiler_control.h and the header will respect it.

  2. New FL_NO_UNWIND_ACTIVE query macro. Always defined to 0 or 1 after include. Lets calling code branch on whether stripping is actually happening, e.g. for log lines or conditional compilation. Also pre-overridable.

  3. Cleaner two-stage policy resolution:

    • Stage 1: resolve FL_NO_UNWIND_ACTIVE (skipped if user pre-defined)
    • Stage 2: emit each macro independently with #ifndef guards (skipped if user pre-defined)

    Eliminates the previous coupled _FL_BUILD_WANTS_BACKTRACE sentinel, which used a reserved-identifier namespace (_ + uppercase, technically reserved by the C++ standard).

  4. Documented user-control hierarchy (highest priority first):

    1. Direct macro override (pre-define FL_NO_UNWIND / FL_NO_UNWIND_BEGIN / FL_NO_UNWIND_END / FL_NO_UNWIND_ACTIVE)
    2. Hard policy override: FASTLED_FORCE_NO_UNWIND_TABLES=1 (always strip) or FASTLED_FORCE_UNWIND_TABLES=1 (always preserve)
    3. Debug auto-detect (!RELEASE, !NDEBUG, FastLED debug macros, ESP32 panic-config, CORE_DEBUG_LEVEL>=3)
    4. Default: release build with no diagnostic indicators → strip
  5. Self-correcting FL_NO_UNWIND_ACTIVE: if user requests stripping (Stage 1 sets it to 1) but we're not on GCC and so can't honor it (Stage 2 emits no-ops), the query macro is corrected back to 0 to accurately reflect what was emitted.

Code shape

// Stage 1: policy
#ifndef FL_NO_UNWIND_ACTIVE
  #if defined(FASTLED_FORCE_NO_UNWIND_TABLES) && FASTLED_FORCE_NO_UNWIND_TABLES
    #define FL_NO_UNWIND_ACTIVE 1
  #elif defined(FASTLED_FORCE_UNWIND_TABLES) && FASTLED_FORCE_UNWIND_TABLES
    #define FL_NO_UNWIND_ACTIVE 0
  #elif <debug auto-detect compound>
    #define FL_NO_UNWIND_ACTIVE 0
  #else
    #define FL_NO_UNWIND_ACTIVE 1
  #endif
#endif

// Stage 2: emission
#if FL_NO_UNWIND_ACTIVE && defined(FL_IS_GCC)
  #ifndef FL_NO_UNWIND       /* ... attribute ... */ #endif
  #ifndef FL_NO_UNWIND_BEGIN /* ... pragmas  ... */ #endif
  #ifndef FL_NO_UNWIND_END   /* ... pop      ... */ #endif
#else
  #ifndef FL_NO_UNWIND       /* no-op */ #endif
  // ...
  #if FL_NO_UNWIND_ACTIVE  // user wanted strip but we're non-GCC
    #undef FL_NO_UNWIND_ACTIVE
    #define FL_NO_UNWIND_ACTIVE 0
  #endif
#endif

Tests added

tests/fl/stl/compiler_control.cpp gets a new FL_NO_UNWIND family test case covering:

  • FL_NO_UNWIND_ACTIVE is exactly 0 or 1
  • Per-function FL_NO_UNWIND attribute compiles + runs
  • TU-level FL_NO_UNWIND_BEGIN/_END compiles + runs (sample function defined inside the block)
  • Macros are always defined (even when no-op)
  • Nested FL_NO_UNWIND_BEGIN/_END blocks compile

Verification

  • bash lint --cpp clean
  • bash test compiler_control — 1/1 binary, all subcases pass
  • bash test --cpp — 301/301 host test binaries pass

Net diff vs prior PR version

src/fl/stl/compiler_control.h     | 172 ++++++++++++++++++++++++-------------
tests/fl/stl/compiler_control.cpp |  51 +++++++++++

Macros header grew (more comments + the cleaner two-stage structure); test coverage added for the new behaviors.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/fl/stl/compiler_control.cpp (1)

816-819: ⚡ Quick win

Use an explicit equality assertion for clearer failure output.

Line 818 uses a generic boolean check; prefer a specific equality assertion in test code for better diagnostics.

Proposed change
-        FL_CHECK(FL_NO_UNWIND_ACTIVE == 0 || FL_NO_UNWIND_ACTIVE == 1);
+        FL_CHECK_EQ((FL_NO_UNWIND_ACTIVE == 0 || FL_NO_UNWIND_ACTIVE == 1), true);

Based on learnings: "Use proper assertion macros (CHECK_EQ, CHECK_LT, etc.) instead of generic CHECK macro".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/fl/stl/compiler_control.cpp` around lines 816 - 819, Replace the
generic boolean check FL_CHECK(FL_NO_UNWIND_ACTIVE == 0 || FL_NO_UNWIND_ACTIVE
== 1) with an explicit equality-style assertion so failures show clear
diagnostics; for example use FL_CHECK_EQ((FL_NO_UNWIND_ACTIVE == 0) ||
(FL_NO_UNWIND_ACTIVE == 1), true) (or an equivalent FL_CHECK_EQ-style macro your
test framework provides) inside the FL_SUBCASE to reference FL_NO_UNWIND_ACTIVE
and FL_CHECK_EQ instead of the generic FL_CHECK.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/fl/stl/compiler_control.cpp`:
- Around line 816-819: Replace the generic boolean check
FL_CHECK(FL_NO_UNWIND_ACTIVE == 0 || FL_NO_UNWIND_ACTIVE == 1) with an explicit
equality-style assertion so failures show clear diagnostics; for example use
FL_CHECK_EQ((FL_NO_UNWIND_ACTIVE == 0) || (FL_NO_UNWIND_ACTIVE == 1), true) (or
an equivalent FL_CHECK_EQ-style macro your test framework provides) inside the
FL_SUBCASE to reference FL_NO_UNWIND_ACTIVE and FL_CHECK_EQ instead of the
generic FL_CHECK.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 89ca54bd-e082-4b29-a51b-fffc7a26cb20

📥 Commits

Reviewing files that changed from the base of the PR and between 9c70fda and 21a71a3.

📒 Files selected for processing (4)
  • src/fl/stl/compiler_control.h
  • src/platforms/esp/32/_build.cpp.hpp
  • src/platforms/esp/32/drivers/_build.cpp.hpp
  • tests/fl/stl/compiler_control.cpp
✅ Files skipped from review due to trivial changes (2)
  • src/platforms/esp/32/_build.cpp.hpp
  • src/fl/stl/compiler_control.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/platforms/esp/32/drivers/_build.cpp.hpp

@zackees
zackees merged commit 022402d into master May 1, 2026
6 of 7 checks passed
zackees added a commit to FastLED/fbuild that referenced this pull request May 13, 2026
…CC platforms

GCC emits .eh_frame unwinding tables by default. On a stock FastLED
ESP32-S3 Blink build this is ~225 KB / 36% of the firmware -- dead
metadata no _Unwind_* API ever consumes when exceptions and panic
backtrace are both off. FastLED's library-side pragma workaround
(FastLED/FastLED#2423) is a no-op on modern GCC (audited in
FastLED/FastLED#2473); the only reliable fix is cc1-level flags, which
is the build system's job.

This PR adds a shared eh_frame strip policy that injects
`-fno-asynchronous-unwind-tables -fno-unwind-tables` to every TU when
appropriate. The decision respects user intent at every layer:
explicit env override, debug builds, `-fexceptions` in build_flags,
ESP-IDF panic-backtrace / gdbstub / ocdaware / optimization-debug
sdkconfig keys.

New modules
- `crates/fbuild-build/src/eh_frame_policy.rs` -- pure `decide()`
  function over plain inputs, plus `STRIP_FLAGS` constant. 16 unit
  tests cover the full precedence matrix.
- `crates/fbuild-build/src/eh_frame_policy_compute.rs` -- orchestrator-
  side helper that reads env vars + extracts BuildContext fields and
  calls `decide()`.
- `crates/fbuild-config/src/sdkconfig.rs` -- minimal sdkconfig parser
  surfacing the 4 keys the policy reads. Defaults to ESP-IDF Arduino
  defaults (`panic_print_backtrace = true`) so the safe assumption for
  an unmodified project is Preserve. 14 unit tests.

Per-platform wiring
- ESP32, generic ARM (STM32/RP2040/NRF52), Teensy, ESP8266, AVR each
  get a `with_eh_frame_policy()` setter and a 3-line append in
  `common_flags()`. Mirrors the existing `with_build_unflags` pattern.
- All orchestrators (esp32, generic_arm, teensy, esp8266, avr, stm32,
  rp2040, apollo3) compute the policy once per build and pass it to
  each compiler construction site. ESP32 also reads sdkconfig from the
  project dir. Other platforms pass `None`.
- 10 new platform unit tests (2 per platform) assert STRIP_FLAGS
  presence under `Strip` and absence under default `Preserve`.

Integration test (`#[ignore]`, toolchain-required)
- `crates/fbuild-build/tests/eh_frame_strip_esp32.rs` builds a tempfile
  ESP32 project twice (FBUILD_KEEP_EH_FRAME=1 vs FBUILD_STRIP_EH_FRAME=1)
  and asserts firmware.bin delta >= 150 KB plus `.eh_frame` ELF section
  delta >= 50 KB via the `object` crate.

User-facing overrides
- `FBUILD_STRIP_EH_FRAME=1` -- force strip regardless of detection
- `FBUILD_KEEP_EH_FRAME=1` -- force preserve

Behavior under defaults
- ESP32 with stock Arduino framework: Preserve (matches user
  expectation of esp32_exception_decoder showing readable backtraces).
- Teensy / STM32 / RP2040 / NRF52 / ESP8266: Strip (their JSON configs
  already ship `-fno-exceptions`; nothing in their toolchain consumes
  eh_frame). Immediate flash savings on every release build.
- AVR: Strip wired for uniformity; runtime is a no-op because AVR-gcc
  only emits eh_frame when `-fexceptions` is on, which AVR's JSON
  disables.
- Debug builds (`build_type = debug`, or `-Og`/`-O0` flags) always
  Preserve, even on platforms that would otherwise strip.

Test coverage
- 16 eh_frame_policy unit tests (decision matrix)
- 14 sdkconfig unit tests (parser + project-dir lookup)
- 10 per-platform compiler tests (STRIP_FLAGS presence/absence)
- 1 integration test (`#[ignore]`, runs locally with ESP32 toolchain)
- Existing 534 fbuild-build + 120 fbuild-config lib tests stay green.

Closes #243.
Closes #244.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit to FastLED/fbuild that referenced this pull request May 13, 2026
…CC platforms (#245)

GCC emits .eh_frame unwinding tables by default. On a stock FastLED
ESP32-S3 Blink build this is ~225 KB / 36% of the firmware -- dead
metadata no _Unwind_* API ever consumes when exceptions and panic
backtrace are both off. FastLED's library-side pragma workaround
(FastLED/FastLED#2423) is a no-op on modern GCC (audited in
FastLED/FastLED#2473); the only reliable fix is cc1-level flags, which
is the build system's job.

This PR adds a shared eh_frame strip policy that injects
`-fno-asynchronous-unwind-tables -fno-unwind-tables` to every TU when
appropriate. The decision respects user intent at every layer:
explicit env override, debug builds, `-fexceptions` in build_flags,
ESP-IDF panic-backtrace / gdbstub / ocdaware / optimization-debug
sdkconfig keys.

New modules
- `crates/fbuild-build/src/eh_frame_policy.rs` -- pure `decide()`
  function over plain inputs, plus `STRIP_FLAGS` constant. 16 unit
  tests cover the full precedence matrix.
- `crates/fbuild-build/src/eh_frame_policy_compute.rs` -- orchestrator-
  side helper that reads env vars + extracts BuildContext fields and
  calls `decide()`.
- `crates/fbuild-config/src/sdkconfig.rs` -- minimal sdkconfig parser
  surfacing the 4 keys the policy reads. Defaults to ESP-IDF Arduino
  defaults (`panic_print_backtrace = true`) so the safe assumption for
  an unmodified project is Preserve. 14 unit tests.

Per-platform wiring
- ESP32, generic ARM (STM32/RP2040/NRF52), Teensy, ESP8266, AVR each
  get a `with_eh_frame_policy()` setter and a 3-line append in
  `common_flags()`. Mirrors the existing `with_build_unflags` pattern.
- All orchestrators (esp32, generic_arm, teensy, esp8266, avr, stm32,
  rp2040, apollo3) compute the policy once per build and pass it to
  each compiler construction site. ESP32 also reads sdkconfig from the
  project dir. Other platforms pass `None`.
- 10 new platform unit tests (2 per platform) assert STRIP_FLAGS
  presence under `Strip` and absence under default `Preserve`.

Integration test (`#[ignore]`, toolchain-required)
- `crates/fbuild-build/tests/eh_frame_strip_esp32.rs` builds a tempfile
  ESP32 project twice (FBUILD_KEEP_EH_FRAME=1 vs FBUILD_STRIP_EH_FRAME=1)
  and asserts firmware.bin delta >= 150 KB plus `.eh_frame` ELF section
  delta >= 50 KB via the `object` crate.

User-facing overrides
- `FBUILD_STRIP_EH_FRAME=1` -- force strip regardless of detection
- `FBUILD_KEEP_EH_FRAME=1` -- force preserve

Behavior under defaults
- ESP32 with stock Arduino framework: Preserve (matches user
  expectation of esp32_exception_decoder showing readable backtraces).
- Teensy / STM32 / RP2040 / NRF52 / ESP8266: Strip (their JSON configs
  already ship `-fno-exceptions`; nothing in their toolchain consumes
  eh_frame). Immediate flash savings on every release build.
- AVR: Strip wired for uniformity; runtime is a no-op because AVR-gcc
  only emits eh_frame when `-fexceptions` is on, which AVR's JSON
  disables.
- Debug builds (`build_type = debug`, or `-Og`/`-O0` flags) always
  Preserve, even on platforms that would otherwise strip.

Test coverage
- 16 eh_frame_policy unit tests (decision matrix)
- 14 sdkconfig unit tests (parser + project-dir lookup)
- 10 per-platform compiler tests (STRIP_FLAGS presence/absence)
- 1 integration test (`#[ignore]`, runs locally with ESP32 toolchain)
- Existing 534 fbuild-build + 120 fbuild-config lib tests stay green.

Closes #243.
Closes #244.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/no-unwind-esp32-2421 branch May 30, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants