Repository navigation
libs/libc/stream: Add profiles and options to printf(). - #21493
Merged
Merged
Conversation
|
casaroli
force-pushed
the
printf-options-up
branch
from
November 5, 2026 20:20
e725087 to
4b1686a
Compare
Contributor
|
@casaroli please fix the conflict. |
This was referenced Nov 6, 2026
casaroli
force-pushed
the
printf-options-up
branch
from
November 6, 2026 07:44
4b1686a to
0ba20e4
Compare
casaroli
marked this pull request as ready for review
November 6, 2026 07:45
casaroli
requested review from
Donny9,
jerpelea and
xiaoxiang781216
as code owners
November 6, 2026 07:45
casaroli
marked this pull request as draft
November 6, 2026 08:53
casaroli
marked this pull request as ready for review
November 6, 2026 11:47
Add the braces that nxstyle asks for. There is no code change. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
A choice of three profiles sets the defaults of the printf feature options: Minimal, Default and Full. Each option keeps its own prompt, so a user can add any feature to any profile. Default is the default of the choice, and the defaults of its options do not change, so no defconfig changes. Full turns on floating point, numbered arguments and locale. Minimal turns off floating point. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
On a 32-bit CPU each integer conversion goes through 64-bit division, even for %d. With LIBC_PRINTF_LONG_LONG off, the digit loop uses long. A value longer than long is read at its size, and printf() prints "?". The option is on in the Default and Full profiles. In the Minimal profile it stays on with SYSLOG_TIMESTAMP or FS_PROCFS, because the timestamps of syslog and the times in /proc print with %jd. It has no effect where long has 64 bits. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
With LIBC_PRINTF_ALT_FORM off, the flag is parsed and ignored. %p keeps its 0x. FL_ALT_FORM is 0 then, so the compiler removes the code that tests it. The option is on in the Default and Full profiles. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
With LIBC_PRINTF_OCTAL off, %o reads its argument and prints "?". The option is on in all profiles. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
With LIBC_PRINTF_LEFT_JUSTIFY off, the flag is parsed and ignored, and the output is padded on the left. The option is on in all profiles. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
…intf(). With LIBC_PRINTF_INT_PRECISION off, a conversion such as %.3d reads its argument and prints "?". The precision of %s and of a floating point conversion does not change. The option is on in the Default and Full profiles. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
With LIBC_PRINTF_SHORT off, a conversion such as %hhx reads its argument and prints "?". It does not print the value without the conversion to char, because that value can be wrong for a correct call. The option is on in all profiles. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
With STREAM_OUT_BUFFER_SIZE at 0, vdprintf() writes through the raw stream, and lib_bufferedoutstream.c is not built. This removes the code and the buffer on the stack, and each write of printf() becomes one write(). The size is 0 by default in the Minimal profile only. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
printf() has two reads for %ld and %d. Where long has the size of int, both read the same slot. One read is enough, and the code is smaller. There is no change in the output. Part of apache#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
force-pushed
the
printf-options-up
branch
from
November 6, 2026 12:13
0ba20e4 to
9c65e7d
Compare
xiaoxiang781216
approved these changes
Nov 8, 2026
acassis
approved these changes
Nov 8, 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.
Part of #21467, step 2.
Summary
#21474 makes
printfsafe for correct calls and adds a few bytes. This PR lets a board take bytes out again, and gives three profiles:Each option has its own prompt, so Minimal or Default can add or remove one feature at a time. A removed conversion still reads its argument at the right size and prints
?, so the next conversion stays correct.LIBC_FLOATINGPOINT%f:?LIBC_NUMBERED_ARGSLIBC_LOCALELIBC_PRINTF_LONG_LONGSYSLOG_TIMESTAMPorFS_PROCFS, else off%lld,%jd:?LIBC_PRINTF_ALT_FORM%#xof 255 printsff;%pkeeps0xLIBC_PRINTF_INT_PRECISION%.3d:?;%.3sstaysSTREAM_OUT_BUFFER_SIZEdprintf()is onewrite()LIBC_PRINTF_OCTAL%o:?LIBC_PRINTF_LEFT_JUSTIFY%-5dpads on the leftLIBC_PRINTF_SHORT%hd,%hhx:?The 64-bit option stays on in Minimal with
SYSLOG_TIMESTAMPorFS_PROCFS, because the log timestamps and/procprinttime_tanduint64_t. Without them,timeandulimitin nsh print?.The last commit reads a
longas anintwhere they have the same size. It has no option and does not change the output.Impact
Default: no feature changes. 90 configs, on arm, arm64, risc-v, xtensa, sim and avr, have the same
savedefconfigas #21474; their.confighas only the newLIBC_PRINTF_*lines.No ABI change. Not a breaking change. No architecture code. Flat, protected and kernel builds.
Image text against master, float and numbered arguments off:
FS_PROCFSandSYSLOG_TIMESTAMPoffFS_PROCFSonBoards:
nucleo-f072rb:nsh,nucleo-f103rb:nsh,rv-virt:nsh,qemu-armv8a:nsh.FS_PROCFSis on in the defconfig of all but the Cortex-M3 board.Image text with each board's defaults; rv32 and arm64 have float on by default:
One option off from Default, float and numbered arguments off:
#%h,%hh%o-dprintf()bufferWith #20996 merged, 64-bit integers off saves less, because libgcc no longer has the division: -252, -200, -168, 0. These four numbers are from one commit before this head. This PR has one line for that case, and it does nothing without #20996.
Documentation: no page describes these options. The Kconfig help has the text, and step 5 of #21467 is the documentation.
Testing
rv-virt:nshMinimal with 64-bit on and off,qemu-armv8a:knshMinimal, and both boards with Full.EXTRAFLAGS="-Wno-cpp -Werror", each of Minimal, Default and Full:nucleo-f072rb:nsh,nucleo-f103rb:nsh,rv-virt:nsh,qemu-armv8a:nsh,mps2-an500:knsh(protected),qemu-armv8a:knsh,rv-virt:knsh(kernel). Each single option off on the four flat boards.Default, Full, the harness and the single-option builds ran one rebuild before this head. The later commits are a style fix, the Kconfig default of the 64-bit option, and one line that has no effect without #20996.
Not run: Cortex-M0 at run time; a protected or kernel build of 32-bit Minimal with 64-bit off on this head; the speed of
dprintf()with no buffer; a size row withSYSLOG_TIMESTAMPon; a CMake build.tools/checkpatch.sh -c -u -m -gpasses.