Skip to content

Propagate eh_frame strip policy to ARM Cortex-M / Teensy / RISC-V GCC targets (follow-up to #243) #244

Description

@zackees

Follow-up to #243 (ESP32: auto-strip .eh_frame when exception handling and panic backtrace are both off).

#243 lands the policy + decision function + flag injection in the ESP32 compiler path only. The same -fno-asynchronous-unwind-tables -fno-unwind-tables pair is a win on every GCC-based embedded target where C++ exceptions and platform-level backtrace are both off — which is most of fbuild's matrix. This ticket tracks propagating that machinery uniformly.

Why this is its own issue

The decision function eh_frame_policy::decide() from #243 is platform-neutral (its inputs are build_flags, build_unflags, profile, env vars, plus an optional platform-specific summary like SdkConfigSummary). The wiring into each per-platform compiler is platform-specific. Splitting them keeps #243's PR small and lets #243 prove out the savings on one platform before fanning out.

Platforms in scope

PlatformCompiler crateNotes
Generic ARM Cortex-M (STM32, RP2040, NRF52)crates/fbuild-build/src/generic_arm/arm_compiler.rsMost users have no exceptions and no fault-handler unwind; expected savings comparable to ESP32 per-TU.
Teensycrates/fbuild-build/src/teensy/teensy_compiler.rsTeensy 4.x has reasonable RAM, but flash is still a savings target. Teensy 3.0/LC are RAM-constrained and benefit any code-size cut indirectly.
ESP8266crates/fbuild-build/src/esp8266/* (if present)Same xtensa-gcc flag semantics as ESP32.
AVRcrates/fbuild-build/src/avr/*Probably out of scope. AVR-gcc emits .eh_frame only when exceptions are enabled, which fbuild's AVR config disables by default. Audit first; skip if zero impact.
WASMn/aDifferent unwind model; not GCC. Out of scope.

Plan

  1. Wait for ESP32: auto-strip .eh_frame when exception handling and panic backtrace are both off (~225 KB savings on FastLED Blink) #243 to merge and confirm:

    • The decision function (crates/fbuild-build/src/esp32/eh_frame_policy.rs) is a pure function over plain inputs.
    • Tests cover the matrix (Preserve / Strip per trigger).
    • Integration test asserts ≥ 150 KB savings on ESP32-S3 NEOPIXEL Blink.
  2. Hoist the decision function up out of esp32/ into a shared module (likely crates/fbuild-build/src/eh_frame_policy.rs or a small fbuild-build-policy sub-module). The inputs stay generic; the per-platform extras (sdkconfig for ESP32, possibly Teensy usb_type/board config for Teensy) plug in as an optional trait or as a &dyn PlatformPolicyHints.

  3. Per platform, wire the policy into the existing common_flags() (or equivalent) method:

    • generic_arm/arm_compiler.rs
    • teensy/teensy_compiler.rs
    • esp8266/* (if applicable)
  4. Per platform, add an integration test mirroring the ESP32 one: build a tiny canonical sketch, assert binary-size delta. Use the same object-crate .eh_frame section-size diagnostic from ESP32: auto-strip .eh_frame when exception handling and panic backtrace are both off (~225 KB savings on FastLED Blink) #243 so failure messages stay informative.

  5. Document in the same fbuild docs page ESP32: auto-strip .eh_frame when exception handling and panic backtrace are both off (~225 KB savings on FastLED Blink) #243 created (docs/.../size-optimization.md or similar). One table of supported platforms, defaults, and overrides.

Decision policy — same as #243

Preserve eh_frame if ANY of:
- build_flags contains `-fexceptions` or `-funwind-tables`
or `-fasynchronous-unwind-tables`
- debug profile (-Og / -O0 / !NDEBUG)
- FBUILD_KEEP_EH_FRAME=1
- (platform-specific) backtrace / fault-decoder enabled in platform config
Strip otherwise (default for release builds with no override).

The platform-specific hint is what differs:

Estimated impact

The ESP32 measurement (#243) shows ~225 KB savings on FastLED Blink with full propagation. Per-platform numbers will be smaller because the framework cores are smaller, but the ratio is roughly the same (~30 % of release-build size is .eh_frame for an exception-handling-disabled C++ library).

Rough projections, to be validated against the integration test:

PlatformCanonical exampleExpected savings
STM32F1 (stm32f103c8)FastLED Blink40–80 KB
RP2040FastLED Blink60–120 KB
Teensy 4.1FastLED Blink100–180 KB
Teensy 3.0 / LCFastLED Blinksmall absolute, may unblock the RAM overflow tracked in FastLED/FastLED#2406

Acceptance

Out of scope

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions