Repository navigation
fix(shrink): disclose the measured newlib-nano formatting gap (ESP32-S3 A/B) - #1884
Merged
Merged
Conversation
`--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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
--shrink=printfon ESP32/Xtensa is measured to change what a sketch printsfor 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:
printf_thin::UNSUPPORTED_CONVERSIONS— the exact measured set, with thehardware evidence in its doc comment:
%lld %llu %llx %zu %hh*;printf_thin::divergence_warning()— one always-visible line pushed tothe build log (and
tracing::warn!) at the momentresolve_shrinkclaims thereducer, naming those conversions and the
--no-shrinkescape hatch;shrink/README.md— the on-device A/B table and the divergence list replacethe un-measured sentence;
failed=0unshrunk vsfailed=6shrunk), so nobody reads that battery as a pass/fail gate undernano.
No behavioural change to the reducer itself: same spec file, same
-Wl,-u,_printf_float, samerecord_for.Autostill resolves toOffeverywhere.
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:
--no-shrink(control)BATTERY total=36 failed=0--shrink=printfBATTERY total=36 failed=6Verbatim failures from the shrunk image:
This is the vendor's formatter, not a missing flag: the toolchain's
libc_nano.aexports_printf_float(which is why%f/%e/%gstill pass) andhas no
_printf_long_longto link, so 64-bit /size_t/hhformattingcannot be restored by another
-u. Symbol sizes confirm the swap itself isexactly as designed (
_vfprintf_r11,413 B → 698 B,_svfprintf_r11,222 B →624 B, measured with the toolchain's own
nm).Consequence for the open policy question
Automust stayOff: a ~23 KB saving that silently mangles a 64-bit counteris 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_disclosurepins 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").
UNSUPPORTED_CONVERSIONSemptied,
--lib printf_thinis 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 --checkrc 0.soldr cargo clippy -p fbuild-build-esp --all-targets -- -D warningsrc 0,minus
-A unfulfilled_lint_expectationsfor one pre-existing expectationon
origin/main(crates/fbuild-core/src/usb/data.rs:193,usb::data::try_install_online_cache'scognitive_complexity) which isunfulfilled with this host's clippy; untouched by this diff
(
git diff --stat origin/main -- crates/fbuild-coreis empty).uv run --no-project python ci/check_test_layout.py— 8 categories, no straytest binaries.
(
/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 —fbuildspawns thefbuild-daemonprovisioned by the installed tool, so a worktree build exercisesthe installed daemon's copy of this code.
Refs #1459.