Skip to content

fix(shrink): disclose the measured newlib-nano formatting gap (ESP32-S3 A/B) - #1884

Merged
zackees merged 3 commits into
mainfrom
agent/1459-hw-validation
Nov 4, 2026
Merged

zackees merged 3 commits into
mainfrom
agent/1459-hw-validation

Conversation

@zackees

@zackees zackees commented Nov 4, 2026

Copy link
Copy Markdown
Member

What

--shrink=printf on ESP32/Xtensa is measured to change what a sketch prints
for five length modifiers. Until now that only lived in prose ("nano has no
wide-char or long-double support"), which was incomplete and unverified. This
change makes the gap measured, single-sourced, and visible at build time:

  • new printf_thin::UNSUPPORTED_CONVERSIONS — the exact measured set, with the
    hardware evidence in its doc comment: %lld %llu %llx %zu %hh*;
  • new printf_thin::divergence_warning() — one always-visible line pushed to
    the build log (and tracing::warn!) at the moment resolve_shrink claims the
    reducer, naming those conversions and the --no-shrink escape hatch;
  • shrink/README.md — the on-device A/B table and the divergence list replace
    the un-measured sentence;
  • the battery-suite doc now records the measured answer (failed=0 unshrunk vs
    failed=6 shrunk), so nobody reads that battery as a pass/fail gate under
    nano.

No behavioural change to the reducer itself: same spec file, same
-Wl,-u,_printf_float, same record_for. Auto still resolves to Off
everywhere.

Why (measured on real hardware, not inferred)

Self-checking battery (crates/fbuild-build/tests/it/esp32_shrink_printf.rs,
36 cases, each compared against its literal expectation) flashed on the attached
ESP32-S3 (Xtensa LX7, xtensa-esp32s3-elf 8.4.0, espressif32 6.13.0,
Arduino core 3.3.12), same source, build dirs fresh, one flag flipped:

image flash serial verdict
--no-shrink (control) 358,903 B BATTERY total=36 failed=0
--shrink=printf 335,875 B (−23,028 B, −6.4 %) BATTERY total=36 failed=6

Verbatim failures from the shrunk image:

FAIL "%lld", -9223372036854775807LL got='ld'  n=20 want='-9223372036854775807'
FAIL "%llu", 18446744073709551615ULL got='lu' n=20 want='18446744073709551615'
FAIL "%llx", 0xDEADBEEFCAFEF00DULL   got='lx' n=16 want='deadbeefcafef00d'
FAIL "%hhu", (unsigned char)200      got='hu' n=3  want='200'
FAIL "%zu",  sizeof(size_t)          got='zu' n=1  want='4'
FAIL vsnprintf                       got='0002.500|ld' n=11 want='0002.500|9000000000'
BATTERY total=36 failed=6

This is the vendor's formatter, not a missing flag: the toolchain's
libc_nano.a exports _printf_float (which is why %f/%e/%g still pass) and
has no _printf_long_long to link, so 64-bit / size_t / hh formatting
cannot be restored by another -u. Symbol sizes confirm the swap itself is
exactly as designed (_vfprintf_r 11,413 B → 698 B, _svfprintf_r 11,222 B →
624 B, measured with the toolchain's own nm).

Consequence for the open policy question

Auto must stay Off: a ~23 KB saving that silently mangles a 64-bit counter
is a bad default. That is now a measured conclusion rather than a pending
experiment, and the build log says so instead of leaving it to the docs.

Validation

  • soldr cargo test -p fbuild-build-esp --lib printf_thin — 7 passed, 0 failed.
  • soldr cargo test -p fbuild-build-esp --lib shrink_link::tests — 5 passed,
    0 failed
    (new applied_notice_pairs_the_claim_with_the_measured_disclosure
    pins that the claim and the disclosure are emitted as a pair, so "we shrank
    your image" cannot reach the log without "and these five conversions
    changed").
  • Behavioural RED for the divergence test: with UNSUPPORTED_CONVERSIONS
    emptied, --lib printf_thin is 6 passed, 1 failed —
    assertion 'left == right' failed: the list is the source of truth for the build-time warning
    (printf_thin_tests.rs:84). Restored → 7 passed.
  • soldr cargo fmt --check rc 0.
  • soldr cargo clippy -p fbuild-build-esp --all-targets -- -D warnings rc 0,
    minus -A unfulfilled_lint_expectations for one pre-existing expectation
    on origin/main (crates/fbuild-core/src/usb/data.rs:193,
    usb::data::try_install_online_cache's cognitive_complexity) which is
    unfulfilled with this host's clippy; untouched by this diff
    (git diff --stat origin/main -- crates/fbuild-core is empty).
  • uv run --no-project python ci/check_test_layout.py — 8 categories, no stray
    test binaries.
  • Hardware: 2 builds + 2 flashes + 2 serial captures on the attached ESP32-S3
    (/dev/ttyACM1, ser=d8:3b:da:41:64:c0), quoted above.

Note on scope of the log proof: the emitted line is covered by unit tests
(pure applied_notice), not by an end-to-end daemon run — fbuild spawns the
fbuild-daemon provisioned by the installed tool, so a worktree build exercises
the installed daemon's copy of this code.

Refs #1459.

`--shrink=printf` on ESP32/Xtensa swaps the full newlib formatter for
newlib-nano, which changes what a sketch PRINTS for five length modifiers.
The old docs claimed only "no wide-char or long-double support" — measured on
an ESP32-S3 it is broader than that.

Battery (tests/it/esp32_shrink_printf.rs, 36 self-checking cases) flashed on
the attached ESP32-S3, xtensa-esp32s3-elf 8.4.0 / espressif32 6.13.0:

  --no-shrink   358,903 B flash   BATTERY total=36 failed=0
  --shrink=printf 335,875 B (-23,028 B, -6.4%)   BATTERY total=36 failed=6

All six are one class: %lld %llu %llx %zu %hh* print the length modifier
instead of the value ("ld", "zu", "hu"), because libc_nano.a exports
_printf_float and nothing equivalent for 64-bit integers (there is no
_printf_long_long to -u). The swap itself is exact: _vfprintf_r 11,413 ->
698 B, _svfprintf_r 11,222 -> 624 B.

So: UNSUPPORTED_CONVERSIONS is the single measured source of truth,
divergence_warning() renders it, and the applied reducer now emits the claim
and that warning as one pair via the pure applied_notice(), so a shrunk build
cannot claim the reducer silently. README gets the on-device A/B table in
place of the un-measured sentence; the battery doc records that under nano it
is a divergence detector, not a pass/fail gate. Auto stays Off — now on
evidence rather than pending measurement.

Refs #1459
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

The applied-notice loop added a nested branch and took the function to
26/25. Invert the nano.specs probe to an early return so the loop sits at
function top level; behaviour and log order are unchanged.
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 4, 2026
…hrink

CI clippy (1.95) counts resolve_shrink at 26/25, and the cognitive-complexity
gate is workspace-wide. Split the architecture gate + probe + notice into
apply_printf_shrink so each half answers one question ('is this mode for this
platform?' vs 'can this toolchain shrink, and what must the user know?').
No behaviour change: same record, same flags, same log order.
@zackees
zackees added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit 29b37a1 Nov 4, 2026
38 checks passed
@zackees
zackees deleted the agent/1459-hw-validation branch November 4, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant