fix(libc): match title printf behavior on Windows #3987

Merged
MarcZX10 merged 7 commits from upstream-pr/3987 into main 2026-10-24 15:59:27 +00:00
MarcZX10 commented 2026-10-11 20:40:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T20:40:50Z.


What

On Windows, match the measured title libc.prx Dinkumware _Printf behavior 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.prx from PPSA13934, PPSA07923, PPSA05916 and PPSA04158 and called each module's snprintf export. 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

  • Linux/GCC 12: a focused harness called FormatWindows directly and passed the measured literal, width, length-modifier and incomplete-format cases.
  • MinGW-w64 GCC 12 POSIX: the focused harness compiled for Windows; it was not run on Windows.
  • python3 tools/check_conventions.py --base upstream/main --head HEAD passed; git diff --check passed.
  • The project guest_formatting test was not run on Windows for this head.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822188578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T20:40:50Z. --- ### What On Windows, match the measured title `libc.prx` Dinkumware `_Printf` behavior 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.prx` from PPSA13934, PPSA07923, PPSA05916 and PPSA04158 and called each module's `snprintf` export. 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 - Linux/GCC 12: a focused harness called `FormatWindows` directly and passed the measured literal, width, length-modifier and incomplete-format cases. - MinGW-w64 GCC 12 POSIX: the focused harness compiled for Windows; it was not run on Windows. - `python3 tools/check_conventions.py --base upstream/main --head HEAD` passed; `git diff --check` passed. - The project `guest_formatting` test was not run on Windows for this head. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
LeandroLP23 commented 2026-10-11 22:56:35 +00:00 (Migrated from github.com)

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):

  • On its base 0a8b1d32b: guest_formatting, guest_wide_formatting, guest_standard_streams, file_streams and guest_crt pass 3/3. With WindowsFormatting.hpp reverted, guest_formatting aborts with Unsupported format conversion '%q' in "%qd|%qu|%qx|%qo", so the Windows path is exercised.
  • Merged onto current main (ae7dbfa9c, plus #4021 so that Windows builds), guest_formatting fails 3/3 with Formatting 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) made main format %1$d and %'d on Windows. With those two entries removed from the list, guest_formatting passes 3/3 on the same merge.

main + #4021 alone and main + #4021 + #3982 both pass guest_formatting, so the failure comes from this PR's test, not from #3982.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114834008 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6114834008). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-11T22:56:35Z. --- Windows run (Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, full build): - On its base `0a8b1d32b`: `guest_formatting`, `guest_wide_formatting`, `guest_standard_streams`, `file_streams` and `guest_crt` pass 3/3. With `WindowsFormatting.hpp` reverted, `guest_formatting` aborts with `Unsupported format conversion '%q' in "%qd|%qu|%qx|%qo"`, so the Windows path is exercised. - **Merged onto current `main` (`ae7dbfa9c`, plus #4021 so that Windows builds), `guest_formatting` fails 3/3 with `Formatting 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) made `main` format `%1$d` and `%'d` on Windows. With those two entries removed from the list, `guest_formatting` passes 3/3 on the same merge. `main` + #4021 alone and `main` + #4021 + #3982 both pass `guest_formatting`, so the failure comes from this PR's test, not from #3982.
MarcZX10 commented 2026-10-12 03:12:31 +00:00 (Migrated from github.com)

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 shows conclusion: success and a completed_at timestamp while still reporting status: in_progress; I found no failing test output. Linux and Windows full-suite jobs are skipped by the workflow.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117066907 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6117066907). Originally posted by [MarcZX10](https://github.com/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 shows `conclusion: success` and a `completed_at` timestamp while still reporting `status: in_progress`; I found no failing test output. Linux and Windows full-suite jobs are skipped by the workflow.
oneandonlydean commented 2026-10-12 08:24:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:24:54Z.


Needs a rebase: main formats %1$d and %'d on Windows since #3569 and #3567, so the throw loop added to Formatting.cpp fails there (LeandroLP23's run above). Which title prints %q, %D/%O/%U or an unknown conversion? Without one I'd keep the throw.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120530961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6120530961). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T08:24:54Z. --- Needs a rebase: main formats `%1$d` and `%'d` on Windows since #3569 and #3567, so the throw loop added to `Formatting.cpp` fails there (LeandroLP23's run above). Which title prints `%q`, `%D`/`%O`/`%U` or an unknown conversion? Without one I'd keep the throw.
MarcZX10 commented 2026-10-13 03:41:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T03:41:45Z.


Rebased onto current main and addressed the Windows test failure: %1$d and %'d have 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_tests built and guest_formatting passed (1/1); conventions, test registration, and git diff --check pass. The Windows-only formatting cases still need a hosted/Windows run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137706603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6137706603). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T03:41:45Z. --- Rebased onto current `main` and addressed the Windows test failure: `%1$d` and `%'d` have 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_tests` built and `guest_formatting` passed (1/1); conventions, test registration, and `git diff --check` pass. The Windows-only formatting cases still need a hosted/Windows run.
MarcZX10 commented 2026-10-13 07:13:37 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140340746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6140340746). Originally posted by [MarcZX10](https://github.com/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.
adriadam10 commented 2026-10-13 10:14:28 +00:00 (Migrated from github.com)

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:

  • Same question as @oneandonlydean's, still open: no title or console evidence that %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.
  • The only source is FreeBSD 11.4 vfprintf.c, and the assumption in the TechnicalDebt line that the console takes these from the same code is unchecked. The console's libc.prx exports Dinkumware's _Printf / _Printf.percent, whose handling of unknown conversions and of q can differ (e.g. printing the whole %y spec rather than just y). Disassembling _Printf in a title's libc.prx and 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_formatting only exercises these cases on Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5502009229 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#pullrequestreview-5502009229). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T10:14:28Z. **Review:** CHANGES_REQUESTED --- Thanks for the rebase. Two things before this can go in: - Same question as @oneandonlydean's, still open: no title or console evidence that `%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. - The only source is FreeBSD 11.4 `vfprintf.c`, and the assumption in the TechnicalDebt line that the console takes these from the same code is unchecked. The console's `libc.prx` exports Dinkumware's `_Printf` / `_Printf.percent`, whose handling of unknown conversions and of `q` can differ (e.g. printing the whole `%y` spec rather than just `y`). Disassembling `_Printf` in a title's `libc.prx` and 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_formatting` only exercises these cases on Windows.
MarcZX10 commented 2026-10-14 14:43:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T14:43:16Z.


I do not have a title trace or a console _Printf sample 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 _Printf check for these cases.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6171018344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6171018344). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T14:43:16Z. --- I do not have a title trace or a console `_Printf` sample 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 `_Printf` check for these cases.
MarcZX10 commented 2026-10-17 00:51:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T00:51:18Z.


Rebased onto current main (6caba0864) and pushed as be146cbd7. The two carried implementation commits remain authored by Hussein Kadhim; both test commits remain authored by MarcZX100. I preserved main's newer strndup technical-debt entry and revised the formatter note to state explicitly that console Dinkumware _Printf behavior 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_formatting run. No title trace or console _Printf evidence has appeared, so the compatibility question in the review remains open and this rebase does not make the PR ready to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227593814 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6227593814). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T00:51:18Z. --- Rebased onto current `main` (`6caba0864`) and pushed as `be146cbd7`. The two carried implementation commits remain authored by Hussein Kadhim; both test commits remain authored by MarcZX100. I preserved main's newer `strndup` technical-debt entry and revised the formatter note to state explicitly that console Dinkumware `_Printf` behavior 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_formatting` run. No title trace or console `_Printf` evidence has appeared, so the compatibility question in the review remains open and this rebase does not make the PR ready to merge.
adriadam10 commented 2026-10-18 16:33:29 +00:00 (Migrated from github.com)

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:

  • No title or console evidence that %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.
  • The only source is FreeBSD 11.4 vfprintf.c; the console's libc.prx uses Dinkumware _Printf. Disassembling _Printf / _Printf.percent in a title's libc.prx and 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_formatting only exercises these cases on Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5563883988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#pullrequestreview-5563883988). Originally posted by [adriadam10](https://github.com/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: - No title or console evidence that `%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. - The only source is FreeBSD 11.4 `vfprintf.c`; the console's `libc.prx` uses Dinkumware `_Printf`. Disassembling `_Printf` / `_Printf.percent` in a title's `libc.prx` and 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_formatting` only exercises these cases on Windows.
ionut27001 commented 2026-10-19 10:34:18 +00:00 (Migrated from github.com)

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's snprintf (resolved from libSceLibcInternal.sprx) called in a payload process on a PS5 (firmware 12.70). It is not _Printf in a title's libc.prx, and it does not show what a title's libc.prx does.

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:

p23: meta fw=0x12700001 pid=135 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 18 2026 02:46:33
p23: resolve sym=snprintf module=libSceLibcInternal.sprx exported=yes
p23: case snprintf fmt="%qd|%qu|%qx|%qo" ret=15 text="%qd|%qu|%qx|%qo"
p23: case snprintf fmt="%D|%hD|%O|%U|%jD" ret=14 text="%D|%D|%O|%U|%D"
p23: case snprintf fmt="[%5%][%-5%][%y][%5y][%-3y]" ret=30 text="[    %][%    ][%y][   %y][%y ]"
p23: case snprintf fmt="%05y" ret=5 text="   %y"
p23: case snprintf fmt="100%" ret=54 text="100"
p23: case snprintf fmt="%d done 5% " ret=51 text="3 done 5%resolve sym=(null) module=(null) loade"
p23: case snprintf fmt="%l5d" ret=3 text="%5d"
p23: case snprintf fmt="%lqd" ret=3 text="%qd"
p23: case snprintf fmt="%qc" ret=3 text="%qc"
p23: case snprintf fmt="%lhd" ret=3 text="%hd"
p23: case snprintf fmt="%l*d" ret=3 text="%*d"

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 the h/j before D is dropped.
  • Unknown conversions, lines 264-265 (expects 29 and [ %][% ][y][ y][y ]): return 30.
    • %5% and %-5% agree with the test.
    • %y is printed with its %, the difference @adriadam10 suggested might exist. The width and - flag are applied and cover both characters.
    • %05y is not in the test. It gives %y: blank padding, as the debt line says the host %c does, but with the %.
  • Throw list, lines 266-270: %l5d, %lqd, %qc, %lhd and %l*d don't fail. Each returns 3 and prints as text: %qc as written, the others without the l.
  • Trailing %, lines 271-272 (expect "100%" → 3 and 100, and "%d done 5% " with 7 → 8 and 7 done 5): the output does not stop at the %. The returns are 54 and 51. The 100 text matches only because a NUL is written right after it (see below).
    • In the probe ELF, the two formats are followed by these strings. The first comes from the probe's main.c, the second from its oracle.c:
      0xe6c9: "100%\0case swprintf fmt=%s ret=%d text=%s nul_at=%zu\0"
      0xebfe: "%d done 5% \0resolve sym=%s module=%s loaded=no\0"
      
    • Both results fit one reading: the NUL that ends the format is skipped, and the byte after it becomes the conversion.
    • For "100%" that is %c of the first (zero) argument, which writes a NUL. That is why the text is only 100.
    • For "%d done 5% " the space is taken as a flag and the conversion is r, an unknown conversion printed as %r.
    • Formatting the rest of each string with the probe's zero arguments gives exactly 54 and 51.
    • This reading comes from the outputs and the ELF bytes, not from disassembly.

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/%U and unknown conversions, the results are closer to what the debt line (docs/dev/debt/libc.md, line 32) says glibc does ("prints %D, %O, %U and 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:

  • a title's libc.prx and its _Printf / _Printf.percent
  • whether any title passes these formats at all
  • narrow %m
  • the size-4 "ab%dcd%" case (line 273)
  • the test's own argument values. The probe used different ones, e.g. -5 for %qd and 3 instead of 7 in "%d done 5% ". The q, %D/%O/%U, unknown-conversion and throw-list outputs print no arguments.
  • the Windows host

I can attach the probe source, the ELF and the full log.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6265216908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6265216908). Originally posted by [ionut27001](https://github.com/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's `snprintf` (resolved from libSceLibcInternal.sprx) called in a payload process on a PS5 (firmware 12.70). It is not `_Printf` in a title's `libc.prx`, and it does not show what a title's `libc.prx` does. 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: ``` p23: meta fw=0x12700001 pid=135 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 18 2026 02:46:33 p23: resolve sym=snprintf module=libSceLibcInternal.sprx exported=yes p23: case snprintf fmt="%qd|%qu|%qx|%qo" ret=15 text="%qd|%qu|%qx|%qo" p23: case snprintf fmt="%D|%hD|%O|%U|%jD" ret=14 text="%D|%D|%O|%U|%D" p23: case snprintf fmt="[%5%][%-5%][%y][%5y][%-3y]" ret=30 text="[ %][% ][%y][ %y][%y ]" p23: case snprintf fmt="%05y" ret=5 text=" %y" p23: case snprintf fmt="100%" ret=54 text="100" p23: case snprintf fmt="%d done 5% " ret=51 text="3 done 5%resolve sym=(null) module=(null) loade" p23: case snprintf fmt="%l5d" ret=3 text="%5d" p23: case snprintf fmt="%lqd" ret=3 text="%qd" p23: case snprintf fmt="%qc" ret=3 text="%qc" p23: case snprintf fmt="%lhd" ret=3 text="%hd" p23: case snprintf fmt="%l*d" ret=3 text="%*d" ``` 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 the `h`/`j` before `D` is dropped. - **Unknown conversions**, lines 264-265 (expects 29 and `[ %][% ][y][ y][y ]`): return 30. - `%5%` and `%-5%` agree with the test. - `%y` is printed with its `%`, the difference @adriadam10 suggested might exist. The width and `-` flag are applied and cover both characters. - `%05y` is not in the test. It gives ` %y`: blank padding, as the debt line says the host `%c` does, but with the `%`. - **Throw list**, lines 266-270: `%l5d`, `%lqd`, `%qc`, `%lhd` and `%l*d` don't fail. Each returns 3 and prints as text: `%qc` as written, the others without the `l`. - **Trailing `%`**, lines 271-272 (expect `"100%"` → 3 and `100`, and `"%d done 5% "` with 7 → 8 and `7 done 5`): the output does not stop at the `%`. The returns are 54 and 51. The `100` text matches only because a NUL is written right after it (see below). - In the probe ELF, the two formats are followed by these strings. The first comes from the probe's `main.c`, the second from its `oracle.c`: ``` 0xe6c9: "100%\0case swprintf fmt=%s ret=%d text=%s nul_at=%zu\0" 0xebfe: "%d done 5% \0resolve sym=%s module=%s loaded=no\0" ``` - Both results fit one reading: the NUL that ends the format is skipped, and the byte after it becomes the conversion. - For `"100%"` that is `%c` of the first (zero) argument, which writes a NUL. That is why the text is only `100`. - For `"%d done 5% "` the space is taken as a flag and the conversion is `r`, an unknown conversion printed as `%r`. - Formatting the rest of each string with the probe's zero arguments gives exactly 54 and 51. - This reading comes from the outputs and the ELF bytes, not from disassembly. 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`/`%U` and unknown conversions, the results are closer to what the debt line (`docs/dev/debt/libc.md`, line 32) says glibc does ("prints `%D`, `%O`, `%U` and 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: - a title's `libc.prx` and its `_Printf` / `_Printf.percent` - whether any title passes these formats at all - narrow `%m` - the size-4 `"ab%dcd%"` case (line 273) - the test's own argument values. The probe used different ones, e.g. `-5` for `%qd` and `3` instead of `7` in `"%d done 5% "`. The `q`, `%D`/`%O`/`%U`, unknown-conversion and throw-list outputs print no arguments. - the Windows host I can attach the probe source, the ELF and the full log.
MarcZX10 commented 2026-10-19 15:07:29 +00:00 (Migrated from github.com)

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’s libc.prx Dinkumware _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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6270473460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6270473460). Originally posted by [MarcZX10](https://github.com/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’s `libc.prx` Dinkumware `_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.
MarcZX10 commented 2026-10-19 15:09:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:09:26Z.


Rebased onto current main at 00d7e611ef and corrected the debt entry to describe this as Windows host-side behavior; the title libc.prx behavior 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 passes git diff --check and 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6270514129 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6270514129). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T15:09:26Z. --- Rebased onto current `main` at `00d7e611ef` and corrected the debt entry to describe this as Windows host-side behavior; the title `libc.prx` behavior 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 passes `git diff --check` and 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.
MarcZX10 commented 2026-10-19 19:16:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T19:16:29Z.


I do not have the requested title libc.prx disassembly or a console-side _Printf run for %q, %D/%O/%U, unknown conversions, and trailing %; the libSceLibcInternal.sprx probe does not resolve that gap. I also have not run the Windows-only guest_formatting cases 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6275253469 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6275253469). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T19:16:29Z. --- I do not have the requested title `libc.prx` disassembly or a console-side `_Printf` run for `%q`, `%D`/`%O`/`%U`, unknown conversions, and trailing `%`; the `libSceLibcInternal.sprx` probe does not resolve that gap. I also have not run the Windows-only `guest_formatting` cases 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.
MarcZX10 commented 2026-10-20 22:37:42 +00:00 (Migrated from github.com)

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’s libc.prx _Printf handles 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 _Printf inspection is still needed before changing the current throw behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303341429 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3987#issuecomment-6303341429). Originally posted by [MarcZX10](https://github.com/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’s `libc.prx` `_Printf` handles 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 `_Printf` inspection is still needed before changing the current throw behavior.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3987
No description provided.