fix(libc): format %p the way the console's libc does #7562

Merged
slick-daddy merged 1 commit from upstream-pr/7562 into main 2026-10-18 18:24:48 +00:00
slick-daddy commented 2026-10-18 14:06:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slick-daddy on 2026-10-18T14:06:37Z.


What

Formats %p as the console's libSceLibcInternal.sprx does, measured on firmware 12.70 in #7549, instead of the FreeBSD form. That module prints bare lowercase hex with no 0x prefix (0 for a null pointer), ignores #, + and the space flag, counts only the digits towards the width, pads with spaces on the left (on the right for -, with zeros for 0 when there is no precision), treats the precision as the minimum number of digits, prints nothing for a null pointer under %.0p and accepts l. A title does not see the 0x… form on hardware.

FormatPointer drops the prefix and the two columns it took from the width, the narrow Windows formatter accepts %lp, and Linux routes %p and %lp to the guest formatter instead of glibc, which prints the FreeBSD form and (nil) for a null pointer. The wide family still refuses %lp and returns -1, because the console's swprintf was not measured with it.

Closes #7549
Depends on: #6315

Tested

Windows 11 Enterprise 26200, MinGW-w64 GCC (WinLibs), Release. Host tests only, no title: guest_formatting and guest_wide_formatting fail before the change and pass after it; guest_allocating_strings, guest_scan_count, guest_wide_strings, guest_strftime, guest_strings, guest_standard_streams and its closed-stdout variant, file_streams and guest_search pass unchanged. The console side is #7549's own payload measurement, not re-run here, and the Linux selector was not executed on this Windows host.

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: #6483
  • Fixes: #7549
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
    Edge cases worth reading before merge:
  • #6483 overlaps. It adds p to the same Linux selector and renames the same function to RequiresGuestFormatting; that change is carried here, so the two branches conflict and its credit belongs to its author. Declared in Depends on per CONTRIBUTING.md:64.
  • Linux routing has a wider surface. Any format containing %p now goes to the guest formatter, so one that combines %p with a conversion the formatter refuses, such as an argument position above 99, throws there instead of reaching glibc.
  • Unmeasured pointer cases follow the formatter's own rules and are recorded in docs/dev/debt/libc.md: a width beside %.0p, the 0 flag beside a precision (C17 ignores 0 there) and %.0p of a non-null pointer were not run on the console.
  • Wide %lp still returns -1 instead of formatting. One probe on hardware settles whether to accept it.
  • Not part of the diff: CMake needed git submodule update --init --recursive here, since libjpeg-turbo, ZArchive/zstd, mbedtls/framework, tracy, libusb-cmake and SPIRV-Tools were not checked out.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4909744017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7562). Originally posted by [slick-daddy](https://github.com/slick-daddy) on 2026-10-18T14:06:37Z. --- ### What Formats `%p` as the console's `libSceLibcInternal.sprx` does, measured on firmware 12.70 in #7549, instead of the FreeBSD form. That module prints bare lowercase hex with no `0x` prefix (`0` for a null pointer), ignores `#`, `+` and the space flag, counts only the digits towards the width, pads with spaces on the left (on the right for `-`, with zeros for `0` when there is no precision), treats the precision as the minimum number of digits, prints nothing for a null pointer under `%.0p` and accepts `l`. A title does not see the `0x…` form on hardware. `FormatPointer` drops the prefix and the two columns it took from the width, the narrow Windows formatter accepts `%lp`, and Linux routes `%p` and `%lp` to the guest formatter instead of glibc, which prints the FreeBSD form and `(nil)` for a null pointer. The wide family still refuses `%lp` and returns -1, because the console's `swprintf` was not measured with it. Closes #7549 Depends on: #6315 ### Tested Windows 11 Enterprise 26200, MinGW-w64 GCC (WinLibs), Release. Host tests only, no title: `guest_formatting` and `guest_wide_formatting` fail before the change and pass after it; `guest_allocating_strings`, `guest_scan_count`, `guest_wide_strings`, `guest_strftime`, `guest_strings`, `guest_standard_streams` and its closed-stdout variant, `file_streams` and `guest_search` pass unchanged. The console side is #7549's own payload measurement, not re-run here, and the Linux selector was not executed on this Windows host. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: #6483 - [x] Fixes: #7549 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Edge cases worth reading before merge: - #6483 overlaps. It adds p to the same Linux selector and renames the same function to RequiresGuestFormatting; that change is carried here, so the two branches conflict and its credit belongs to its author. Declared in Depends on per CONTRIBUTING.md:64. - Linux routing has a wider surface. Any format containing %p now goes to the guest formatter, so one that combines %p with a conversion the formatter refuses, such as an argument position above 99, throws there instead of reaching glibc. - Unmeasured pointer cases follow the formatter's own rules and are recorded in docs/dev/debt/libc.md: a width beside %.0p, the 0 flag beside a precision (C17 ignores 0 there) and %.0p of a non-null pointer were not run on the console. - Wide %lp still returns -1 instead of formatting. One probe on hardware settles whether to accept it. - Not part of the diff: CMake needed git submodule update --init --recursive here, since libjpeg-turbo, ZArchive/zstd, mbedtls/framework, tracy, libusb-cmake and SPIRV-Tools were not checked out.
github-actions[bot] commented 2026-10-18 14:13:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:13:44Z.


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/tests/GuestWideFormatting.cpp
docs/dev/debt/libc.md
PR 6044 core/libs/tests/Formatting.cpp
core/libs/tests/GuestWideFormatting.cpp
PR 6226 docs/dev/debt/libc.md
PR 6334 docs/dev/debt/libc.md
PR 6483 core/libs/prx/libc/src/Formatting.cpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 6541 docs/dev/debt/libc.md
PR 6565 docs/dev/debt/libc.md
PR 6879 core/libs/prx/libc/include/WindowsFormatting.hpp
PR 7201 core/libs/tests/Formatting.cpp
PR 7332 core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250932584 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7562#issuecomment-6250932584). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:13:44Z. --- <!-- 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/include/WindowsFormatting.hpp`<br>`core/libs/tests/Formatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `core/libs/tests/GuestWideFormatting.cpp`<br>`docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/Formatting.cpp`<br>`core/libs/tests/GuestWideFormatting.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6334](https://www.github.com/boykopovar/AnyPS5/pull/6334) | `docs/dev/debt/libc.md` | | [PR 6483](https://www.github.com/boykopovar/AnyPS5/pull/6483) | `core/libs/prx/libc/src/Formatting.cpp`<br>`core/libs/tests/Formatting.cpp`<br>`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 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libc/include/WindowsFormatting.hpp` | | [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 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `docs/dev/debt/libc.md` |
TheTerr4 commented 2026-10-18 14:59:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheTerr4 on 2026-10-18T14:59:38Z.


Windows runtime check. Windows 11 Pro 10.0.26200, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7 (UCRT), Release.

This PR's head 536fef322 merged cleanly into main 385ed71f2; the full build and libs both exit 0.

  • guest_formatting and guest_wide_formatting pass, three repeated -j1 runs.
  • Negative control: with libc/include/WindowsFormatting.hpp and libc/src/Formatting.cpp restored to main's versions, both tests abort (exit 0xc0000409).
  • Not run: the full suite, Linux, macOS.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251391219 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7562#issuecomment-6251391219). Originally posted by [TheTerr4](https://github.com/TheTerr4) on 2026-10-18T14:59:38Z. --- Windows runtime check. Windows 11 Pro 10.0.26200, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7 (UCRT), Release. This PR's head `536fef322` merged cleanly into `main` `385ed71f2`; the full build and `libs` both exit 0. - `guest_formatting` and `guest_wide_formatting` pass, three repeated `-j1` runs. - Negative control: with `libc/include/WindowsFormatting.hpp` and `libc/src/Formatting.cpp` restored to `main`'s versions, both tests abort (exit 0xc0000409). - Not run: the full suite, Linux, macOS. AI-assisted: yes (Claude Code).
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!7562
No description provided.