feat(libc): cover the codecvt, numpunct, num_put and time_put facets, their ids and std::clog #9038

Merged
akkadbakkad89 merged 8 commits from upstream-pr/9038 into main 2026-10-24 17:39:28 +00:00
akkadbakkad89 commented 2026-10-21 10:33:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-21T10:33:43Z.


What

Implements the four Dinkumware facet _Getcat exports plus the two missing facet id objects and std::clog, all evidence-backed by the bundled console libc.prx from a shipping title's sce_module (unwrapped with tools/unwrap_self.py, dynsym/NID-resolved, disassembled, and vtable-relocated):

  • codecvt<char,char,_Mbstatet>::_Getcat (zyhiiLKndO8): console builds a bare 0x10-byte facet, category 2. Its virtuals were fully disassembled: always_noconv=true, encoding/max_length=1, in/out copy the source range pointer through and return noconv(3), unshift returns ok(0), length returns min(last1-first1, count).
  • numpunct<char>::_Getcat (zCB24JBovnQ): console builds a 0x30-byte facet, category 4, with the C-locale table at fixed offsets — grouping "" @0x10, '.' @0x18, ',' @0x19, "false" @0x20, "true" @0x28. The five do_* virtuals were disassembled and return guest Strings via the inline-capacity assignment path (vtable order: falsename before truename).
  • num_put<char,...>::_Getcat (hNAh1l09UpA): console allocates a bare 0x10-byte facet, category 4; the formatting virtuals' exact behaviour is not yet proven, so they throw NotImplemented_nid_no_patch by name rather than fabricating output.
  • time_put<char,...>::_Getcat (ec0YLGHS8cw): console allocates a 0xb8-byte facet, category 5, containing a _Locinfo-style time-format table after the facet header; formatting virtuals throw for the same reason.
  • numpunct<char>::id (9iXtwvGVFRI) and time_put<char,...>::id (BamOsNbUcn4): zeroed 8-byte std::locale::id objects matching the console data exports and the existing collate/num_get ids.
  • std::clog (jSquWN7i7lc): zeroed stream storage like cout/cerr/cin.
  • std::wclog (awr1A2VAVZQ): the same zeroed stream storage beside wcerr, completing the eight NSTDSTR slots (cin/cout/cerr/clog and their wide counterparts) that ios_base::_Addstd registers.

All facets use the established GuestLocale::Facet refcounted-vtable layout with static_assert-pinned offsets, and _Getcat falls back to the C locale for an unknown locale argument — matching console behaviour, which does not reject by name (unlike collate::_Getcat); recorded in the debt note.

Tested

  • CheckFacetGetcat() in core/libs/tests/GuestLocale.cpp, now called from the test main: category values, allocation shapes, codecvt conversion results (noconv/ok/length), numpunct C-locale strings and separators, id objects, and retain/release refcounting. The unimplemented num_put/time_put formatting virtuals still throw NotImplemented_nid_no_patch, but the test no longer pins that behaviour.
  • g++ -fsyntax-only on LocaleSupport.cpp and the test: clean.
  • Focused standalone driver against the real LocaleSupport.o: all new checks pass. The pre-existing guest_locale stub-harness failure reproduces identically on unmodified origin/main (environmental, not a regression).
  • python3 tools/check_conventions.py --base origin/main: pass.
  • python3 tools/pr_overlap.py --branch feat/libc-facet-getcat: no same-export overlap. #7081 touches LocaleSupport.cpp for sceAmpr* symbols only; #8880 covers num_get/time_get — disjoint from this num_put/time_put/numpunct/codecvt slice. Remaining flags are docs/dev/debt/libc.md tail edits.

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:4950169119 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9038). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-21T10:33:43Z. --- ### What Implements the four Dinkumware facet `_Getcat` exports plus the two missing facet `id` objects and `std::clog`, all evidence-backed by the bundled console `libc.prx` from a shipping title's `sce_module` (unwrapped with `tools/unwrap_self.py`, dynsym/NID-resolved, disassembled, and vtable-relocated): - `codecvt<char,char,_Mbstatet>::_Getcat` (`zyhiiLKndO8`): console builds a bare 0x10-byte facet, category 2. Its virtuals were fully disassembled: `always_noconv`=true, `encoding`/`max_length`=1, `in`/`out` copy the source range pointer through and return `noconv`(3), `unshift` returns `ok`(0), `length` returns `min(last1-first1, count)`. - `numpunct<char>::_Getcat` (`zCB24JBovnQ`): console builds a 0x30-byte facet, category 4, with the C-locale table at fixed offsets — grouping `""` @0x10, `'.'` @0x18, `','` @0x19, `"false"` @0x20, `"true"` @0x28. The five `do_*` virtuals were disassembled and return guest `String`s via the inline-capacity assignment path (vtable order: falsename before truename). - `num_put<char,...>::_Getcat` (`hNAh1l09UpA`): console allocates a bare 0x10-byte facet, category 4; the formatting virtuals' exact behaviour is not yet proven, so they throw `NotImplemented_nid_no_patch` by name rather than fabricating output. - `time_put<char,...>::_Getcat` (`ec0YLGHS8cw`): console allocates a 0xb8-byte facet, category 5, containing a `_Locinfo`-style time-format table after the facet header; formatting virtuals throw for the same reason. - `numpunct<char>::id` (`9iXtwvGVFRI`) and `time_put<char,...>::id` (`BamOsNbUcn4`): zeroed 8-byte `std::locale::id` objects matching the console data exports and the existing `collate`/`num_get` ids. - `std::clog` (`jSquWN7i7lc`): zeroed stream storage like `cout`/`cerr`/`cin`. - `std::wclog` (`awr1A2VAVZQ`): the same zeroed stream storage beside `wcerr`, completing the eight `NSTDSTR` slots (`cin`/`cout`/`cerr`/`clog` and their wide counterparts) that `ios_base::_Addstd` registers. All facets use the established `GuestLocale::Facet` refcounted-vtable layout with `static_assert`-pinned offsets, and `_Getcat` falls back to the C locale for an unknown locale argument — matching console behaviour, which does not reject by name (unlike `collate::_Getcat`); recorded in the debt note. ### Tested - `CheckFacetGetcat()` in `core/libs/tests/GuestLocale.cpp`, now called from the test `main`: category values, allocation shapes, `codecvt` conversion results (`noconv`/`ok`/`length`), `numpunct` C-locale strings and separators, `id` objects, and `retain`/`release` refcounting. The unimplemented `num_put`/`time_put` formatting virtuals still throw `NotImplemented_nid_no_patch`, but the test no longer pins that behaviour. - `g++ -fsyntax-only` on `LocaleSupport.cpp` and the test: clean. - Focused standalone driver against the real `LocaleSupport.o`: all new checks pass. The pre-existing `guest_locale` stub-harness failure reproduces identically on unmodified `origin/main` (environmental, not a regression). - `python3 tools/check_conventions.py --base origin/main`: pass. - `python3 tools/pr_overlap.py --branch feat/libc-facet-getcat`: no same-export overlap. #7081 touches `LocaleSupport.cpp` for `sceAmpr*` symbols only; #8880 covers `num_get`/`time_get` — disjoint from this `num_put`/`time_put`/`numpunct`/`codecvt` slice. Remaining flags are `docs/dev/debt/libc.md` tail edits. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
akkadbakkad89 commented 2026-10-21 11:21:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-21T11:21:02Z.


CI note: relinker (windows-latest, g++) failed on a timeout unrelated to this change — shader_cache_native_paths hit its 20 s TIMEOUT property (CMakeLists.txt:134); the test is a python/cmake path check in core/shader/recompiler, untouched by this diff (libc prx + locale test + debt doc only). main's own Build run also failed a job in the same window (linux, run 39586562576), so this looks like runner flakiness — a re-run should clear it. All other legs (ubuntu g++, macOS clang++, asan) passed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314666466 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9038#issuecomment-6314666466). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-21T11:21:02Z. --- CI note: `relinker (windows-latest, g++)` failed on a timeout unrelated to this change — `shader_cache_native_paths` hit its 20 s `TIMEOUT` property (CMakeLists.txt:134); the test is a python/cmake path check in `core/shader/recompiler`, untouched by this diff (libc prx + locale test + debt doc only). `main`'s own Build run also failed a job in the same window (linux, run 39586562576), so this looks like runner flakiness — a re-run should clear it. All other legs (ubuntu g++, macOS clang++, asan) passed.
harisibrar1 commented 2026-10-24 15:38:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T15:38:14Z.

Review: COMMENTED


Checked against main b607bfdc8b and the NID calculator, plus MSVC/Dinkumware's <xlocale>/<xlocnum> facet declarations:

  • The other NIDs (zyhiiLKndO8, zCB24JBovnQ, hNAh1l09UpA, ec0YLGHS8cw, 9iXtwvGVFRI, jSquWN7i7lc, awr1A2VAVZQ) all match, and I confirm @oneandonlydean's point that time_put::id at LocaleSupport.cpp:387 still hashes to p0ahIkj6K-0 rather than BamOsNbUcn4.
  • The branch still merges cleanly into current main, and none of these exports exist there yet. The new facets reuse main's no-op destroy and _ZdlPv delete, so numpunct's static strings are never freed, which is good.
  • docs/dev/debt/libc.md:138 looks like a bad splice: "zeroed as on the consoleing the destroy/deleteObject/retain/release base used for collate." is a broken sentence, and the clog/id sentence then appears a second time. Could you clean it up?
  • The description says the C-locale fallback for an unknown locale argument (unlike collate's throw) is recorded in the debt note, but the entry doesn't mention it, or std::wclog. It would help to add both.
  • Small nit: MSVC declares do_always_noconv, do_max_length, do_encoding and then do_in, do_out, so if the console uses that order, CodecvtVtable's names at 0x28/0x30 and 0x38/0x40 (and the out == 0x38 static_assert) are swapped. Behaviour is unaffected, since each pair shares one function.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638812156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9038#pullrequestreview-5638812156). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T15:38:14Z. **Review:** COMMENTED --- Checked against main b607bfdc8b and the NID calculator, plus MSVC/Dinkumware's `<xlocale>`/`<xlocnum>` facet declarations: - The other NIDs (zyhiiLKndO8, zCB24JBovnQ, hNAh1l09UpA, ec0YLGHS8cw, 9iXtwvGVFRI, jSquWN7i7lc, awr1A2VAVZQ) all match, and I confirm @oneandonlydean's point that `time_put::id` at `LocaleSupport.cpp:387` still hashes to `p0ahIkj6K-0` rather than `BamOsNbUcn4`. - The branch still merges cleanly into current main, and none of these exports exist there yet. The new facets reuse main's no-op destroy and `_ZdlPv` delete, so numpunct's static strings are never freed, which is good. - `docs/dev/debt/libc.md:138` looks like a bad splice: "zeroed as on the consoleing the `destroy`/`deleteObject`/`retain`/`release` base used for `collate`." is a broken sentence, and the clog/id sentence then appears a second time. Could you clean it up? - The description says the C-locale fallback for an unknown locale argument (unlike collate's throw) is recorded in the debt note, but the entry doesn't mention it, or `std::wclog`. It would help to add both. - Small nit: MSVC declares `do_always_noconv, do_max_length, do_encoding` and then `do_in, do_out`, so if the console uses that order, `CodecvtVtable`'s names at 0x28/0x30 and 0x38/0x40 (and the `out == 0x38` static_assert) are swapped. Behaviour is unaffected, since each pair shares one function. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
harisibrar1 commented 2026-10-24 16:37:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T16:37:25Z.

Review: APPROVED


Re-checked head c89baddeab against main feb5059ac4:

  • time_put<char>::id is now spelled _ZNSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE (LocaleSupport.cpp:387), which hashes to BamOsNbUcn4, so @oneandonlydean's point is fixed too.
  • The libc.md entry is clean now: the facet-lifetime sentence and the clog/id sentence are separate and complete, and it records the C-locale fallback for a non-C name and std::wclog.
  • CodecvtVtable follows the MSVC/Dinkumware order (alwaysNoconv, maxLength, encoding, in, out, …), with the 0x38 static_assert on in; behaviour is unchanged since each pair shares one function.
  • It still merges cleanly into main. Thanks, LGTM.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638985841 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9038#pullrequestreview-5638985841). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T16:37:25Z. **Review:** APPROVED --- Re-checked head c89baddeab against main feb5059ac4: - `time_put<char>::id` is now spelled `_ZNSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE` (LocaleSupport.cpp:387), which hashes to `BamOsNbUcn4`, so @oneandonlydean's point is fixed too. - The libc.md entry is clean now: the facet-lifetime sentence and the clog/id sentence are separate and complete, and it records the C-locale fallback for a non-C name and `std::wclog`. - `CodecvtVtable` follows the MSVC/Dinkumware order (`alwaysNoconv`, `maxLength`, `encoding`, `in`, `out`, …), with the 0x38 static_assert on `in`; behaviour is unchanged since each pair shares one function. - It still merges cleanly into main. Thanks, LGTM. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!9038
No description provided.