fix(libc): match title printf behavior on Windows #3987
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3987"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T20:40:50Z.
What
On Windows, match the measured title
libc.prxDinkumware_Printfbehavior for%q,%D,%O,%U, and unknown conversion characters. These are emitted as literal text; unknown conversions keep the leading%, use the measured width and-behavior, and discard length modifiers. Width handling for%%remains covered. A trailing%reads beyond the format NUL in the measured binaries, so this implementation throws instead of reproducing that undefined over-read. Unknown conversions with other flags or precision still throw because those cases were not measured.The probe in #3975 loaded the decrypted
libc.prxfrom PPSA13934, PPSA07923, PPSA05916 and PPSA04158 and called each module'ssnprintfexport. All four returned byte-identical results for the tested formats.The overlap scan found adjacent test insertions with #7386 in
Formatting.cpp; the wide-scanf and printf checks are independent, and I proposed landing this small test block first so #7386 can rebase while keeping its tests. Other shared formatter/debt files belong to separate open work on argument positions (#9552), float conversions (#9699, #9916, #9927 and #9958), and UTF-16 string conversion (#9939); I reviewed their changed hunks, and this change does not depend on those implementations. Preserve each PR's test and debt entries when rebasing.Tested
FormatWindowsdirectly and passed the measured literal, width, length-modifier and incomplete-format cases.python3 tools/check_conventions.py --base upstream/main --head HEADpassed;git diff --checkpassed.guest_formattingtest was not run on Windows for this head.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T22:56:35Z.
Windows run (Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, full build):
0a8b1d32b:guest_formatting,guest_wide_formatting,guest_standard_streams,file_streamsandguest_crtpass 3/3. WithWindowsFormatting.hppreverted,guest_formattingaborts withUnsupported format conversion '%q' in "%qd|%qu|%qx|%qo", so the Windows path is exercised.main(ae7dbfa9c, plus #4021 so that Windows builds),guest_formattingfails 3/3 withFormatting check failed. The loop that expects%m,%1$d,%'d, … to keep throwing no longer holds: since this branch was cut, #3569 (positional arguments) and #3567 (the'flag) mademainformat%1$dand%'don Windows. With those two entries removed from the list,guest_formattingpasses 3/3 on the same merge.main+ #4021 alone andmain+ #4021 + #3982 both passguest_formatting, so the failure comes from this PR's test, not from #3982.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T03:12:31Z.
CI status note: all reported checks are passing except
register-context (ubuntu-latest, Release), which remains marked pending. Its Actions job record showsconclusion: successand acompleted_attimestamp while still reportingstatus: in_progress; I found no failing test output. Linux and Windows full-suite jobs are skipped by the workflow.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:24:54Z.
Needs a rebase: main formats
%1$dand%'don Windows since #3569 and #3567, so the throw loop added toFormatting.cppfails there (LeandroLP23's run above). Which title prints%q,%D/%O/%Uor an unknown conversion? Without one I'd keep the throw.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T03:41:45Z.
Rebased onto current
mainand addressed the Windows test failure:%1$dand%'dhave since become supported by #3569 and #3567, so I removed them from the unsupported-format throw list. The carried implementation commits retain Hussein Kadhim as author; the follow-up test commit is by MarcZX100. Validation on Linux/GCC 12.2 Release:guest_formatting_testsbuilt andguest_formattingpassed (1/1); conventions, test registration, andgit diff --checkpass. The Windows-only formatting cases still need a hosted/Windows run.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:13:37Z.
I do not have a title log showing a call with %q, %D, %O, %U, or another conversion that the PR newly rejects. The current evidence only compares the formatter with FreeBSD behavior. I will not claim that this establishes console behavior; if title or console evidence is required for the change, I agree it is still missing.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:14:28Z.
Review: CHANGES_REQUESTED
Thanks for the rebase. Two things before this can go in:
%q,%D/%O/%U, an unknown conversion or a trailing%is ever printed. Until then the guest aborting is the safer behaviour than a plausible-but-wrong output.vfprintf.c, and the assumption in the TechnicalDebt line that the console takes these from the same code is unchecked. The console'slibc.prxexports Dinkumware's_Printf/_Printf.percent, whose handling of unknown conversions and ofqcan differ (e.g. printing the whole%yspec rather than justy). Disassembling_Printfin a title'slibc.prxand checking those four cases would settle it; then the code and the expected values in the test should follow that.Also, the current head hasn't had a Windows run (the earlier ones were before the rebase);
guest_formattingonly exercises these cases on Windows.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T14:43:16Z.
I do not have a title trace or a console
_Printfsample for the newly handled conversions, and I have not rerun the Windows-only formatting cases on this head. I agree the current FreeBSD comparison does not establish the console behavior. I will leave the PR open without claiming that it is ready to merge; the missing evidence is a title call or a console-side_Printfcheck for these cases.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T00:51:18Z.
Rebased onto current
main(6caba0864) and pushed asbe146cbd7. The two carried implementation commits remain authored by Hussein Kadhim; both test commits remain authored by MarcZX100. I preserved main's newerstrnduptechnical-debt entry and revised the formatter note to state explicitly that console Dinkumware_Printfbehavior is unverified and may differ.Validation on this head: conventions pass. Hosted relinker jobs pass on Ubuntu, Windows and macOS; register-context passes on Ubuntu and macOS Debug/Release; write-watch passes on macOS. The main Linux and Windows build/test jobs are skipped by workflow gating, so this does not provide a Windows
guest_formattingrun. No title trace or console_Printfevidence has appeared, so the compatibility question in the review remains open and this rebase does not make the PR ready to merge.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T16:33:29Z.
Review: CHANGES_REQUESTED
Thanks for the rebase and the debt note. The two open points from the previous review are unchanged:
%q,%D/%O/%U, an unknown conversion or a trailing%is ever printed (@oneandonlydean's question, still unanswered). Until there is, aborting is safer than a plausible-but-wrong output.vfprintf.c; the console'slibc.prxuses Dinkumware_Printf. Disassembling_Printf/_Printf.percentin a title'slibc.prxand checking those four cases would settle it, and the code and test expectations should then follow it.Also, no Windows run exists for the current head;
guest_formattingonly exercises these cases on Windows.Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T10:34:18Z.
This measures the four cases from @adriadam10's review (
%q,%D/%O/%U, an unknown conversion and a trailing%), with one limit up front. It is libSceLibcInternal'ssnprintf(resolved from libSceLibcInternal.sprx) called in a payload process on a PS5 (firmware 12.70). It is not_Printfin a title'slibc.prx, and it does not show what a title'slibc.prxdoes.The probe is an ELF payload (ps5-payload-dev/sdk v0.44, clang 18.1.8) run from a payload manager. Each call passes the format as a string literal with size 48, into a 64-byte buffer prefilled with
Z. The log prints the return value and the buffer up to its first NUL. This is from one run:Compared with the current head (
be146cbd7),core/libs/tests/Formatting.cpp:q, lines 260-261 (expects 28 and-5000000000|5000000000|ff|10): printed as written, return 15.%D|%hD|%O|%U|%jD, lines 262-263 (expects 48 and-5000000000|5000000000|10|5000000000|-6000000000): prints%D|%D|%O|%U|%D, return 14. No number is printed, and theh/jbeforeDis dropped.[ %][% ][y][ y][y ]): return 30.%5%and%-5%agree with the test.%yis printed with its%, the difference @adriadam10 suggested might exist. The width and-flag are applied and cover both characters.%05yis not in the test. It gives%y: blank padding, as the debt line says the host%cdoes, but with the%.%l5d,%lqd,%qc,%lhdand%l*ddon't fail. Each returns 3 and prints as text:%qcas written, the others without thel.%, lines 271-272 (expect"100%"→ 3 and100, and"%d done 5% "with 7 → 8 and7 done 5): the output does not stop at the%. The returns are 54 and 51. The100text matches only because a NUL is written right after it (see below).main.c, the second from itsoracle.c:"100%"that is%cof the first (zero) argument, which writes a NUL. That is why the text is only100."%d done 5% "the space is taken as a flag and the conversion isr, an unknown conversion printed as%r.So for these cases, the only parts of the test's expected output that this process reproduces are
%5%and%-5%. For an unknown conversion, the width and-flag are applied as the debt line describes, but the%is kept.For
%D/%O/%Uand unknown conversions, the results are closer to what the debt line (docs/dev/debt/libc.md, line 32) says glibc does ("prints%D,%O,%Uand unknown conversions as written"), but they are not the same. A length modifier is dropped (%hD→%D), and the width and-flag are applied (%5y→%y).If the reading above is right, a trailing
%gives a result that depends on whatever bytes follow the format in memory, so there is no fixed output to match.Not measured:
libc.prxand its_Printf/_Printf.percent%m"ab%dcd%"case (line 273)-5for%qdand3instead of7in"%d done 5% ". Theq,%D/%O/%U, unknown-conversion and throw-list outputs print no arguments.I can attach the probe source, the ELF and the full log.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:07:29Z.
Thanks for the detailed payload probe. It is useful evidence for
libSceLibcInternal.sprx, but it does not establish the behavior of a title’slibc.prxDinkumware_Printf, which is the formatter this PR changes. It also shows trailing%can read beyond the format, so that result should not be treated as a deterministic conversion to emulate. The target-specific evidence requested in the review is still missing, and the current PR is dirty against main; I’m checking its rebase state separately.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:09:26Z.
Rebased onto current
mainat00d7e611efand corrected the debt entry to describe this as Windows host-side behavior; the titlelibc.prxbehavior remains unverified. All four original implementation/test commits are preserved with their original authors, followed by a conflict-resolution commit under my account. The current head passesgit diff --checkand the conventions checker. I could not run the Windows-only tests here; CMake configuration is blocked by the missing SDL2 CMake source and XRandR development support. The unsupported-conversion semantics remain under review pending target-module evidence.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T19:16:29Z.
I do not have the requested title
libc.prxdisassembly or a console-side_Printfrun for%q,%D/%O/%U, unknown conversions, and trailing%; thelibSceLibcInternal.sprxprobe does not resolve that gap. I also have not run the Windows-onlyguest_formattingcases on the rebased head. I agree those are still blockers, so I am not treating this PR as merge-ready or claiming the behavior matches the console. I will leave the implementation unchanged until target-specific evidence is available.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:37:42Z.
Thanks for the clarification and for the firmware 12.70 payload measurement. Since it exercises
libSceLibcInternal.sprx, it does not establish how a title’slibc.prx_Printfhandles these conversions. I’ll treat it as a useful separate data point, not evidence for this PR; the unsupported%q,%D/%O/%U, unknown-conversion, and trailing-percent behavior remains unverified for the title module. The reviewer’s requested title trace or_Printfinspection is still needed before changing the current throw behavior.