feat(libc,libSceLibcInternal): wire the char16_t and char32_t codecvt facets #21981

Merged
Herolias merged 2 commits from upstream-pr/21981 into main 2026-11-17 07:21:45 +00:00
Herolias commented 2026-11-17 00:43:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Herolias on 2026-11-17T00:43:19Z.


What

This brings back #21252 the way oneandonlydean asked when closing it: "bring it back together with the vtable and id exports" so that it can be judged as one working piece. The do_in/do_out bodies reviewed there are unchanged. They now sit in libc, together with everything else the console's libc exports for these two facets.

libc now exports 22 NIDs for codecvt<char16_t, char, _Mbstatet> and codecvt<char32_t, char, _Mbstatet>: both vtables, both ids, the complete and deleting destructors and every virtual. ps5rs libc.txt lists all 22 for libc. On main libc exports none of them. libSceLibcInternal has do_in/do_out stubs that throw and the metadata bodies, but no vtable points at any of them.

How code reaches it: in Dinkumware V6.00 the three constructors and _Getcat are inline in the class, and id is the only static data member (crt.vc12 xlocale lines 1040-1070 and 1364-1394). A guest that uses either standard facet therefore does three things. It reads the exported id, builds the facet with the inline _Getcat or constructor, which writes the exported vtable into the object, and then calls the virtuals through that vtable. On main the id and vtable imports are data that no library exports, which stops a title at startup (FAIL: unresolved ELF import, WindowsEntryStubBuilder.cpp line 293). I know of no title that does this. None of the eight title import lists (#265-#272) holds one of these NIDs, but those lists name only the NIDs that were new when they were posted, so that shows nothing either way. This PR claims no unblocked title.

  • Vtables (jlNI3SSF41o, 9H2BStEAAMg): thirteen uintptr_t slots each, in this order:

    • offset-to-top and typeinfo, both zero as in libc's other filled vtables;
    • D1 and D0;
    • _Incref and _Decref (RetainFacet and ReleaseFacet, as for libc's other facets);
    • codecvt_base's do_always_noconv, do_max_length and do_encoding (microsoft/STL xlocale lines 691-704);
    • then do_in, do_out, do_unshift and do_length, in the declaration order of lines 965-1188 and 1264-1423.

    That is the shape of the codecvt<char,char,_Mbstatet> vtable, whose libc.md entry records thirteen slots and st_size 104, measured on PPSA26344's libc.prx. The sizes of these two vtables were not measured.

  • Ids (xM5re58mxj8, u2MAta5SS84): 8-byte zeros, like libc's other facet ids.

  • do_in/do_out (+uPwCGfmJHs, 0FKwlv9iH1c, PJ2UDX9Tvwg, eoW60zcLT8Q): #21252's bodies, moved to libc and renamed. They follow microsoft/STL xlocale lines 965-1150 and 1264-1394, which crt.vc12 lines 1081-1255 and 1405-1525 match. _Maxcode is the 8-byte unsigned long at 0x10 and _Mode the 4-byte enum at 0x18. The retry after a byte order mark calls the vtable's do_in slot (0x38 past the address point), as the sources' virtual call does.

  • Metadata and do_unshift: char16_t exports 9Vyfb-I-9xw, BvRS0cGTd6I, Mo6K-pUyNhI and RYTHR81Y-Mc; char32_t exports NQ81EZ7CL6w, E5NdzqEmWuY, DDnr3lDwW8I and c6Lyc6xOp4o.

    • do_unshift, do_max_length and the char32_t do_encoding are main's libSceLibcInternal bodies, moved unchanged. They match crt.vc12 lines 1257-1265, 1304-1309, 1527-1532 and 1571-1581.
    • The char16_t do_unshift returns error while a first surrogate is pending, and the char32_t one returns ok. microsoft/STL returns noconv for char32_t (lines 1396-1400). Where the two releases differ, I followed Dinkumware V6.00, because the console's libc is Dinkumware's.
    • do_always_noconv returns false, and the char16_t do_encoding returns 0 (crt.vc12 lines 1299-1302, 1311-1314 and 1566-1569).
  • Destructors (Oeo9tUbzW7s and zYHryd8vd0w for char16_t, TuhGCIxgLvA and vwMx2NhWdLw for char32_t): the destructor is empty (crt.vc12 lines 1073-1075, 1397-1399), and the deleting destructor then frees the facet with operator delete. D2 is not exported, because ps5rs libc.txt lists no D2 for either facet (9qe-2KFnfNo, lZqo+v9IY9M).

  • libSceLibcInternal: six exports become forwarders to libc's _nid_no_patch bodies:

    • the four do_in/do_out stubs (sceLibcInternalPending3_017, 018, 024 and 025 in Err.cpp), now with their real signatures;
    • the deleting destructors (libSceLibcInternalInventory_090/092 in InventoryExports.cpp).

    The five metadata exports in CodecvtUtfMetadata.cpp forward too, so libSceLibcInternal and libc no longer keep two copies of these bodies. patched_self_imports passes, so no forwarder binds to its own library. Its do_length stubs and sceLibcInternalUnknown6_090_Oeo9tUbzW7s are unchanged.

  • How the 22 are exported: 15 use libc's usual _nid_postfix names. Seven use APS5_EXPORT with a _nid_no_patch body, as libc already does for __cxa_finalize:

    • BvRS0cGTd6I, RYTHR81Y-Mc, lynApfiP6Lw, E5NdzqEmWuY, DDnr3lDwW8I and c6Lyc6xOp4o: libSceLibcInternal already defines those names with _nid_postfix (CodecvtUtfMetadata.cpp lines 6-23, Err.cpp line 272), and check_conventions rejects a second definition as duplicate-export;
    • Oeo9tUbzW7s: libSceLibcInternal exports that NID as sceLibcInternalUnknown6_090_Oeo9tUbzW7s (InventoryExports6.cpp lines 373-376), so the _nid_postfix name is rejected as unknown-nid.
  • One side effect of the Oeo9tUbzW7s export: both libraries now export it under the same name, Oeo9tUbzW7s_nid_no_patch_cut.

    • The patch step leaves unpatched, in every other library, each name that libc also exports (core/libs/CMakeLists.txt lines 144-149 and 218, from a43f73163d). So the patched libSceLibcInternal.prx no longer carries this NID: nm -D shows Oeo9tUbzW7s_nid_no_patch_cut on this branch and Oeo9tUbzW7s on main.
    • A Windows import of it from libSceLibcInternal still resolves. The stub searches the import's own library first and then libc.prx (WindowsEntryStubBuilder.cpp lines 180-207).
    • Both bodies are the same empty destructor, except that libc's throws on a null facet. I did not check this with a relinked executable on Linux.

What still throws, and why:

  • do_length for both facets (lynApfiP6Lw, m6rjfL4aMcA) calls NotImplemented_nid_no_patch, because the two Dinkumware releases differ. V6.00 (crt.vc12 lines 1267-1297, 1534-1564) counts the characters that the virtual do_in converts from a copy of the state. microsoft/STL's _Codecvt_do_length (lines 850-891) returns the bytes consumed and advances the caller's state. No source here shows which one the console's libc has.
  • A null facet passed to the destructors throws std::invalid_argument, where the console would fault. This is the host-safety policy of the ctype<char> destructor (LocaleSupport.cpp lines 1378-1379).
  • An unreadable facet mode, shift state or output pointer in the metadata and do_unshift bodies throws, as on main.

Debt: docs/dev/debt/changes/feat-codecvt-utf-facets.md makes these changes:

  • adds four libc Functional entries: the vtables and ids, do_in/do_out, the metadata, unshift and destructors, and the throwing do_length (839, 661, 767 and 542 characters);
  • changes the libSceLibcInternal "UTF codecvt metadata and unshift" entry to say it forwards. The entry keeps its SDK 10.00 citations as recorded. I did not open the SDK;
  • adds one libSceLibcInternal Functional entry for the forwarders (471);
  • removes the four libSceLibcInternal do_in/do_out stub entries.

Overlap:

  • tools/pr_overlap.py --names for 63 names, these two facets' members and typeinfo together with num_put<wchar_t>'s, found no open PR that implements an export of this one. It names #17300 for 15 of these members, which renames libSceLibcInternal's stubs, and #13449 for the two _ZTS typeinfo names, which this PR does not add.
  • tools/pr_overlap.py --branch feat/codecvt-utf-facets lists #17300 under "Same exports". #17300 renames libSceLibcInternal's stubs of these members to their bare mangled names. That is a different library and a different symbol name from libc's, as with __cxa_finalize.
  • It exits 2 because 27 PRs that share a file with this branch already conflict with main. I fetched their heads and ran git merge-tree of each against main and against this branch. Then I compared the conflict hunks in every file this branch changes.

Not in this PR:

  • The typeinfo objects _ZTISt7codecvtIDsc9_MbstatetE (v1WebHtIa24) and _ZTISt7codecvtIDic9_MbstatetE (+TtUFzALoDc). main exports no facet typeinfo, and a guest class derived from one of these facets with RTTI needs them.
  • libSceLibcInternal's do_length stubs (Err.cpp line 272 and sceLibcInternalPending3_019), which stay as they are on main.
  • The std::__sce_v2 variants.

Tested

Fedora Linux 44, GCC 16.2.1, GNU ld 2.46.1, CMake 4.3.0, Ninja 1.13.2, Release build with -DBUILD_TESTING=ON, on 49da1aea8b (based on main at 3b7ffd7a05). No title, no console and no Windows host.

  • Full build: passes.

  • tools/select_tests.py selects 5788 of 5895 tests for this change. 5787 pass, and 62 of them skip themselves on this NVIDIA machine. The one failure is agc_driver_image_table_packed_guards ("deferred write-back failed: image table ... invalid format"). It fails the same way with main's copies of this branch's eight changed files that exist on main checked out and only that test rebuilt (on 8332b52dbf; main has changed no AGC, shader or VideoOut file since), so it comes from main.

  • guest_codecvt_utf_facets (new) checks, for both vtables:

    • every slot, by behaviour, because Windows import thunks make address comparisons unreliable;
    • do_max_length and do_encoding for all eight mode values;
    • a do_in with a byte order mark, A and é under consume_header, and a do_out under generate_header;
    • do_unshift on a pending surrogate;
    • D1 releasing nothing and D0 releasing the facet, against a recording application heap.

    It also checks the ids, the destructor exports with a null facet, the query exports, and libSceLibcInternal's six forwarders, which convert € both ways and release the facet.

  • guest_codecvt_utf_conversion is #21252's test, which now links libc. It covers sequences, surrogates, errors, partial input, _Maxcode, non-canonical input, headers, output room, and the virtual retry after a byte order mark. guest_codecvt_utf_metadata (libSceLibcInternal, on main) passes through the forwarders unchanged. guest_locale, guest_libc_internal_empty_facet_members, public_headers with its 64 compile batches, and patched_self_imports pass.

  • nm -D --defined-only on the patched libc.prx lists all 22 NIDs: the vtables as data, the ids as BSS, the 18 members as text.

  • Negative controls: I made 24 single mutations of CodecvtUtf.cpp, LocaleSupport.cpp and the libSceLibcInternal forwarders, and built and ran each with the three codecvt tests. Among them are a zeroed vtable, swapped slots, a non-zero id, destructors that delete or keep the facet or skip the null check, do_always_noconv returning true, the char16_t do_encoding following the mode, wrong do_max_length reads, do_unshift ignoring a pending surrogate or returning microsoft/STL's noconv, do_length returning 0, do_in retrying directly or ignoring _Maxcode, and two wrong forwarders. All 24 failed at least one test, and the tests passed again with the code restored. These ran on the first version of the first commit, which lacked only the #include of the new header in libc's Api.hpp and one sentence of the debt fragment. Only the do_length checks caught the do_length mutation, and the second commit removes them, as review asked, so that mutation now fails no test.

  • x86_64-w64-mingw32-g++ 16.2.1 -fsyntax-only with -D_UCRT -D__MSVCRT_VERSION__=0xE00 passes for CodecvtUtf.cpp, LocaleSupport.cpp, CodecvtUtfMetadata.cpp, Err.cpp, InventoryExports.cpp and both tests. Nothing ran on Windows.

  • python3 tools/check_conventions.py --base origin/main passes, and git diff --check is clean. python3 tools/debt_fold.py --check fails, as it does on main itself: #19093 (2fe1ce5a7c) added feat-libressl3-evp-pkey-new-mac-key-v2.md, which changes the same libSceLibreSsl3 entry as libressl3-20171-inventory.md. On a copy of this branch without that one file it passes, and it passed on the earlier base 8332b52dbf.

Sources

Behaviour Source
Vtable order: codecvt_base's three virtuals, then do_in, do_out, do_unshift, do_length microsoft/STL 219514876e stl/inc/xlocale lines 691-704, lines 965-1188 and 1264-1423
Vtable header (offset-to-top, typeinfo, two destructors, _Incref/_Decref) and 104-byte shape the libc.md "codecvt<char,char,_Mbstatet> vtable" entry on main (st_size 104 on PPSA26344's libc.prx)
Constructors and _Getcat inline; id the only static member ganboing/crt.vc12 f1d47126bf src/xlocale lines 1040-1070, 1364-1394
do_in, do_out microsoft/STL stl/inc/xlocale lines 965-1150, 1264-1394; crt.vc12 src/xlocale lines 1081-1255, 1405-1525
do_unshift, do_max_length, do_encoding, do_always_noconv crt.vc12 src/xlocale lines 1257-1265, 1299-1314, 1527-1532, 1566-1581; microsoft/STL char32_t do_unshift (noconv) lines 1396-1400
Destructors empty crt.vc12 src/xlocale lines 1073-1075, 1397-1399; Itanium C++ ABI 5.1.4, "deleting destructor"
do_length throws: the two releases differ crt.vc12 src/xlocale lines 1267-1297, 1534-1564; microsoft/STL stl/inc/xlocale lines 850-891
libc exports the 22 NIDs, and no D2 claimore22/ps5rs 2304be5131 data/stubs/by_library/libc.txt lines 35, 91, 547, 557, 660, 720, 765, 1127, 1162, 1217, 1246, 1355, 1462, 1839, 1972, 2201, 2306, 2317, 2663, 2737, 2804, 2895
Parameter types the mangled names; tools/check_conventions.py compute_nid gives each listed NID from its name
libc's exports stay unpatched in other libraries core/libs/CMakeLists.txt lines 144-149 and 218
A host import falls back to libc.prx core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp lines 180-207
A data import no library exports stops the title core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp line 293

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5348055364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21981). Originally posted by [Herolias](https://github.com/Herolias) on 2026-11-17T00:43:19Z. --- ### What This brings back #21252 the way oneandonlydean asked when closing it: "bring it back together with the vtable and id exports" so that it can be judged as one working piece. The `do_in`/`do_out` bodies reviewed there are unchanged. They now sit in libc, together with everything else the console's libc exports for these two facets. libc now exports 22 NIDs for `codecvt<char16_t, char, _Mbstatet>` and `codecvt<char32_t, char, _Mbstatet>`: both vtables, both ids, the complete and deleting destructors and every virtual. ps5rs `libc.txt` lists all 22 for libc. On `main` libc exports none of them. libSceLibcInternal has `do_in`/`do_out` stubs that throw and the metadata bodies, but no vtable points at any of them. How code reaches it: in Dinkumware V6.00 the three constructors and `_Getcat` are inline in the class, and `id` is the only static data member ([crt.vc12 `xlocale` lines 1040-1070](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1040-L1070) and 1364-1394). A guest that uses either standard facet therefore does three things. It reads the exported `id`, builds the facet with the inline `_Getcat` or constructor, which writes the exported vtable into the object, and then calls the virtuals through that vtable. On `main` the `id` and vtable imports are data that no library exports, which stops a title at startup (`FAIL: unresolved ELF import`, `WindowsEntryStubBuilder.cpp` line 293). I know of no title that does this. None of the eight title import lists (#265-#272) holds one of these NIDs, but those lists name only the NIDs that were new when they were posted, so that shows nothing either way. This PR claims no unblocked title. - **Vtables (`jlNI3SSF41o`, `9H2BStEAAMg`):** thirteen `uintptr_t` slots each, in this order: - offset-to-top and typeinfo, both zero as in libc's other filled vtables; - D1 and D0; - `_Incref` and `_Decref` (`RetainFacet` and `ReleaseFacet`, as for libc's other facets); - `codecvt_base`'s `do_always_noconv`, `do_max_length` and `do_encoding` ([microsoft/STL `xlocale` lines 691-704](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocale#L691-L704)); - then `do_in`, `do_out`, `do_unshift` and `do_length`, in the declaration order of lines 965-1188 and 1264-1423. That is the shape of the `codecvt<char,char,_Mbstatet>` vtable, whose `libc.md` entry records thirteen slots and `st_size` 104, measured on PPSA26344's `libc.prx`. The sizes of these two vtables were not measured. - **Ids (`xM5re58mxj8`, `u2MAta5SS84`):** 8-byte zeros, like libc's other facet ids. - **`do_in`/`do_out` (`+uPwCGfmJHs`, `0FKwlv9iH1c`, `PJ2UDX9Tvwg`, `eoW60zcLT8Q`):** #21252's bodies, moved to libc and renamed. They follow [microsoft/STL `xlocale` lines 965-1150](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocale#L965-L1150) and 1264-1394, which crt.vc12 lines 1081-1255 and 1405-1525 match. `_Maxcode` is the 8-byte `unsigned long` at 0x10 and `_Mode` the 4-byte enum at 0x18. The retry after a byte order mark calls the vtable's `do_in` slot (0x38 past the address point), as the sources' virtual call does. - **Metadata and `do_unshift`:** `char16_t` exports `9Vyfb-I-9xw`, `BvRS0cGTd6I`, `Mo6K-pUyNhI` and `RYTHR81Y-Mc`; `char32_t` exports `NQ81EZ7CL6w`, `E5NdzqEmWuY`, `DDnr3lDwW8I` and `c6Lyc6xOp4o`. - `do_unshift`, `do_max_length` and the `char32_t` `do_encoding` are `main`'s libSceLibcInternal bodies, moved unchanged. They match [crt.vc12 lines 1257-1265, 1304-1309](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1257-L1309), 1527-1532 and 1571-1581. - The `char16_t` `do_unshift` returns `error` while a first surrogate is pending, and the `char32_t` one returns `ok`. microsoft/STL returns `noconv` for `char32_t` (lines 1396-1400). Where the two releases differ, I followed Dinkumware V6.00, because the console's libc is Dinkumware's. - `do_always_noconv` returns false, and the `char16_t` `do_encoding` returns 0 (crt.vc12 lines 1299-1302, 1311-1314 and 1566-1569). - **Destructors (`Oeo9tUbzW7s` and `zYHryd8vd0w` for `char16_t`, `TuhGCIxgLvA` and `vwMx2NhWdLw` for `char32_t`):** the destructor is empty ([crt.vc12 lines 1073-1075](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1073-L1075), 1397-1399), and the deleting destructor then frees the facet with `operator delete`. D2 is not exported, because ps5rs `libc.txt` lists no D2 for either facet (`9qe-2KFnfNo`, `lZqo+v9IY9M`). - **libSceLibcInternal:** six exports become forwarders to libc's `_nid_no_patch` bodies: - the four `do_in`/`do_out` stubs (`sceLibcInternalPending3_017`, `018`, `024` and `025` in `Err.cpp`), now with their real signatures; - the deleting destructors (`libSceLibcInternalInventory_090`/`092` in `InventoryExports.cpp`). The five metadata exports in `CodecvtUtfMetadata.cpp` forward too, so libSceLibcInternal and libc no longer keep two copies of these bodies. `patched_self_imports` passes, so no forwarder binds to its own library. Its `do_length` stubs and `sceLibcInternalUnknown6_090_Oeo9tUbzW7s` are unchanged. - **How the 22 are exported:** 15 use libc's usual `_nid_postfix` names. Seven use `APS5_EXPORT` with a `_nid_no_patch` body, as libc already does for `__cxa_finalize`: - `BvRS0cGTd6I`, `RYTHR81Y-Mc`, `lynApfiP6Lw`, `E5NdzqEmWuY`, `DDnr3lDwW8I` and `c6Lyc6xOp4o`: libSceLibcInternal already defines those names with `_nid_postfix` (`CodecvtUtfMetadata.cpp` lines 6-23, `Err.cpp` line 272), and `check_conventions` rejects a second definition as `duplicate-export`; - `Oeo9tUbzW7s`: libSceLibcInternal exports that NID as `sceLibcInternalUnknown6_090_Oeo9tUbzW7s` (`InventoryExports6.cpp` lines 373-376), so the `_nid_postfix` name is rejected as `unknown-nid`. - **One side effect of the `Oeo9tUbzW7s` export:** both libraries now export it under the same name, `Oeo9tUbzW7s_nid_no_patch_cut`. - The patch step leaves unpatched, in every other library, each name that libc also exports (`core/libs/CMakeLists.txt` lines 144-149 and 218, from a43f73163d). So the patched `libSceLibcInternal.prx` no longer carries this NID: `nm -D` shows `Oeo9tUbzW7s_nid_no_patch_cut` on this branch and `Oeo9tUbzW7s` on `main`. - A Windows import of it from libSceLibcInternal still resolves. The stub searches the import's own library first and then `libc.prx` (`WindowsEntryStubBuilder.cpp` lines 180-207). - Both bodies are the same empty destructor, except that libc's throws on a null facet. I did not check this with a relinked executable on Linux. What still throws, and why: - `do_length` for both facets (`lynApfiP6Lw`, `m6rjfL4aMcA`) calls `NotImplemented_nid_no_patch`, because the two Dinkumware releases differ. V6.00 ([crt.vc12 lines 1267-1297](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1267-L1297), 1534-1564) counts the characters that the virtual `do_in` converts from a copy of the state. microsoft/STL's `_Codecvt_do_length` ([lines 850-891](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocale#L850-L891)) returns the bytes consumed and advances the caller's state. No source here shows which one the console's libc has. - A null facet passed to the destructors throws `std::invalid_argument`, where the console would fault. This is the host-safety policy of the `ctype<char>` destructor (`LocaleSupport.cpp` lines 1378-1379). - An unreadable facet mode, shift state or output pointer in the metadata and `do_unshift` bodies throws, as on `main`. Debt: `docs/dev/debt/changes/feat-codecvt-utf-facets.md` makes these changes: - adds four libc Functional entries: the vtables and ids, `do_in`/`do_out`, the metadata, unshift and destructors, and the throwing `do_length` (839, 661, 767 and 542 characters); - changes the libSceLibcInternal "UTF codecvt metadata and unshift" entry to say it forwards. The entry keeps its SDK 10.00 citations as recorded. I did not open the SDK; - adds one libSceLibcInternal Functional entry for the forwarders (471); - removes the four libSceLibcInternal `do_in`/`do_out` stub entries. Overlap: - `tools/pr_overlap.py --names` for 63 names, these two facets' members and typeinfo together with `num_put<wchar_t>`'s, found no open PR that implements an export of this one. It names #17300 for 15 of these members, which renames libSceLibcInternal's stubs, and #13449 for the two `_ZTS` typeinfo names, which this PR does not add. - `tools/pr_overlap.py --branch feat/codecvt-utf-facets` lists #17300 under "Same exports". #17300 renames libSceLibcInternal's stubs of these members to their bare mangled names. That is a different library and a different symbol name from libc's, as with `__cxa_finalize`. - It exits 2 because 27 PRs that share a file with this branch already conflict with `main`. I fetched their heads and ran `git merge-tree` of each against `main` and against this branch. Then I compared the conflict hunks in every file this branch changes. - 26 of them have the same hunks against both: #7447, #7715, #8150, #8965, #9466, #12682, #12688, #12700, #12717, #12849, #12965, #16791, #17345, #17354, #17557, #17558 and #19181 (libc `CMakeLists.txt`, some also libc `Api.hpp`), #9526 and #11172 (`LocaleSupport.cpp`), #12184 and #19767 (libc `Api.hpp`), #13778, #14834, #19602 and #20834 (libSceLibcInternal `InventoryExports.cpp` and headers) and #18135. - The exception is #17300. It gains three hunks in `Err.cpp` and two in `InventoryExports.cpp`, because it renames the same `Pending3_017`/`018`/`024`/`025` and `Inventory_090`/`092` stubs that this branch turns into forwarders. #17300 already conflicts with `main`, and changes were requested on it on 2026-11-08. Not in this PR: - The typeinfo objects `_ZTISt7codecvtIDsc9_MbstatetE` (`v1WebHtIa24`) and `_ZTISt7codecvtIDic9_MbstatetE` (`+TtUFzALoDc`). `main` exports no facet typeinfo, and a guest class derived from one of these facets with RTTI needs them. - libSceLibcInternal's `do_length` stubs (`Err.cpp` line 272 and `sceLibcInternalPending3_019`), which stay as they are on `main`. - The `std::__sce_v2` variants. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Fedora Linux 44, GCC 16.2.1, GNU ld 2.46.1, CMake 4.3.0, Ninja 1.13.2, Release build with `-DBUILD_TESTING=ON`, on `49da1aea8b` (based on `main` at `3b7ffd7a05`). No title, no console and no Windows host. - Full build: passes. - `tools/select_tests.py` selects 5788 of 5895 tests for this change. 5787 pass, and 62 of them skip themselves on this NVIDIA machine. The one failure is `agc_driver_image_table_packed_guards` ("deferred write-back failed: image table ... invalid format"). It fails the same way with `main`'s copies of this branch's eight changed files that exist on `main` checked out and only that test rebuilt (on `8332b52dbf`; `main` has changed no AGC, shader or VideoOut file since), so it comes from `main`. - `guest_codecvt_utf_facets` (new) checks, for both vtables: - every slot, by behaviour, because Windows import thunks make address comparisons unreliable; - `do_max_length` and `do_encoding` for all eight mode values; - a `do_in` with a byte order mark, `A` and `é` under `consume_header`, and a `do_out` under `generate_header`; - `do_unshift` on a pending surrogate; - D1 releasing nothing and D0 releasing the facet, against a recording application heap. It also checks the ids, the destructor exports with a null facet, the query exports, and libSceLibcInternal's six forwarders, which convert `€` both ways and release the facet. - `guest_codecvt_utf_conversion` is #21252's test, which now links libc. It covers sequences, surrogates, errors, partial input, `_Maxcode`, non-canonical input, headers, output room, and the virtual retry after a byte order mark. `guest_codecvt_utf_metadata` (libSceLibcInternal, on `main`) passes through the forwarders unchanged. `guest_locale`, `guest_libc_internal_empty_facet_members`, `public_headers` with its 64 compile batches, and `patched_self_imports` pass. - `nm -D --defined-only` on the patched `libc.prx` lists all 22 NIDs: the vtables as data, the ids as BSS, the 18 members as text. - Negative controls: I made 24 single mutations of `CodecvtUtf.cpp`, `LocaleSupport.cpp` and the libSceLibcInternal forwarders, and built and ran each with the three codecvt tests. Among them are a zeroed vtable, swapped slots, a non-zero id, destructors that delete or keep the facet or skip the null check, `do_always_noconv` returning true, the `char16_t` `do_encoding` following the mode, wrong `do_max_length` reads, `do_unshift` ignoring a pending surrogate or returning microsoft/STL's `noconv`, `do_length` returning 0, `do_in` retrying directly or ignoring `_Maxcode`, and two wrong forwarders. All 24 failed at least one test, and the tests passed again with the code restored. These ran on the first version of the first commit, which lacked only the `#include` of the new header in libc's `Api.hpp` and one sentence of the debt fragment. Only the `do_length` checks caught the `do_length` mutation, and the second commit removes them, as review asked, so that mutation now fails no test. - `x86_64-w64-mingw32-g++` 16.2.1 `-fsyntax-only` with `-D_UCRT -D__MSVCRT_VERSION__=0xE00` passes for `CodecvtUtf.cpp`, `LocaleSupport.cpp`, `CodecvtUtfMetadata.cpp`, `Err.cpp`, `InventoryExports.cpp` and both tests. Nothing ran on Windows. - `python3 tools/check_conventions.py --base origin/main` passes, and `git diff --check` is clean. `python3 tools/debt_fold.py --check` fails, as it does on `main` itself: #19093 (2fe1ce5a7c) added `feat-libressl3-evp-pkey-new-mac-key-v2.md`, which changes the same libSceLibreSsl3 entry as `libressl3-20171-inventory.md`. On a copy of this branch without that one file it passes, and it passed on the earlier base `8332b52dbf`. ### Sources | Behaviour | Source | | --- | --- | | Vtable order: `codecvt_base`'s three virtuals, then `do_in`, `do_out`, `do_unshift`, `do_length` | [microsoft/STL 219514876e `stl/inc/xlocale` lines 691-704](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocale#L691-L704), lines 965-1188 and 1264-1423 | | Vtable header (offset-to-top, typeinfo, two destructors, `_Incref`/`_Decref`) and 104-byte shape | the `libc.md` "codecvt<char,char,_Mbstatet> vtable" entry on `main` (`st_size` 104 on PPSA26344's `libc.prx`) | | Constructors and `_Getcat` inline; `id` the only static member | [ganboing/crt.vc12 f1d47126bf `src/xlocale` lines 1040-1070](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1040-L1070), 1364-1394 | | `do_in`, `do_out` | [microsoft/STL `stl/inc/xlocale` lines 965-1150](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocale#L965-L1150), 1264-1394; [crt.vc12 `src/xlocale` lines 1081-1255](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1081-L1255), 1405-1525 | | `do_unshift`, `do_max_length`, `do_encoding`, `do_always_noconv` | [crt.vc12 `src/xlocale` lines 1257-1265, 1299-1314](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1257-L1314), 1527-1532, 1566-1581; microsoft/STL `char32_t` `do_unshift` (`noconv`) lines 1396-1400 | | Destructors empty | [crt.vc12 `src/xlocale` lines 1073-1075](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1073-L1075), 1397-1399; [Itanium C++ ABI 5.1.4, "deleting destructor"](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-special-ctor-dtor) | | `do_length` throws: the two releases differ | [crt.vc12 `src/xlocale` lines 1267-1297](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xlocale#L1267-L1297), 1534-1564; [microsoft/STL `stl/inc/xlocale` lines 850-891](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocale#L850-L891) | | libc exports the 22 NIDs, and no D2 | [claimore22/ps5rs 2304be5131 `data/stubs/by_library/libc.txt`](https://github.com/claimore22/ps5rs/blob/2304be5131221bae0dac24b9767cabffda33f747/data/stubs/by_library/libc.txt) lines 35, 91, 547, 557, 660, 720, 765, 1127, 1162, 1217, 1246, 1355, 1462, 1839, 1972, 2201, 2306, 2317, 2663, 2737, 2804, 2895 | | Parameter types | the mangled names; `tools/check_conventions.py` `compute_nid` gives each listed NID from its name | | libc's exports stay unpatched in other libraries | `core/libs/CMakeLists.txt` lines 144-149 and 218 | | A host import falls back to `libc.prx` | `core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp` lines 180-207 | | A data import no library exports stops the title | `core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp` line 293 | ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
PrivacyOnion commented 2026-11-17 00:58:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T00:58:08Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 1424ee32cf:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_codecvt_utf_conversion_tests, guest_codecvt_utf_facets_tests built cleanly.
  • CTest (guest_codecvt_utf_conversion, guest_codecvt_utf_facets):
    1/2 Test #1355: guest_codecvt_utf_conversion .....   Passed    0.01 sec
    2/2 Test #1356: guest_codecvt_utf_facets .........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceLibcInternal/CodecvtUtfMetadata.cpp, core/libs/prx/libSceLibcInternal/Err.cpp, core/libs/prx/libSceLibcInternal/InventoryExports.cpp, core/libs/prx/libSceLibcInternal/include/Api.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/LocaleSupport.cpp, core/libs/prx/libc/src/CodecvtUtf.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified CodecvtUtf16In_nid_no_patch and CodecvtUtf32In_nid_no_patch decode sequences, handle surrogate pairs, check maxcode bounds, and properly support BOM consumption with recursive VirtualIn dispatch in core/libs/prx/libc/src/CodecvtUtf.cpp
    • Verified CodecvtUtf16Out_nid_no_patch and CodecvtUtf32Out_nid_no_patch encode UTF-16 surrogates and UTF-32 codepoints into UTF-8, handling buffer limits, header generation (BOM), and state updates in core/libs/prx/libc/src/CodecvtUtf.cpp
    • Verified vtable layouts in core/libs/prx/libc/src/LocaleSupport.cpp matching 13 slots (104 bytes), offset-to-top, typeinfo, virtual destructors, retain/release, and virtual facet methods
    • Verified libSceLibcInternal forwarding stubs in Err.cpp, InventoryExports.cpp, and CodecvtUtfMetadata.cpp properly passing arguments to libc implementations
    • Verified technical debt tracking in docs/dev/debt/changes/feat-codecvt-utf-facets.md and AGENTS.md conventions compliance (no forbidden comments, NotImplemented on do_length)

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5930772170 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21981#pullrequestreview-5930772170). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T00:58:08Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `1424ee32cf`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_codecvt_utf_conversion_tests`, `guest_codecvt_utf_facets_tests` built cleanly. - **CTest** (`guest_codecvt_utf_conversion`, `guest_codecvt_utf_facets`): ``` 1/2 Test #1355: guest_codecvt_utf_conversion ..... Passed 0.01 sec 2/2 Test #1356: guest_codecvt_utf_facets ......... Passed 0.01 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/CodecvtUtfMetadata.cpp`, `core/libs/prx/libSceLibcInternal/Err.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports.cpp`, `core/libs/prx/libSceLibcInternal/include/Api.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/src/LocaleSupport.cpp`, `core/libs/prx/libc/src/CodecvtUtf.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified CodecvtUtf16In_nid_no_patch and CodecvtUtf32In_nid_no_patch decode sequences, handle surrogate pairs, check maxcode bounds, and properly support BOM consumption with recursive VirtualIn dispatch in core/libs/prx/libc/src/CodecvtUtf.cpp - Verified CodecvtUtf16Out_nid_no_patch and CodecvtUtf32Out_nid_no_patch encode UTF-16 surrogates and UTF-32 codepoints into UTF-8, handling buffer limits, header generation (BOM), and state updates in core/libs/prx/libc/src/CodecvtUtf.cpp - Verified vtable layouts in core/libs/prx/libc/src/LocaleSupport.cpp matching 13 slots (104 bytes), offset-to-top, typeinfo, virtual destructors, retain/release, and virtual facet methods - Verified libSceLibcInternal forwarding stubs in Err.cpp, InventoryExports.cpp, and CodecvtUtfMetadata.cpp properly passing arguments to libc implementations - Verified technical debt tracking in docs/dev/debt/changes/feat-codecvt-utf-facets.md and AGENTS.md conventions compliance (no forbidden comments, NotImplemented on do_length) Looks Good To Me
PrivacyOnion commented 2026-11-17 01:28:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T01:28:08Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 49da1aea8b:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_codecvt_utf_conversion_tests, guest_codecvt_utf_facets_tests built cleanly.
  • CTest (guest_codecvt_utf_conversion, guest_codecvt_utf_facets):
    1/2 Test #1357: guest_codecvt_utf_conversion .....   Passed    0.01 sec
    2/2 Test #1358: guest_codecvt_utf_facets .........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceLibcInternal/CodecvtUtfMetadata.cpp, core/libs/prx/libSceLibcInternal/Err.cpp, core/libs/prx/libSceLibcInternal/InventoryExports.cpp, core/libs/prx/libSceLibcInternal/include/Api.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/LocaleSupport.cpp, core/libs/prx/libc/src/CodecvtUtf.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libc/src/CodecvtUtf.cpp: verified CodecvtUtf16In_nid_no_patch and CodecvtUtf32In_nid_no_patch handle multi-byte UTF-8 sequences, partial buffer boundaries, maxcode filtering, surrogate generation, and recursive VirtualIn header consumption
    • core/libs/prx/libc/src/CodecvtUtf.cpp: verified CodecvtUtf16Out_nid_no_patch and CodecvtUtf32Out_nid_no_patch handle surrogate pair recombination, UTF-8 buffer bounds checks, BOM emission logic, and partial buffer states
    • core/libs/prx/libc/src/CodecvtUtf.cpp: verified CodecvtUtf16Unshift_nid_no_patch and CodecvtUtf32Unshift_nid_no_patch write next pointers via GuestCopyOut_nid_no_patch and validate shift state using GuestCopyIn_nid_no_patch
    • core/libs/prx/libc/src/LocaleSupport.cpp: verified both _ZTVSt7codecvtIDsc9_MbstatetE_nid_postfix and _ZTVSt7codecvtIDic9_MbstatetE_nid_postfix contain 13 uintptr_t slots (104 bytes) matching Dinkumware/MSVC layout and slot alignment
    • core/libs/prx/libSceLibcInternal: verified Err.cpp, InventoryExports.cpp, and CodecvtUtfMetadata.cpp correctly forward NID exports to libc implementations with matching signatures and conventions
    • AGENTS.md & technical debt: verified no forbidden comments in source, license header attribution matches upstream, and technical debt fragment docs/dev/debt/changes/feat-codecvt-utf-facets.md accurately documents gaps (including NotImplemented on do_length)

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5931092768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21981#pullrequestreview-5931092768). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T01:28:08Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `49da1aea8b`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_codecvt_utf_conversion_tests`, `guest_codecvt_utf_facets_tests` built cleanly. - **CTest** (`guest_codecvt_utf_conversion`, `guest_codecvt_utf_facets`): ``` 1/2 Test #1357: guest_codecvt_utf_conversion ..... Passed 0.01 sec 2/2 Test #1358: guest_codecvt_utf_facets ......... Passed 0.01 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/CodecvtUtfMetadata.cpp`, `core/libs/prx/libSceLibcInternal/Err.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports.cpp`, `core/libs/prx/libSceLibcInternal/include/Api.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/src/LocaleSupport.cpp`, `core/libs/prx/libc/src/CodecvtUtf.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libc/src/CodecvtUtf.cpp: verified CodecvtUtf16In_nid_no_patch and CodecvtUtf32In_nid_no_patch handle multi-byte UTF-8 sequences, partial buffer boundaries, maxcode filtering, surrogate generation, and recursive VirtualIn header consumption - core/libs/prx/libc/src/CodecvtUtf.cpp: verified CodecvtUtf16Out_nid_no_patch and CodecvtUtf32Out_nid_no_patch handle surrogate pair recombination, UTF-8 buffer bounds checks, BOM emission logic, and partial buffer states - core/libs/prx/libc/src/CodecvtUtf.cpp: verified CodecvtUtf16Unshift_nid_no_patch and CodecvtUtf32Unshift_nid_no_patch write next pointers via GuestCopyOut_nid_no_patch and validate shift state using GuestCopyIn_nid_no_patch - core/libs/prx/libc/src/LocaleSupport.cpp: verified both _ZTVSt7codecvtIDsc9_MbstatetE_nid_postfix and _ZTVSt7codecvtIDic9_MbstatetE_nid_postfix contain 13 uintptr_t slots (104 bytes) matching Dinkumware/MSVC layout and slot alignment - core/libs/prx/libSceLibcInternal: verified Err.cpp, InventoryExports.cpp, and CodecvtUtfMetadata.cpp correctly forward NID exports to libc implementations with matching signatures and conventions - AGENTS.md & technical debt: verified no forbidden comments in source, license header attribution matches upstream, and technical debt fragment docs/dev/debt/changes/feat-codecvt-utf-facets.md accurately documents gaps (including NotImplemented on do_length) Looks Good To Me
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!21981
No description provided.