Repository navigation
feat(fl/stl): add FL_NO_UNWIND macros, apply to ESP32 unity headers - #2423
Conversation
📝 WalkthroughWalkthroughAdds a configurable "no unwind" macro family ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/fl/stl/compiler_control.h (1)
252-270: 💤 Low valueConsider using
#ifndefguards to avoid potential macro redefinition warnings.Multiple conditions can define
_FL_BUILD_WANTS_BACKTRACEto 1, which works but may trigger-Wmacro-redefinedwarnings on strict compiler settings. Using#ifndefguards 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
📒 Files selected for processing (3)
src/fl/stl/compiler_control.hsrc/platforms/esp/32/_build.cpp.hppsrc/platforms/esp/32/drivers/_build.cpp.hpp
d9ebddd to
9c70fda
Compare
|
The new binary size for the example code from #2420 with |
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]>
9c70fda to
21a71a3
Compare
Refactored macro structure for robustness + user overrideForce-pushed (PR still one commit, What's new
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
#endifTests added
Verification
Net diff vs prior PR versionMacros header grew (more comments + the cleaner two-stage structure); test coverage added for the new behaviors. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/fl/stl/compiler_control.cpp (1)
816-819: ⚡ Quick winUse 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
📒 Files selected for processing (4)
src/fl/stl/compiler_control.hsrc/platforms/esp/32/_build.cpp.hppsrc/platforms/esp/32/drivers/_build.cpp.hpptests/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
…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]>
…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]>
Summary
Adds
FL_NO_UNWIND/FL_NO_UNWIND_BEGIN/FL_NO_UNWIND_ENDmacros 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) showedlibFastLED.acontributing 180 KB of.eh_frame— half of the entire.flash.rodatasection. A direct count of FDE entries showed:--gc-sectionsstrips dead virtual-dispatch code but fails to cull the corresponding.eh_frameentryFull breakdown: #2421 (comment)
FL_NOEXCEPTdoes not suppress this —noexceptis a language contract,.eh_frameis 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 existingFL_DISABLE_WARNING_PUSH/POPandFL_BEGIN_OPTIMIZE_FOR_EXACT_TIMINGblockssrc/platforms/esp/32/_build.cpp.hpp(+5): wrap entire unity TU withFL_NO_UNWIND_BEGIN/_ENDsrc/platforms/esp/32/drivers/_build.cpp.hpp(+5): sameGating 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,!NDEBUGESP32 sdkconfig (only when
FL_IS_ESP32is defined):CONFIG_ESP_SYSTEM_PANIC_PRINT_BACKTRACE(ESP-IDF default ON)CONFIG_ESP_SYSTEM_PANIC_GDBSTUBCONFIG_ESP_DEBUG_OCDAWARECONFIG_COMPILER_OPTIMIZATION_DEBUG/CONFIG_COMPILER_OPTIMIZATION_NONEArduino-ESP32 verbosity:
CORE_DEBUG_LEVEL >= 3User 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_TABLESinbuild_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
???inesp32_exception_decoderoutput. 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.hand not a newcodegen.hThe original spec proposed
src/fl/stl/codegen.h, butsrc/fl/stl/compiler_control.halready 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 alsono-asynchronous-unwind-tables-fno-unwind-tablesis 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 optimizeis 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 toFL_IS_GCCkeeps clang builds clean.Verification
bash lint— cleanbash 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)toolchain-xtensa-esp-elfTest plan
-DFASTLED_FORCE_NO_UNWIND_TABLESand confirm ~180 KB savingsChannel::showPixelsin default mode (backtrace should be intact) and in opt-in mode (frame should show???, downstream frames should still resolve)-DFASTLED_FORCE_NO_UNWIND_TABLESinbuild_flagsand report the new binary sizeWhat this does NOT fix
This PR addresses ONE half of #2421 (the binary bloat). It does NOT fix:
show()vTaskDelay(1)timing regression (separateFASTLED_TIGHT_TIMINGproposal in [Tracking] ESP32-S3 timing regression + binary bloat from Channel API (from #2420) #2421)_build.cpp.hpp(per-driver feature gates, ~125 KB more savings)fl.audio/fl.remote/fl.net/fl.fx/fl.gfxfor one symbol each (will be a follow-up issue)Those land in subsequent PRs against #2421.
🤖 Generated with Claude Code
Summary by CodeRabbit
Chores
Tests