Skip to content

fix(libc): print unknown printf conversions and ' as titles' libc.prx does - #11907

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/libc-printf-unknown-flags
Nov 4, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/libc-printf-unknown-flags

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Two differences from the libc.prx that titles ship, in how the printf family handles conversions it does not know.

' is not a flag there. #3567 made ' FreeBSD's grouping flag, from FreeBSD's documentation. The titles' copy treats ' as an unknown conversion character: %'d prints %'d and consumes no argument. On main, printf("%'d|%d", 11, 22) prints 11|22. On the console it prints %'d|11, so every later conversion reads a different argument.

Flags on unknown conversions. main throws for an unknown conversion with +, space or ', or with 0 and a width, and for any unknown conversion in the _s forms. The wide family returns -1. The titles' copy prints % and the character:

  • it ignores +, space, #, 0 and the precision;
  • it pads to the width with spaces, on the left with -;
  • * still consumes its int;
  • the _s forms behave the same.
Format Titles' copy main
`%'d %d` with 11, 22 `%'d
[%-'5d] with 11 [%'5d] [11 ]
%+5k, %05k, % k %k, %k, %k throws
`% +#0-7k ` `%k
snprintf_s %k, `%5k ` %k, ` %k
swprintf %5k, %-04k, %+.2k %k, %k , %k -1

Both formatters now treat ' as a conversion character and print unknown conversions this way in every form. On Linux, RequiresGuestFormatting sends a format containing ' to the guest formatter instead of glibc. The printf family conversions debt entry now states the measured rule in place of "unverified and throw".

Tested

Latest Linux qualification (2026-11-02): exact head 8cac89f55a87191359f990f27952ecc1dd3cfbfe on pinned main a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. Resolved printf debt against main while retaining the measured unknown-conversion/flag behavior and main’s new thread-exit registration entry. Production and test blobs equal the automatic integration.

3 focused groups repeated three times: 9 passes, zero skips. Public headers, conventions, whitespace, raw libc/test builds and the actual production NID-patching command passed. MinGW syntax passed for Formatting.cpp, FormattingWide.cpp. No new Windows/macOS runtime, bundled-SDK reference, native title, GPU or performance claim; earlier evidence retains its historical pins.

Earlier pinned qualifications follow.

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON. The base is #11893 17c950f0a5 (on main 8ff4baf).

  • Comparison: a scratch loader runs the decrypted libc.prx of PPSA07923 and PPSA13934 natively.
    • Each row above, and each new expected string, was printed by both titles with the function it names or that its test calls (snprintf, snprintf_s, swprintf or snwprintf_s). The two titles agree on every one.
    • ' behaves the same before d u x ld f g s and after +, 0 or a precision. %''d prints %''d.
  • guest_formatting:
    • fix(libc): accept the ' flag in Windows formatting #3567's %'d|%'u|%'.2f|%'-8ld|%'+05d|%'g check now expects the format text, with no arguments.
    • Its %'lld %'zu and %'d %ls checks are replaced by [%6'd][%-6'd] and %'d %ls|%d, with arguments valid on the console.
    • A new line checks padded and flagged unknown conversions. The vsnprintf_s %y check now expects [%y][%k ] instead of a throw.
  • guest_wide_formatting:
    • CheckGroupingFlag now expects the format text from swprintf and snwprintf_s, plus padded unknown conversions.
    • The old swprintf %q check expected failure. It now expects [%q][ %q], which the titles' swprintf prints, measured on PPSA07923 and PPSA13934.
  • guest_formatting, guest_wide_formatting and guest_stdio_variadic pass in each of 3 runs on the exact head 15b33e8e76.
  • Negative control: with fix(libc): ignore printf length modifiers that do not apply, as titles' libc.prx does #11893's WindowsFormatting.hpp, Formatting.cpp and FormattingWide.cpp and these tests, guest_formatting and guest_wide_formatting abort (exit 0xc0000409). guest_stdio_variadic passes there too.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.
  • Linux: MarcZX10 built this exact head on Linux (GCC 12.2.0, Release); guest_formatting, guest_wide_formatting and guest_stdio_variadic pass 3/3 (review). That covers the RequiresGuestFormatting routing change.
  • Not tested: a console and macOS. A % right at the end of a format still throws, since the console reads past the terminator there.

Checklist

AI-assisted (Claude Code).

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I built the exact head 15b33e8e76 on Linux (GCC 12.2.0, Release) after initializing the declared submodules and configured XRandR support. The focused tests passed: guest_formatting, guest_wide_formatting, and guest_stdio_variadic (3/3). This covers the changed Linux routing as well as the narrow/wide formatter behavior. The hosted Windows/macOS and remaining platform jobs are still in progress, so I am leaving the final review decision until they complete.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9087 core/libs/tests/Formatting.cpp L288-294

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/include/WindowsFormatting.hpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 5303 core/libs/prx/libc/src/FormattingWide.cpp
core/libs/tests/GuestWideFormatting.cpp
docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7386 core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9340 core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 10158 docs/dev/debt/libc.md
PR 10165 docs/dev/debt/libc.md
PR 10200 docs/dev/debt/libc.md
PR 10405 docs/dev/debt/libc.md
PR 10780 docs/dev/debt/libc.md
PR 10987 core/libs/tests/GuestWideFormatting.cpp
docs/dev/debt/libc.md
PR 11332 core/libs/prx/libc/include/WindowsFormatting.hpp
core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 11621 docs/dev/debt/libc.md
PR 11664 docs/dev/debt/libc.md
PR 11724 core/libs/prx/libc/src/Formatting.cpp
docs/dev/debt/libc.md
PR 11726 core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 11831 docs/dev/debt/libc.md
PR 12510 docs/dev/debt/libc.md
PR 12511 docs/dev/debt/libc.md
PR 12518 docs/dev/debt/libc.md
PR 12704 docs/dev/debt/libc.md
PR 13449 docs/dev/debt/libc.md
PR 13486 core/libs/prx/libc/include/WindowsFormatting.hpp
core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 13793 docs/dev/debt/libc.md
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 13809 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md
PR 14235 docs/dev/debt/libc.md
PR 14588 docs/dev/debt/libc.md

@JJenkx

JJenkx commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

A native check of #11907 (15b33e8e76), #11893 (17c950f0a5) and #12397 (f2548977ea) together, merged locally onto main 319621ba2e. The only conflict was #12397's debt entry, taken as is. Results against the titles' libc.prx (PPSA07923), called by NID next to the build:

check main the three merged
swprintf copy rule for unknown conversions, 37 formats crashes on the first, %5S 0 differ
%S, %C, %y, %lS, %hS, %ws in swprintf, swprintf_s, snwprintf_s, plus %S, %C, %y in snprintf and snprintf_s 20 differ, then snprintf_s %y aborts 0 differ

The 37 formats cover:

  • width, including * and -; zero flag and precision (ignored);
  • the dropped h/hh/l/ll/L/j/z/t modifiers; q and I as conversion characters; positional %1$S;
  • no argument consumed (%y%d); and single unknown characters from %Z to %!.

With my #12627 (the wide _s constraints) merged on top as well, the four wide _s formatters also match on every row, %S included. guest_wide_formatting, guest_formatting, guest_safe_errors and guest_wide_strings pass.

AI-assisted: yes (Claude Code).

@JJenkx
JJenkx force-pushed the windows/libc-printf-unknown-flags branch from 15b33e8 to 8cac89f Compare November 2, 2026 17:57
@JJenkx

JJenkx commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Current-main qualification at 8cac89f55a87191359f990f27952ecc1dd3cfbfe, tested main a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. Resolved printf debt against main while retaining the measured unknown-conversion/flag behavior and main’s new thread-exit registration entry. Production and test blobs equal the automatic integration.

Linux: guest_formatting, guest_wide_formatting, guest_stdio_variadic, each three times: 9 passes, zero skips. Public headers, conventions, whitespace, raw production libc and test builds, and the production NID patch command pass. MinGW syntax passed for Formatting.cpp, FormattingWide.cpp. Main gitlinks and relevant fixtures/helpers are preserved.

No new Windows/macOS, console/reference-library, title, GPU or performance run is claimed. Earlier measurements and controls remain at their original pins. AI-assisted: yes (Codex).

Immutable source, command and test evidence, SHA-256 0e0231161112ecd15878b8abd7273e56dbc3644bf2506e3f10dd0c7d20be24eb (public download verified).

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 2, 2026
@JJenkx

JJenkx commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

The failing relinker (windows-latest, g++) check (run 41496038960) is a runner timeout unrelated to this change. check_compile_modes_test_clang_driver_only_and_hidden_queries_cannot_report_success hit its CTest timeout; the other tests in that job passed.

  • Locally: the same test takes 0.1 s (clang is not installed here, so its clang cases finish early) on Windows 11 (MinGW-w64 GCC 15.2.0 UCRT, main 7feb37ee3e).
  • Other PRs: the same job timed out in different tool tests on other PRs within the same hour.
  • Rerun: I can't rerun jobs on this repository. A maintainer rerun, or the next push, should clear it.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit acf7ac2 into boykopovar:main Nov 4, 2026
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants