Repository navigation
libs/libc/stdio: default to LIBC_PRINTF_MINIMAL on DEFAULT_SMALL - #22317
Merged
acassis merged 1 commit intoNov 25, 2026
Merged
Conversation
NuttX provides three printf profiles: Minimal, Default, and Full. Currently, the profile choice unconditionally defaults to LIBC_PRINTF_DEFAULT across all targets, preventing memory-constrained systems (CONFIG_DEFAULT_SMALL=y) from benefiting from the Minimal profile by default. This change sets the default printf profile to LIBC_PRINTF_MINIMAL when DEFAULT_SMALL is enabled. This reduces text size by omitting unneeded conversions and features: - On stm32f103-minimum:nsh (Cortex-M3): -440 B Flash (53,255 B -> 52,815 B) - On nucleo-f072rb:nsh (Cortex-M0): -332 B Flash (46,792 B -> 46,460 B) - On rv-virt:nsh (32-bit RISC-V): -3,324 B Flash (231,490 B -> 228,166 B) - On qemu-armv8a:nsh (arm64): -3,720 B Flash (329,564 B -> 325,844 B) Additionally, with LIBC_PRINTF_MINIMAL, CONFIG_STREAM_OUT_BUFFER_SIZE defaults to 0, saving 64 bytes of stack frame on dprintf() and vdprintf() calls and omitting lib_bufferedoutstream.c from compilation. Standard targets (!DEFAULT_SMALL) continue to default to LIBC_PRINTF_DEFAULT. Related to apache#20414 Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Swatantra Yadav <[email protected]>
|
xiaoxiang781216
approved these changes
Nov 25, 2026
acassis
approved these changes
Nov 25, 2026
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.
Summary
Addresses Issue #20414 ([HELP] Improve NuttX bloated size)
NuttX libc provides three printf profiles (
Minimal,Default, andFull), documented inDocumentation/os/libs/libc/printf.rst. Currently, the profile choice unconditionally defaults toLIBC_PRINTF_DEFAULTfor all targets.This patch changes the profile choice in
libs/libc/stdio/Kconfigto default toLIBC_PRINTF_MINIMALwhenCONFIG_DEFAULT_SMALL=y:On memory-constrained targets,
Minimalomits unnecessary conversions and flags that are rarely required in resource-constrained firmware:%lld/ 64-bit integer division on 32-bit CPUs (unlessSYSLOG_TIMESTAMPorFS_PROCFSis enabled).#flag for%#x,%#o).%.3d).CONFIG_STREAM_OUT_BUFFER_SIZEto0inlibs/libc/stream/Kconfig, saving 64 bytes of stack frame ondprintf()andvdprintf()calls and omittinglib_bufferedoutstream.c.Standard configurations (
!DEFAULT_SMALL) continue to default toLIBC_PRINTF_DEFAULTwith zero impact. Targets needing specific printf features can still enable them individually or selectDefault/Fullin menuconfig.Size Impact
Measured across multiple architectures with
-Os:Default)Minimal)stm32f103-minimum:nshnucleo-f072rb:nshrv-virt:nshqemu-armv8a:nshImpact
LIBC_PRINTF_MINIMALonDEFAULT_SMALL=y.?and consumes arguments correctly).CONFIG_LIBC_PRINTF_*, so defconfig normalization is 100% clean.DEFAULT_SMALLboards.Documentation/os/libs/libc/printf.rst.Testing
Build host: Linux container (
nuttx-builder) witharm-none-eabi-gcc10.3.1.Target board:
stm32f103-minimum:nsh.1. Style & Verification
git diff --check: PASSED (0 whitespace errors).2. Build & Size Comparison Logs
Before (
CONFIG_LIBC_PRINTF_DEFAULT=y):After (
CONFIG_LIBC_PRINTF_MINIMAL=yviaDEFAULT_SMALL):Total flash reduction on
stm32f103-minimum:nsh: -440 bytes.