Repository navigation
Description
Symptom
On AVR (and likely any framework-rich Arduino target), an empty FastLED Blink sketch built with fbuild is ~11% larger than the same sketch built with PlatformIO. On attiny85:
| Backend | Flash text + data (bytes) | Hex file (bytes) |
|---|---|---|
| platformio | 3386 | 9554 |
| fbuild | 3728 | 10511 |
| delta | +342 (+10.1%) | +957 |
The delta is large enough that FastLED's attiny85_binary_size workflow's max_size: 9500 Apa102 budget is starting to come under pressure on otherwise-innocent commits.
Root cause (confirmed via symbol diff)
The entire 342-byte delta is three symbols from Tone.cpp in the ATtinyCore framework that are present only in the fbuild ELF:
| # | Symbol | fbuild | platformio | Source |
|---|---|---|---|---|
| 1 | __vector_3 |
206 B | weak/default (absent) | framework-arduino-avr-attiny's Tone.cpp |
| 2 | __vector_1 |
90 B | weak/default (absent) | Tone.cpp |
| 3 | noTone (+.part.0) |
50 B | absent | Tone.cpp |
| total extra | 346 | 0 | matches text delta to within link-time padding |
All other ~1,500 symbols are byte-identical between the two builds.
Why are they in fbuild and not in PlatformIO?
PlatformIO archives the framework core into libFrameworkArduino.a and passes that archive to the linker. The linker only pulls archive members whose strong symbols are referenced. FastLED's Blink doesn't call tone(), so Tone.cpp.o is not referenced and is silently dropped. Confirmed in PIO's firmware.map, line 1:
Archive member included to satisfy reference by file (symbol)
fbuild instead links all framework .o files directly as inputs (visible under .build/pio/<board>/.fbuild/build/<board>/release/core/Tone_<hash>.cpp.o, no .a produced). Direct .o inputs are always kept by the linker — section-GC (-ffunction-sections -fdata-sections -Wl,--gc-sections, which fbuild does pass) doesn't help because the ISRs __vector_1 / __vector_3 are reachable from the AVR interrupt vector table. They override AVR libc's weak __vector_default, get linked in, and drag noTone and its static state along for the ride.
The mechanism is hard to fix at the user's source level — the symbols are reachable. The fix has to be at the link-input shape: archive the framework objects so unreferenced ones are dropped by archive-member-selection rules before the vector table sees them.
Reproduction (FastLED master @ 064354e6ea)
# Get worktree, fall through to fbuild defaults
cd FastLED
bash compile attiny85 --examples Blink # backend=fbuild (default)
ls -l .build/pio/attiny85/.fbuild/build/attiny85/release/firmware.elf
avr-size .build/pio/attiny85/.fbuild/build/attiny85/release/firmware.elf
bash compile attiny85 --examples Blink --backend platformio
ls -l .build/pio/attiny85/.pio/build/attiny85/firmware.elf
avr-size .build/pio/attiny85/.pio/build/attiny85/firmware.elf
# Diff symbols
avr-nm --size-sort --print-size \
.build/pio/attiny85/.fbuild/build/attiny85/release/firmware.elf > /tmp/fb.syms
avr-nm --size-sort --print-size \
.build/pio/attiny85/.pio/build/attiny85/firmware.elf > /tmp/pio.syms
diff /tmp/pio.syms /tmp/fb.syms # ← shows __vector_1, __vector_3, noToneProposed fix
Archive framework core objects into libFrameworkArduino.a before passing them to the linker, matching PlatformIO's behavior. Equivalent shape:
avr-ar rcs libFrameworkArduino.a core/*.o variants/*.o ...
avr-gcc <other objects> -L<dir> -lFrameworkArduino -Wl,--gc-sections -o firmware.elf
Acceptable alternatives that achieve the same effect:
- Pass framework objects via
-Wl,--exclude-libssemantics so unreferenced ones don't impose dependencies. - Two-pass link: first pass with
-Wl,--no-whole-archivefor framework, second pass adds anything that pulled in symbols from the framework. (Not worth the complexity vs. just making an archive.) - Static analysis of framework sources to identify objects whose only strong symbols are weak-overridable ISRs, and exclude those when not referenced. (Brittle.)
Option 1 (the canonical Arduino-build pattern) is the recommendation. Should localize to whatever crate emits link inputs for the Arduino/AVR target.
Why this matters broadly
The same shape will hit any Arduino-framework target where the framework ships .cpp files that define weak-overridable ISR symbols. Probable also-affected (untested in this report but worth checking):
- AVR:
uno,nano,attiny*—Tone.cpp,HardwareSerial1.cpp/HardwareSerial2.cpp/etc. (vector pull-ins for unused UARTs) - Teensy 3.x / LC:
serialEvent*, audio library entry points - STM32 (bluepill): HAL IRQ handlers
- ESP32: probably masked by larger overall binary size and IDF framework already shipping as
.a, but worth diff-checking
The attiny85 reproduction is the cleanest because the framework is small enough that 340 bytes shows up as 10% — but the absolute byte savings should be similar or larger on Teensy 3.x and STM32.
Test plan
- Cargo test of the new link-input emitter: assert that for a "core_with_isr.cpp" fixture (defines
__vector_5andnoTone), an Arduino-style link without any reference totone()produces an ELF with zero bytes from that file. - Integration test in fbuild's own CI: compile FastLED
examples/Blinkforattiny85and asserttext + data <= 3450bytes (PIO baseline + 64 byte slack). - FastLED-side: revert the
--backend platformioworkaround that the size-check workflow will get (coming in a parallel FastLED PR) and confirmattiny85_binary_sizestays green.
Related
- fbuild deficiency vs PlatformIO: no build_info.json metadata emitter (blocks downstream size/symbol tooling) #297 — missing
build_info.jsonemitter. Different bug, same surface. Both compound to make this regression invisible in CI for a month. - FastLED downstream workaround: FastLED's
.github/workflows/build_template_binary_size.ymlwill be patched to force--backend platformiofor size checks while this lands.
Filed during a coordinated CI-green sweep on FastLED master. Detailed symbol-level diff available on request — every byte of the 342-byte delta is accounted for above.
Activity
ci(size): pin binary-size checks to --backend platformio (unblock mas…
zackees commentedon May 30, 2026
Implementation plan (after reading the relevant fbuild source)
Tracing through the code to confirm exactly where to fix:
`crates/fbuild-build/src/pipeline/sequential.rs:229` — `core_objects.extend(library_objects);` concatenates framework core, variant, and local-library `.o` files into a single `Vec`.
`crates/fbuild-build/src/pipeline/sequential.rs:235-248` — passes that vec as the `archives` parameter to `Linker::link_all` / `Linker::link`.
`crates/fbuild-build/src/avr/avr_linker.rs:93-97` — the AVR `link` impl, despite the parameter being named `archives`, iterates and passes each as a raw positional arg:
```rust
// Core objects passed directly (not archived) for LTO compatibility
// Python fbuild does the same: archive breaks LTO symbol visibility
for archive in archives {
args.push(archive.to_string_lossy().to_string());
}
```
So the `.o` files end up as direct linker inputs, not archive members. The comment cites LTO compatibility, but:
```rust
// Use gcc-ar for LTO archives so the linker-plugin index is written.
let lib_ar_path = pipeline::pick_archiver(&ar_path, &gcc_ar_path, &c_flags, &cpp_flags);
```
Recommended patch shape
Two reasonable options, both small (~30 lines):
Option A — fix at the AVR linker boundary (minimal blast radius)
In `crates/fbuild-build/src/avr/avr_linker.rs::link()`:
The current LTO concern is satisfied because gcc-ar writes the plugin index. The existing comment on lines 93-94 should be updated to:
```
// Archive framework + library objects into libframework.a so the linker
// only pulls in members whose strong symbols are referenced. This prevents
// unused ISRs (Tone.cpp __vector_1/__vector_3 on AVR) from being dragged
// in via weak-symbol override of __vector_default. Use gcc-ar when LTO is
// enabled to preserve the linker-plugin index.
```
Pro: contained to AVR. No risk to Teensy/RP2040/STM32/etc. Aligns AVR behavior with PlatformIO exactly.
Con: each `avr_linker.rs::link` call now incurs ~30 ms of `ar` runtime. Negligible vs. compile+link total.
Option B — fix at the pipeline boundary (broader applicability)
In `crates/fbuild-build/src/pipeline/sequential.rs` between lines 229 and 235, take `core_objects` and run `linker.archive(&core_objects, &ctx.build_dir.join("libframework.a"))?` before passing it down. Then `core_objects = vec![framework_archive];`.
Pro: every platform that goes through `run_sequential_build_with_libs` benefits (Teensy, RP2040, STM32, NRF52, SAM, Renesas, Apollo3, CH32V, ESP8266). Likely smaller binaries everywhere.
Con: needs validation on each of those platforms (and they all have their own `Linker` impls — `archive()` must be functional on all). For platforms whose frameworks already ship as `.a` (none in this list AFAICT), this changes nothing.
I'd recommend Option A first as a 2-hour fix that nails AVR, then a follow-up sweep for Option B once Teensy / STM32 fixtures exist in fbuild's test matrix to catch any regressions.
Acceptance test (to add to fbuild's test suite)
```rust
#[test]
fn attiny85_blink_size_under_pio_baseline_plus_64b() {
// Reference: PlatformIO produces 3386 bytes flash for the same source.
// 64B slack covers padding/alignment differences from any future
// toolchain bump.
let result = build_fixture("attiny85", "blink").unwrap();
assert!(
result.size_info.unwrap().total_flash <= 3450,
"AVR Blink size regression — Tone.cpp ISR pull-in may be back"
);
}
```
My environment limitation
I have the repo cloned and reviewed but don't have the full soldr + Rust 1.94.1 toolchain set up locally on this Windows box (and the hook discipline in this repo correctly blocks bare `cargo` invocations). Happy to file a PR if a maintainer can confirm Option A is the preferred direction, or I can spin up the dev env if the answer is "just send the PR."
In the meantime, FastLED master is unblocked via FastLED PR #2602 (pending) which routes the size-check workflows back through PlatformIO. Easy revert once this lands.
feat(debug): print link command on -v + always emit firmware.map (fixes
fix(avr): archive framework objects with gcc-ar (fixes #304)
fix(avr): archive framework objects with gcc-ar (fixes #304)
fix(avr): archive framework objects with gcc-ar (fixes #304) (#306)
ci: bump setup-soldr v0.9.24 → v0.9.35 (#333)