Repository navigation
libs/libc: make printf octal formatting optional for DEFAULT_SMALL - #22162
Merged
GUIDINGLI merged 1 commit intoNov 23, 2026
Merged
Conversation
Memory-constrained embedded targets (DEFAULT_SMALL=y) rarely format integers in octal notation (%o). The vsprintf engine in libs/libc/stream/lib_libvsprintf.c already provides dead-code elimination via CONFIG_LIBC_PRINTF_OCTAL, printing '?' when octal support is disabled. However, CONFIG_LIBC_PRINTF_OCTAL currently defaults unconditionally to 'y'. Change CONFIG_LIBC_PRINTF_OCTAL to default to LIBC_PRINTF_FULL || !DEFAULT_SMALL. This eliminates octal parsing, alternate form (%#o) checks, and base-8 conversion logic on small profiles, saving 178 bytes of Flash (text) and 32 bytes of bss in lib_libvsprintf.o (176 bytes of Flash in the linked nuttx binary on sim:nsh), while preserving full conformance when LIBC_PRINTF_FULL is selected or on standard targets. Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Swatantra Yadav <[email protected]>
|
xiaoxiang781216
approved these changes
Nov 22, 2026
GUIDINGLI
approved these changes
Nov 23, 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
Memory-constrained embedded targets (
DEFAULT_SMALL=y) rarely format integers in octal notation (%o). The vsprintf engine inlibs/libc/stream/lib_libvsprintf.calready provides dead-code elimination viaCONFIG_LIBC_PRINTF_OCTAL, printing'?'when octal support is disabled. However,CONFIG_LIBC_PRINTF_OCTALcurrently defaults unconditionally toy.Change
CONFIG_LIBC_PRINTF_OCTALto default toLIBC_PRINTF_FULL || !DEFAULT_SMALL. This eliminates octal parsing, alternate form (%#o) checks, and base-8 conversion logic on small profiles, saving 178 bytes of Flash (text) and 32 bytes of RAM (bss) inlib_libvsprintf.o(176 bytes Flash in the linkednuttxbinary onsim:nsh), while preserving full conformance whenLIBC_PRINTF_FULLis selected or on standard targets.Part of Issue #20414.
Impact
CONFIG_LIBC_PRINTF_OCTAL).printf("%o")outputs'?'onDEFAULT_SMALL=ytargets unless explicitly enabled or usingLIBC_PRINTF_FULL.LIBC_PRINTF_FULL=y. OnDEFAULT_SMALL=ytargets, saves Flash without manual Kconfig tuning.Documentation/os/libs/libc/printf.rst.Size Difference (sim:nsh)
Configuration:
sim:nsh(x86_64)libs/libc/bin/lib_libvsprintf.oCONFIG_LIBC_PRINTF_OCTAL=yCONFIG_LIBC_PRINTF_OCTAL=nLinked Binary (
nuttx)CONFIG_LIBC_PRINTF_OCTAL=yCONFIG_LIBC_PRINTF_OCTAL=nTesting
Build Verification
CONFIG_LIBC_PRINTF_OCTAL=y: Success.CONFIG_LIBC_PRINTF_OCTAL=n: Success.Runtime Test Log (
sim:nsh,CONFIG_LIBC_PRINTF_OCTAL=n)