fix(libc): use guest pointer formatting on Linux #6483

Closed
casualmelatonin wants to merge 3 commits from upstream-pr/6483 into main
casualmelatonin commented 2026-10-15 17:06:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by casualmelatonin on 2026-10-15T17:06:10Z.


What

Route Linux narrow printf-family formats containing %p through the existing shared guest formatter. Previously a null pointer could print (nil) in a narrow format but 0x0 when a wide conversion selected the shared formatter. Rename the selector to RequiresGuestFormatting and update its callers, including allocating, stream and argument-list forms.

Enable the existing pointer-formatting cases on Linux and add regressions for mixed wide/pointer formats, escaped percent signs, positional width/precision, mixed integer/floating-point arguments, argument-list and secure wrappers, truncation, %n and allocating output. Update the libc debt entry, retaining the unverified console behavior and the remaining host-only NaN discrepancy.

Reference behavior: FreeBSD 11.4 vfprintf. The existing pointer formatter supplies lowercase hexadecimal with a 0x prefix. No PS5 measurement is claimed.

Overlap reviewed: no duplicate Linux pointer-routing change found. #3987 extends shared formatter conversions, #5303 changes the wide family, and #6315 changes secure formatting constraints. #6315 touches two selector callers and may require a rebase when either PR merges; merge order still needs confirmation with its author. #6044 reorganizes tests and may require relocating these regression cases. Other shared test/debt paths reported by the overlap check concern separate behavior. No functional dependency is required for the conversions covered here.

Tested

Local checks and an independently reported Linux runtime run are separated below. Maintainer full Linux/Windows Build workflow checks remain pending.

  • External report by jotitadev, not reproduced on this Mac: Ubuntu 26.04, i7-8700, GCC 15.2/glibc, Release full build with BUILD_TESTING=ON, head cf5e89015 applied to main 03c4cb5. The PR's tests on the original source fail guest_formatting; with the fix, guest_formatting and guest_wide_formatting pass. Additional mixed-conversion probes matched glibc apart from the documented NaN behavior. The 649-test non-GPU suite matched main, with the same two pre-existing file-writer failures.
  • Apple Silicon macOS, AppleClang 21, Release relinker-only build: passed; CTest 172/172 passed in 23.59 seconds. This build does not exercise the changed libc runtime.
  • Native ARM checks of verbatim extracted selector, FormatPointer and FormatOutput bodies: 83/83 passed with C++20, warnings as errors, AddressSanitizer and UndefinedBehaviorSanitizer. The original selector from origin/main fails the 15 pointer-routing assertions in the same harness. These are helper checks, not guest ABI tests; the harness was kept outside the repository.
  • Actual Formatting.cpp compiled and linked into an x86-64 Mach-O harness; modified core/libs/tests/Formatting.cpp passed x86-64 syntax checking. An external Darwin compatibility shim was used for existing platform macros and GCC varargs builtins. No repository compatibility shim was added. The x86 binary could not run because Rosetta is unavailable.
  • tools/check_conventions.py --base origin/main: passed with bundled Python 3; git diff --check: passed.
  • Local full build configuration attempted with BUILD_TESTING=ON: blocked by uninitialized third-party submodules. Linux/Windows guest runtime tests were not run locally; Windows and game/console behavior remain unverified here. A maintainer-triggered full Build workflow is still needed.

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:4877008996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6483). Originally posted by [casualmelatonin](https://github.com/casualmelatonin) on 2026-10-15T17:06:10Z. --- ### What Route Linux narrow printf-family formats containing `%p` through the existing shared guest formatter. Previously a null pointer could print `(nil)` in a narrow format but `0x0` when a wide conversion selected the shared formatter. Rename the selector to `RequiresGuestFormatting` and update its callers, including allocating, stream and argument-list forms. Enable the existing pointer-formatting cases on Linux and add regressions for mixed wide/pointer formats, escaped percent signs, positional width/precision, mixed integer/floating-point arguments, argument-list and secure wrappers, truncation, `%n` and allocating output. Update the libc debt entry, retaining the unverified console behavior and the remaining host-only NaN discrepancy. Reference behavior: [FreeBSD 11.4 vfprintf](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libc/stdio/vfprintf.c#L787-L800). The existing pointer formatter supplies lowercase hexadecimal with a `0x` prefix. No PS5 measurement is claimed. Overlap reviewed: no duplicate Linux pointer-routing change found. #3987 extends shared formatter conversions, #5303 changes the wide family, and #6315 changes secure formatting constraints. #6315 touches two selector callers and may require a rebase when either PR merges; merge order still needs confirmation with its author. #6044 reorganizes tests and may require relocating these regression cases. Other shared test/debt paths reported by the overlap check concern separate behavior. No functional dependency is required for the conversions covered here. ### Tested Local checks and an independently reported Linux runtime run are separated below. Maintainer full Linux/Windows Build workflow checks remain pending. - External report by [jotitadev](https://github.com/boykopovar/AnyPS5/pull/6483#pullrequestreview-5537799724), not reproduced on this Mac: Ubuntu 26.04, i7-8700, GCC 15.2/glibc, Release full build with `BUILD_TESTING=ON`, head `cf5e89015` applied to `main` `03c4cb5`. The PR's tests on the original source fail `guest_formatting`; with the fix, `guest_formatting` and `guest_wide_formatting` pass. Additional mixed-conversion probes matched glibc apart from the documented NaN behavior. The 649-test non-GPU suite matched main, with the same two pre-existing file-writer failures. - Apple Silicon macOS, AppleClang 21, Release relinker-only build: passed; CTest 172/172 passed in 23.59 seconds. This build does not exercise the changed libc runtime. - Native ARM checks of verbatim extracted selector, `FormatPointer` and `FormatOutput` bodies: 83/83 passed with C++20, warnings as errors, AddressSanitizer and UndefinedBehaviorSanitizer. The original selector from `origin/main` fails the 15 pointer-routing assertions in the same harness. These are helper checks, not guest ABI tests; the harness was kept outside the repository. - Actual `Formatting.cpp` compiled and linked into an x86-64 Mach-O harness; modified `core/libs/tests/Formatting.cpp` passed x86-64 syntax checking. An external Darwin compatibility shim was used for existing platform macros and GCC varargs builtins. No repository compatibility shim was added. The x86 binary could not run because Rosetta is unavailable. - `tools/check_conventions.py --base origin/main`: passed with bundled Python 3; `git diff --check`: passed. - Local full build configuration attempted with `BUILD_TESTING=ON`: blocked by uninitialized third-party submodules. Linux/Windows guest runtime tests were not run locally; Windows and game/console behavior remain unverified here. A maintainer-triggered full Build workflow is still needed. ### 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
github-actions[bot] commented 2026-10-15 17:29:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T17:29:17Z.


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 3965 docs/dev/debt/libc.md
PR 3987 core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 4627 core/libs/tests/Formatting.cpp
PR 5021 core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/tests/Formatting.cpp
PR 6144 docs/dev/debt/libc.md
PR 6217 docs/dev/debt/libc.md
PR 6226 docs/dev/debt/libc.md
PR 6315 core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 6322 docs/dev/debt/libc.md
PR 6330 docs/dev/debt/libc.md
PR 6331 docs/dev/debt/libc.md
PR 6334 docs/dev/debt/libc.md
PR 6339 docs/dev/debt/libc.md
PR 6345 docs/dev/debt/libc.md
PR 6447 core/libs/prx/libc/src/Formatting.cpp
PR 6469 docs/dev/debt/libc.md
PR 6541 docs/dev/debt/libc.md
PR 6565 docs/dev/debt/libc.md
PR 6610 docs/dev/debt/libc.md
PR 6686 docs/dev/debt/libc.md
PR 6707 docs/dev/debt/libc.md
PR 6713 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 6842 docs/dev/debt/libc.md
PR 6916 docs/dev/debt/libc.md
PR 6975 docs/dev/debt/libc.md
PR 6985 docs/dev/debt/libc.md
PR 7039 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7201 core/libs/tests/Formatting.cpp
PR 7332 core/libs/tests/Formatting.cpp
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 7411 docs/dev/debt/libc.md
PR 7417 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7506 docs/dev/debt/libc.md
PR 7525 core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 7529 docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7545 docs/dev/debt/libc.md
PR 7546 docs/dev/debt/libc.md
PR 7562 core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6198200836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6483#issuecomment-6198200836). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T17:29:17Z. --- <!-- pr-overlap --> 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 3965](https://www.github.com/boykopovar/AnyPS5/pull/3965) | `docs/dev/debt/libc.md` | | [PR 3987](https://www.github.com/boykopovar/AnyPS5/pull/3987) | `core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 4627](https://www.github.com/boykopovar/AnyPS5/pull/4627) | `core/libs/tests/Formatting.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/Formatting.cpp` | | [PR 6144](https://www.github.com/boykopovar/AnyPS5/pull/6144) | `docs/dev/debt/libc.md` | | [PR 6217](https://www.github.com/boykopovar/AnyPS5/pull/6217) | `docs/dev/debt/libc.md` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6315](https://www.github.com/boykopovar/AnyPS5/pull/6315) | `core/libs/prx/libc/src/Formatting.cpp`<br>`core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 6322](https://www.github.com/boykopovar/AnyPS5/pull/6322) | `docs/dev/debt/libc.md` | | [PR 6330](https://www.github.com/boykopovar/AnyPS5/pull/6330) | `docs/dev/debt/libc.md` | | [PR 6331](https://www.github.com/boykopovar/AnyPS5/pull/6331) | `docs/dev/debt/libc.md` | | [PR 6334](https://www.github.com/boykopovar/AnyPS5/pull/6334) | `docs/dev/debt/libc.md` | | [PR 6339](https://www.github.com/boykopovar/AnyPS5/pull/6339) | `docs/dev/debt/libc.md` | | [PR 6345](https://www.github.com/boykopovar/AnyPS5/pull/6345) | `docs/dev/debt/libc.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libc/src/Formatting.cpp` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6541](https://www.github.com/boykopovar/AnyPS5/pull/6541) | `docs/dev/debt/libc.md` | | [PR 6565](https://www.github.com/boykopovar/AnyPS5/pull/6565) | `docs/dev/debt/libc.md` | | [PR 6610](https://www.github.com/boykopovar/AnyPS5/pull/6610) | `docs/dev/debt/libc.md` | | [PR 6686](https://www.github.com/boykopovar/AnyPS5/pull/6686) | `docs/dev/debt/libc.md` | | [PR 6707](https://www.github.com/boykopovar/AnyPS5/pull/6707) | `docs/dev/debt/libc.md` | | [PR 6713](https://www.github.com/boykopovar/AnyPS5/pull/6713) | `docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 6842](https://www.github.com/boykopovar/AnyPS5/pull/6842) | `docs/dev/debt/libc.md` | | [PR 6916](https://www.github.com/boykopovar/AnyPS5/pull/6916) | `docs/dev/debt/libc.md` | | [PR 6975](https://www.github.com/boykopovar/AnyPS5/pull/6975) | `docs/dev/debt/libc.md` | | [PR 6985](https://www.github.com/boykopovar/AnyPS5/pull/6985) | `docs/dev/debt/libc.md` | | [PR 7039](https://www.github.com/boykopovar/AnyPS5/pull/7039) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/tests/Formatting.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7386](https://www.github.com/boykopovar/AnyPS5/pull/7386) | `core/libs/prx/libc/src/Formatting.cpp`<br>`core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7411](https://www.github.com/boykopovar/AnyPS5/pull/7411) | `docs/dev/debt/libc.md` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `docs/dev/debt/libc.md` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7506](https://www.github.com/boykopovar/AnyPS5/pull/7506) | `docs/dev/debt/libc.md` | | [PR 7525](https://www.github.com/boykopovar/AnyPS5/pull/7525) | `core/libs/prx/libc/src/Formatting.cpp`<br>`core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7529](https://www.github.com/boykopovar/AnyPS5/pull/7529) | `docs/dev/debt/libc.md` | | [PR 7544](https://www.github.com/boykopovar/AnyPS5/pull/7544) | `docs/dev/debt/libc.md` | | [PR 7545](https://www.github.com/boykopovar/AnyPS5/pull/7545) | `docs/dev/debt/libc.md` | | [PR 7546](https://www.github.com/boykopovar/AnyPS5/pull/7546) | `docs/dev/debt/libc.md` | | [PR 7562](https://www.github.com/boykopovar/AnyPS5/pull/7562) | `core/libs/prx/libc/src/Formatting.cpp`<br>`core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` |
jotitadev commented 2026-10-15 18:09:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T18:09:35Z.

Review: COMMENTED


Linux run, since the Tested section is empty and the change only affects Linux.

Ubuntu 26.04, i7-8700, gcc 15.2 (glibc host), Release, BUILD_TESTING=ON, full build. Head cf5e89015 applied on main 03c4cb5e7.

  • Test only (the PR's Formatting.cpp test on main's source): guest_formatting fails with Formatting check failed. The pointer checks that used to be Windows-only now run on Linux.
  • With the fix: guest_formatting and guest_wide_formatting pass.
  • Extra probe on the fixed build. When a format has %p, the rest of it now goes through the shared formatter on Linux too, so I compared each conversion with glibc. These all match glibc's output: %lld %zu %hd %hhd %jd %.3f %e %g %a %Lf %s %5.2s %c %x %X %#o. printf and libc_printf print 0x0|5|x for "%p|%d|%s" with a null pointer. The only difference is the documented NaN one, and it now depends on the format. "%p %f" with -nan prints nan, while "%f" alone still prints -nan, and +/space are honored only without %p.
  • Non-GPU suite (649 tests, -E "^agc|gpu|vulkan|video_out", -j8): same result as main. Only file_writer_binary and file_writer_text fail, on main too (this host's coreutils rejects the command they run).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5537799724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6483#pullrequestreview-5537799724). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T18:09:35Z. **Review:** COMMENTED --- Linux run, since the Tested section is empty and the change only affects Linux. Ubuntu 26.04, i7-8700, gcc 15.2 (glibc host), Release, `BUILD_TESTING=ON`, full build. Head `cf5e89015` applied on `main` 03c4cb5e7. - Test only (the PR's `Formatting.cpp` test on `main`'s source): `guest_formatting` fails with `Formatting check failed`. The pointer checks that used to be Windows-only now run on Linux. - With the fix: `guest_formatting` and `guest_wide_formatting` pass. - Extra probe on the fixed build. When a format has `%p`, the rest of it now goes through the shared formatter on Linux too, so I compared each conversion with glibc. These all match glibc's output: `%lld %zu %hd %hhd %jd %.3f %e %g %a %Lf %s %5.2s %c %x %X %#o`. `printf` and `libc_printf` print `0x0|5|x` for `"%p|%d|%s"` with a null pointer. The only difference is the documented NaN one, and it now depends on the format. `"%p %f"` with `-nan` prints `nan`, while `"%f"` alone still prints `-nan`, and `+`/space are honored only without `%p`. - Non-GPU suite (649 tests, `-E "^agc|gpu|vulkan|video_out"`, `-j8`): same result as `main`. Only `file_writer_binary` and `file_writer_text` fail, on `main` too (this host's coreutils rejects the command they run). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-18 17:59:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:59:40Z.


A new PS5 payload probe in issue #7549 measured snprintf/swprintf from libSceLibcInternal.sprx: %p emits bare lowercase hex (0 for null), without 0x, and # does not add a prefix. PR #6483 currently routes Linux narrow %p through FormatPointer, whose output still has 0x. The probe is for the system libSceLibcInternal.sprx in a payload process, not a title-bundled libc.prx, so scope may differ; I’m sharing it because the PR currently records console behavior as unmeasured. I would not change this branch based on that evidence alone without deciding which guest libc/API behavior this formatter is intended to model.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253235796 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6483#issuecomment-6253235796). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T17:59:40Z. --- A new PS5 payload probe in [issue #7549](https://github.com/boykopovar/AnyPS5/issues/7549) measured `snprintf`/`swprintf` from `libSceLibcInternal.sprx`: `%p` emits bare lowercase hex (`0` for null), without `0x`, and `#` does not add a prefix. PR #6483 currently routes Linux narrow `%p` through `FormatPointer`, whose output still has `0x`. The probe is for the system `libSceLibcInternal.sprx` in a payload process, not a title-bundled `libc.prx`, so scope may differ; I’m sharing it because the PR currently records console behavior as unmeasured. I would not change this branch based on that evidence alone without deciding which guest libc/API behavior this formatter is intended to model.
oneandonlydean commented 2026-10-18 18:25:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T18:25:10Z.


Thanks @casualmelatonin, this change landed as part of #7562 (the same Linux selector change and rename), so I'm closing this as included.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253501431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6483#issuecomment-6253501431). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T18:25:10Z. --- Thanks @casualmelatonin, this change landed as part of #7562 (the same Linux selector change and rename), so I'm closing this as included.

Pull request closed

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!6483
No description provided.