Skip to content

LPC845 bloat: 8.3 KB of soft-FP / integer-div leaks past the no-soft-FP invariant on LowMemory + RX_SCT_WS2812 #3076

Closed

Description

@zackees

2026-06-15 revision: original numbers in this issue came from a flawed map-parser methodology (see retraction comment on #3075 / #3078). Issue body now reflects real arm-none-eabi-nm --print-size data on the ELF. Substance of the bug is confirmed and bigger than originally reported.

Symptom

Despite the FL_PLATFORM_HAS_LARGE_MEMORY == 0 "no soft-FP" invariant intended for Low-memory targets, the LPC845 LowMemory + FASTLED_LPC_RX_SCT_WS2812=1 link pulls in 8,332 bytes of libgcc/libc soft-FP and integer-division routines from the cortex-m0plus nofp newlib variant (arm-none-eabi/lib/thumb/v6-m/nofp/).

Real nm breakdown:

Symbol Bytes
__aeabi_dadd (double add) 2,088
__aeabi_dmul (double mul) 1,392
__aeabi_fsub (float sub) 1,172
__aeabi_fadd (float add) 1,110
__clzdi2 (64-bit count-leading-zeros) 860
__aeabi_fmul (float mul) 660
__aeabi_fdiv (float div) 556
Others (smaller __div* / __fix* / __float*) ~500
Total ~8,300

LPC845 has no FPU. Any double arithmetic in a reachable code path costs 30 to 80 times more flash than an integer equivalent. The __aeabi_dadd + __aeabi_dmul pair alone (~3.5 KB) is more than the entire base LowMemory sketch.

Why this is surprising

This is exactly the invariant #3022 / #3038 / #3000 were supposed to enforce. We have a centralized FL_PLATFORM_HAS_LARGE_MEMORY macro and a documented link-symbol check (src/platforms/arm/lpc/README.md). Either:

  • The link-symbol check is not being run for the RX_SCT_WS2812 config (it may be only checked for the base LowMemory config), OR
  • Something in <FastLED.h> or its transitive headers has a double literal in a reachable code path that the soft-FP guard did not catch.

Suspects to chase

  1. fl::ieee754_format_decimal (594 B) + fl::ieee754_parse_decimal (482 B) + fl::kPow10Mant LUT (824 B) — the JSON number formatter/parser uses a manual IEEE-754 decimal path that should be int-only, but if any reachable code path lifts to float or double it'd pull the soft-FP cascade.
  2. The fl::json float-coercion path (fl::json::as_float()) — should be int-tagged via #3022 but the test-config delta matters; verify it stays out of the link when only int-typed RPC methods are registered.
  3. Any header transitively pulled by <FastLED.h> that has a static constexpr double or static const float constant in an inlined function.

Repro

Build LPC845 with -DFASTLED_LPC_RX_SCT_WS2812=1. Until FastLED/fbuild#594 lands, this requires hand-patching the LD script:

# Bump LENGTH from 64K to 128K in:
~/.fbuild/prod/cache/platforms/zackees-ArduinoCore-LPC8xx/.../lpc845_flash.ld

PLATFORMIO_SRC_DIR=examples/AutoResearch fbuild build -e lpc845brk

# Then run nm --print-size on the resulting ELF:
arm-none-eabi-nm --print-size --demangle .fbuild/build/lpc845brk/release/firmware.elf | \
  grep -E '__aeabi_[fdiu]|__[afsmd][udl][bd]df|__div|__floatsi|__fix|__clz'

Acceptance

  • arm-none-eabi-nm firmware.elf reports zero references to __aeabi_dadd, __aeabi_dsub, __aeabi_dmul, __aeabi_ddiv and less than 1 KB combined for the float variants for the LPC845 LowMemory + RX_SCT_WS2812 config
  • The link-symbol guard test is extended to cover this config (not just the base LowMemory build)
  • Documented in src/platforms/arm/lpc/README.md which nm invocation is the canonical guard

Related

Activity

  1. zackees commented on Jun 15, 2026

    @zackees
    MemberAuthor

    Tracked under meta #3079 (LPC845 64 KB flash bloat hunt) alongside three sibling bloat sub-issues and the FastLED/fbuild#594 tooling-gap dependency.

  2. changed the title [-]LPC845 bloat: ~5 KB of double-precision soft-FP leaks past the no-soft-FP invariant[/-] [+]LPC845 bloat: 8.3 KB of soft-FP / integer-div leaks past the no-soft-FP invariant on LowMemory + RX_SCT_WS2812[/+] on Jun 15, 2026
  3. zackees commented on Jun 15, 2026

    @zackees
    MemberAuthor

    Issue body and title revised 2026-06-15 with real nm --print-size data. Now part of revised meta #3079 sub-issue set: {#3076 soft-FP, #3077 variant, #3081 RPC dispatch, #3082 JSON codec}. Two earlier sub-issues #3075 #3078 closed as filed-in-error.

  4. zackees commented on Jun 15, 2026

    @zackees
    MemberAuthor

    Investigation findings (2026-06-15)

    Ran arm-none-eabi-nm --print-size --demangle on the LPC845 ELF (built with FLASH region temporarily relaxed to 128 KB so the link succeeds) and traced the soft-FP cascade.

    Not the culprit (DCE'd cleanly)

    • fl::json::as_double() and fl::json_value::as_double() — not present in the linked binary. class json's in-header inline definitions get DCE'd when nothing calls them.
    • fl::float_conversion_visitor<double> — not instantiated.
    • fl::int_conversion_visitor<int>::operator()(const double&) — the "dead-code-by-design" overload at src/fl/stl/json/types.h:281 is not reachable in the link.

    Actually reachable visitor instantiations on this build

    SizeVisitor
    SerializerVisitor                  <- prime suspect
    JsonToIntegerVisitor<int>
    IsArrayVisitor
    

    SerializerVisitor walks the variant to emit a JSON string. For the float alternative it calls fl::ieee754_format_decimal (594 B in the binary) which depends on the fl::kPow10Mant LUT (824 B rodata). That's the float formatting path.

    Why double soft-FP is still present

    The single-precision soft-FP helpers (__aeabi_fadd, __aeabi_fsub, __aeabi_fmul, __aeabi_fdiv) on the cortex-m0plus nofp newlib variant internally call double soft-FP for some operations. Specifically, __aeabi_fadd and __aeabi_fsub use the __addsf3/__subsf3 paths that share infrastructure with __adddf3/__subdf3 in libgcc's softfp.h. Linking any float operation transitively pulls __aeabi_dadd (2,088 B) and friends.

    This explains why simply auditing for double literals in C++ source doesn't help — the leak comes from libgcc's internal float-via-double implementation, not from user-level double usage.

    Real fix paths

    This is more invasive than originally scoped. Three viable approaches:

    1. Drop the float alternative from json_value::variant_t on Low-memory targets. Replaces the variant with a 9-alternative version that has i64, string, array, object, vector<i16>, vector<u8>, vector<float> (still has the byte-array one — would need a sibling decision) but no scalar float. Removes the SerializerVisitor::operator()(const float&) and ieee754_format_decimal paths from the link.
    2. Replace ieee754_format_decimal with an integer-only fixed-point decimal formatter on Low-memory. Loses precision for large floats but avoids the soft-FP path. Costs ~1 KB rodata for the integer-decimal multipliers.
    3. Investigate which specific __aeabi_f* operations are reachable and whether using LLVM compiler-rt instead of libgcc would avoid the internal double dependencies. Toolchain-level change; out of scope here.

    Scope honesty

    Original acceptance criteria ("zero references to __aeabi_dadd etc.") was based on the assumption that the fix would be small. The actual fix requires JSON variant surgery (path #1) or a new decimal codec (path #2). Both are 2-3 PR design exercises, not a quick fix.

    Marking this as scoped for design discussion before further PR work. Path #1 is most aligned with the integer-only LPC8xx RPC contract; #2 is more generally useful but bigger.

  5. added a commit that references this issue on Jun 15, 2026
    608798a
  6. added a commit that references this issue on Jun 15, 2026
    370a840
  7. moved this from Triage to Done in FastLED Trackeron Jun 15, 2026
  8. added a commit that references this issue on Jun 15, 2026
    81bcaf3
  9. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Concrete bloat numbers from the LPC845-BRK LowMemory build today

    Investigated as part of the #3102 bench-validation meta, Section 1. Build is examples/AutoResearch/AutoResearch.ino with -DFASTLED_AUTORESEARCH_LOW_MEMORY=1, the LPC8xx low-memory branch. Currently overflows the 64 KB flash budget by 7,472 bytes -- which lines up almost exactly with this issue's 8.3 KB headline and confirms the same root cause.

    How I produced an ELF to measure

    Temporarily expanded the LPC845 linker script's FLASH region from 64K -> 128K (reverted before commit) so the link could complete. Resulting firmware was 71.62 KB / 64 KB (111.9%). RAM was fine: 8.51 KB / 16 KB (53.2%, see ranged-stack caveat at the end).

    Then ran fbuild symbols firmware.elf for a sized symbol table and arm-none-eabi-objdump -dC | awk to chase BL call-graph edges for the soft-FP helpers.

    Top FLASH symbols (text section)

       BYTES  symbol
        3116  fl::Rpc::handle(fl::json const&)
        3012  autoResearchLowMemorySetup()
        2996  fl::Remote::processRpc(fl::json const&)
        2342  fl::(anonymous)::JsonBuilder::on_token(...)
        2196  fl::TypedRpcBinding<fl::string (int, int, int, int)>::invokeWithReturn(...)
        2088  libgcc.a:adddf3.o  -- __aeabi_dadd          <-- soft-FP
        1516  Reset_Handler
        1392  libgcc.a:muldf3.o  -- __aeabi_dmul          <-- soft-FP
        1350  fl::(anonymous)::JsonTokenizer::parse(...)
        1172  libgcc.a:subsf3.o  -- __aeabi_fsub          <-- soft-FP
        1110  libgcc.a:addsf3.o  -- __aeabi_fadd          <-- soft-FP
         660  libgcc.a:mulsf3.o  -- __aeabi_fmul          <-- soft-FP
         556  libgcc.a:divsf3.o  -- __aeabi_fdiv          <-- soft-FP
    

    Soft-FP helpers, total cost

    Helper Bytes Triggered by
    __aeabi_dadd (double add) 2088 indirectly via __aeabi_l2f
    __aeabi_dmul (double mul) 1392 indirectly via __aeabi_l2f
    __aeabi_fsub (single sub) 1172 fl::basic_string::append(float, int)
    __aeabi_fadd (single add) 1110 fl::parseFloat (3x), fl::basic_string::append(float, int)
    __aeabi_fmul (single mul) 660 fl::parseFloat (3x), fl::basic_string::append(float, int)
    __aeabi_fdiv (single div) 556 fl::parseFloat (1x)
    Total 6978

    That's 6,978 bytes of pure libgcc soft-FP, which is ~94% of the 7,472-byte overflow. Eliminate it and the LowMemory build fits 64 KB with ~500 bytes of margin.

    Call-graph entry points (from objdump -dC)

    Concrete entry points pulling in the soft-FP chain:

    fl::parseFloat(char const*, unsigned int)        -- 3 fmul, 3 fadd, 1 fdiv
    fl::json_value::as_int()                          -- fcmplt, fcmpgt, f2iz
    fl::detail::JsonToIntegerVisitor<int>::...        -- fcmpeq, f2iz
    fl::detail::TypedSchemaGenerator<int(int)>::...   -- fcmpeq
    fl::basic_string::append(float const&, int)       -- fsub, fmul, fcmplt, fcmpge, fadd, f2iz
    
    void fl::variant<float, fl::Empty>                -- pulls __aeabi_l2f (which cascades to dadd/dmul/d2f)
    CFastLED::show(unsigned char)                     -- pulls __aeabi_l2f (same cascade)
    

    So the real picture is:

    1. fl::json stores parsed numbers in fl::variant<float, ...>. Even though the AutoResearch RPCs take (int, int, int, int), the variant has a float alternative and its constructor invokes __aeabi_l2f on long-to-float conversion. __aeabi_l2f is implemented in libgcc using double-precision intermediates -- which pulls in __aeabi_dadd (2088 B), __aeabi_dmul (1392 B), and __aeabi_d2f (4 calls). That cascade alone is 3,876 bytes.

    2. fl::parseFloat is invoked from JsonTokenizer::parse when the tokenizer hits a number with a decimal point or exponent. Pulls in __aeabi_fmul, __aeabi_fadd, __aeabi_fdiv directly.

    3. fl::basic_string::append(float, int) is the float-overload of string::append, invoked from fl::sstream::operator<<(float) (probably). The pin-toggle handler does s << static_cast<fl::u32>(n_read) etc -- all integer operands -- but the append(float) overload still gets instantiated via some path I haven't isolated yet.

    4. fl::json_value::as_int() does if (val < INT_MAX && val > INT_MIN) return (int)val against the variant's float branch, hence fcmplt + fcmpgt + f2iz.

    Two concrete fix vectors I see

    Path A -- kill the float branch in fl::variant<float, fl::Empty> on LowMemory targets.

    The cascade of 3876 bytes from __aeabi_l2f -> __aeabi_dmul/dadd/d2f exists because the variant's type list contains float. Even if no LowMemory code path ever stores a float in that variant, the constructor for variant<float, ...>(long) instantiates the long-to-float branch and the linker can't dead-code-eliminate it because it's reachable from RTTI-style template dispatch.

    If fl::variant<float, fl::Empty> were replaced (under a LowMemory or FL_PLATFORM_HAS_TINY_MEMORY=1 guard) with fl::variant<i32, fl::Empty> or similar integer-only alternative, the entire l2f -> double cascade goes away. That's the #3038 follow-up the platformio.ini comment hints at:

    ;   ; -DFASTLED_LPC_RX_SCT_WS2812=1 ; pulls <FastLED.h>, +20 KB, exceeds 64 KB
    ;   ;                                ; flash budget on LPC845-BRK. Re-enable
    ;   ;                                ; once additional flash-budget reduction
    ;   ;                                ; lands (gamma LUT / EngineEvents / etc.).

    Estimated saving: 3,876 + ~1,000 = ~5 KB.

    Path B -- kill the float overloads of fl::basic_string::append and fl::parseFloat on LowMemory.

    parseFloat is called from JsonTokenizer::parse only when a token has a . / e / E. The LowMemory JSON-RPC contract takes integers only (the RPC schema is pinToggleRx: [int, int, int, int]). If parseFloat and the related decimal-parse path were #ifdef-out under FL_PLATFORM_HAS_TINY_MEMORY (with an error-on-decimal-number fallback), we'd save another ~2,500 bytes.

    Same for string::append(float, int) -- LowMemory doesn't need float formatting; the sstream << chain uses only integer operands. Saving: ~1 KB.

    How this maps to FastLED #3079 / #3076 / #3102

    Unrelated side find -- RAM bomb in pinToggleRx

    While in the symbol table I noticed pinToggleRx declares fl::EdgeTime edges_buf[2048]; on the stack. Each EdgeTime is 4 bytes (bitfield + alignment), so that's a 8 KB stack frame on a 16 KB SRAM part. .bss already uses 8.5 KB. The handler will stack-overflow at runtime even if flash fits. Should probably be moved to static storage or down-sized to ~256 entries (~1 KB) for the Phase-1 pin-toggle test.

    Repro / verification

    Method I used (working repro after zccache 1.12.7's namespace fix landed):

    # kill any wedged zccache daemons first
    Get-Process | Where-Object { $_.ProcessName -match "zccache" } | Stop-Process -Force
    
    # expand FLASH temporarily so the link succeeds (revert before commit!)
    $ld = "$HOME\.fbuild\prod\cache\platforms\zackees-ArduinoCore-LPC8xx\*\*\ArduinoCore-LPC8xx-*\linker_scripts\gcc\lpc845_flash.ld"
    (Get-Content $ld) -replace 'LENGTH = 64K', 'LENGTH = 128K' | Set-Content $ld
    
    bash autoresearch lpc845brk --pin-toggle-rx --upload-port COM10
    # build succeeds with overflow noted in log
    # firmware.elf now exists at .fbuild/build/lpc845brk/release/firmware.elf
    
    uv run fbuild symbols .fbuild/build/lpc845brk/release/firmware.elf

    Happy to bundle the full symbol report or run additional teardown if it's useful.

    Filed via Claude Code on behalf of [email protected].

  10. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Validation against current master — bloat fix confirmed working

    Re-tested against today's master (post 4f620ff0d, which includes the bloat-reduction sweep: #3084 / #3085 / #3087 / #3088 / #3089).

    Reproduction case from the issue body:

    bash autoresearch lpc845brk --pin-toggle-rx --upload-port COM10
    

    Before the sweep (recorded in my 19:14 UTC comment): build overflowed 64 KB by 7,472 bytes due to ~7 KB of libgcc soft-FP helpers (__aeabi_dadd, __aeabi_dmul, __aeabi_fadd, __aeabi_fmul, __aeabi_fdiv).

    After the sweep (now): build succeeds at 64 KB flash. Firmware flashes via pyocd, device boots, echo RPC round-trips cleanly through the JSON-RPC pipe. The FASTLED_LPC_RX_SCT_WS2812=1 flag now ships default-on in platformio.ini (per #3089) -- so the original "exceeds 64 KB budget" comment is also retired.

    This issue's symptom is gone. Closure stands.

    Two follow-ups surfaced from the same bench session

    Both are separate concerns from this issue's bloat scope; recording them here so the bench-validation trail in #3102 Section 1 is traceable.

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