feat(libc,libSceLibcInternal): wire the char16_t and char32_t codecvt facets #21981
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21981"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_outbodies 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>andcodecvt<char32_t, char, _Mbstatet>: both vtables, both ids, the complete and deleting destructors and every virtual. ps5rslibc.txtlists all 22 for libc. Onmainlibc exports none of them. libSceLibcInternal hasdo_in/do_outstubs 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
_Getcatare inline in the class, andidis the only static data member (crt.vc12xlocalelines 1040-1070 and 1364-1394). A guest that uses either standard facet therefore does three things. It reads the exportedid, builds the facet with the inline_Getcator constructor, which writes the exported vtable into the object, and then calls the virtuals through that vtable. Onmaintheidand vtable imports are data that no library exports, which stops a title at startup (FAIL: unresolved ELF import,WindowsEntryStubBuilder.cppline 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): thirteenuintptr_tslots each, in this order:_Increfand_Decref(RetainFacetandReleaseFacet, as for libc's other facets);codecvt_base'sdo_always_noconv,do_max_lengthanddo_encoding(microsoft/STLxlocalelines 691-704);do_in,do_out,do_unshiftanddo_length, in the declaration order of lines 965-1188 and 1264-1423.That is the shape of the
codecvt<char,char,_Mbstatet>vtable, whoselibc.mdentry records thirteen slots andst_size104, measured on PPSA26344'slibc.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/STLxlocalelines 965-1150 and 1264-1394, which crt.vc12 lines 1081-1255 and 1405-1525 match._Maxcodeis the 8-byteunsigned longat 0x10 and_Modethe 4-byte enum at 0x18. The retry after a byte order mark calls the vtable'sdo_inslot (0x38 past the address point), as the sources' virtual call does.Metadata and
do_unshift:char16_texports9Vyfb-I-9xw,BvRS0cGTd6I,Mo6K-pUyNhIandRYTHR81Y-Mc;char32_texportsNQ81EZ7CL6w,E5NdzqEmWuY,DDnr3lDwW8Iandc6Lyc6xOp4o.do_unshift,do_max_lengthand thechar32_tdo_encodingaremain's libSceLibcInternal bodies, moved unchanged. They match crt.vc12 lines 1257-1265, 1304-1309, 1527-1532 and 1571-1581.char16_tdo_unshiftreturnserrorwhile a first surrogate is pending, and thechar32_tone returnsok. microsoft/STL returnsnoconvforchar32_t(lines 1396-1400). Where the two releases differ, I followed Dinkumware V6.00, because the console's libc is Dinkumware's.do_always_noconvreturns false, and thechar16_tdo_encodingreturns 0 (crt.vc12 lines 1299-1302, 1311-1314 and 1566-1569).Destructors (
Oeo9tUbzW7sandzYHryd8vd0wforchar16_t,TuhGCIxgLvAandvwMx2NhWdLwforchar32_t): the destructor is empty (crt.vc12 lines 1073-1075, 1397-1399), and the deleting destructor then frees the facet withoperator delete. D2 is not exported, because ps5rslibc.txtlists no D2 for either facet (9qe-2KFnfNo,lZqo+v9IY9M).libSceLibcInternal: six exports become forwarders to libc's
_nid_no_patchbodies:do_in/do_outstubs (sceLibcInternalPending3_017,018,024and025inErr.cpp), now with their real signatures;libSceLibcInternalInventory_090/092inInventoryExports.cpp).The five metadata exports in
CodecvtUtfMetadata.cppforward too, so libSceLibcInternal and libc no longer keep two copies of these bodies.patched_self_importspasses, so no forwarder binds to its own library. Itsdo_lengthstubs andsceLibcInternalUnknown6_090_Oeo9tUbzW7sare unchanged.How the 22 are exported: 15 use libc's usual
_nid_postfixnames. Seven useAPS5_EXPORTwith a_nid_no_patchbody, as libc already does for__cxa_finalize:BvRS0cGTd6I,RYTHR81Y-Mc,lynApfiP6Lw,E5NdzqEmWuY,DDnr3lDwW8Iandc6Lyc6xOp4o: libSceLibcInternal already defines those names with_nid_postfix(CodecvtUtfMetadata.cpplines 6-23,Err.cppline 272), andcheck_conventionsrejects a second definition asduplicate-export;Oeo9tUbzW7s: libSceLibcInternal exports that NID assceLibcInternalUnknown6_090_Oeo9tUbzW7s(InventoryExports6.cpplines 373-376), so the_nid_postfixname is rejected asunknown-nid.One side effect of the
Oeo9tUbzW7sexport: both libraries now export it under the same name,Oeo9tUbzW7s_nid_no_patch_cut.core/libs/CMakeLists.txtlines 144-149 and 218, froma43f73163d). So the patchedlibSceLibcInternal.prxno longer carries this NID:nm -DshowsOeo9tUbzW7s_nid_no_patch_cuton this branch andOeo9tUbzW7sonmain.libc.prx(WindowsEntryStubBuilder.cpplines 180-207).What still throws, and why:
do_lengthfor both facets (lynApfiP6Lw,m6rjfL4aMcA) callsNotImplemented_nid_no_patch, because the two Dinkumware releases differ. V6.00 (crt.vc12 lines 1267-1297, 1534-1564) counts the characters that the virtualdo_inconverts 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.std::invalid_argument, where the console would fault. This is the host-safety policy of thectype<char>destructor (LocaleSupport.cpplines 1378-1379).do_unshiftbodies throws, as onmain.Debt:
docs/dev/debt/changes/feat-codecvt-utf-facets.mdmakes these changes:do_in/do_out, the metadata, unshift and destructors, and the throwingdo_length(839, 661, 767 and 542 characters);do_in/do_outstub entries.Overlap:
tools/pr_overlap.py --namesfor 63 names, these two facets' members and typeinfo together withnum_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_ZTStypeinfo names, which this PR does not add.tools/pr_overlap.py --branch feat/codecvt-utf-facetslists #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.main. I fetched their heads and rangit merge-treeof each againstmainand against this branch. Then I compared the conflict hunks in every file this branch changes.CMakeLists.txt, some also libcApi.hpp), #9526 and #11172 (LocaleSupport.cpp), #12184 and #19767 (libcApi.hpp), #13778, #14834, #19602 and #20834 (libSceLibcInternalInventoryExports.cppand headers) and #18135.Err.cppand two inInventoryExports.cpp, because it renames the samePending3_017/018/024/025andInventory_090/092stubs that this branch turns into forwarders. #17300 already conflicts withmain, and changes were requested on it on 2026-11-08.Not in this PR:
_ZTISt7codecvtIDsc9_MbstatetE(v1WebHtIa24) and_ZTISt7codecvtIDic9_MbstatetE(+TtUFzALoDc).mainexports no facet typeinfo, and a guest class derived from one of these facets with RTTI needs them.do_lengthstubs (Err.cppline 272 andsceLibcInternalPending3_019), which stay as they are onmain.std::__sce_v2variants.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, on49da1aea8b(based onmainat3b7ffd7a05). No title, no console and no Windows host.Full build: passes.
tools/select_tests.pyselects 5788 of 5895 tests for this change. 5787 pass, and 62 of them skip themselves on this NVIDIA machine. The one failure isagc_driver_image_table_packed_guards("deferred write-back failed: image table ... invalid format"). It fails the same way withmain's copies of this branch's eight changed files that exist onmainchecked out and only that test rebuilt (on8332b52dbf;mainhas changed no AGC, shader or VideoOut file since), so it comes frommain.guest_codecvt_utf_facets(new) checks, for both vtables:do_max_lengthanddo_encodingfor all eight mode values;do_inwith a byte order mark,Aandéunderconsume_header, and ado_outundergenerate_header;do_unshifton a pending surrogate;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_conversionis #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, onmain) passes through the forwarders unchanged.guest_locale,guest_libc_internal_empty_facet_members,public_headerswith its 64 compile batches, andpatched_self_importspass.nm -D --defined-onlyon the patchedlibc.prxlists 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.cppand 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_noconvreturning true, thechar16_tdo_encodingfollowing the mode, wrongdo_max_lengthreads,do_unshiftignoring a pending surrogate or returning microsoft/STL'snoconv,do_lengthreturning 0,do_inretrying 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#includeof the new header in libc'sApi.hppand one sentence of the debt fragment. Only thedo_lengthchecks caught thedo_lengthmutation, 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-onlywith-D_UCRT -D__MSVCRT_VERSION__=0xE00passes forCodecvtUtf.cpp,LocaleSupport.cpp,CodecvtUtfMetadata.cpp,Err.cpp,InventoryExports.cppand both tests. Nothing ran on Windows.python3 tools/check_conventions.py --base origin/mainpasses, andgit diff --checkis clean.python3 tools/debt_fold.py --checkfails, as it does onmainitself: #19093 (2fe1ce5a7c) addedfeat-libressl3-evp-pkey-new-mac-key-v2.md, which changes the same libSceLibreSsl3 entry aslibressl3-20171-inventory.md. On a copy of this branch without that one file it passes, and it passed on the earlier base8332b52dbf.Sources
codecvt_base's three virtuals, thendo_in,do_out,do_unshift,do_lengthstl/inc/xlocalelines 691-704, lines 965-1188 and 1264-1423_Incref/_Decref) and 104-byte shapelibc.md"codecvt<char,char,_Mbstatet> vtable" entry onmain(st_size104 on PPSA26344'slibc.prx)_Getcatinline;idthe only static membersrc/xlocalelines 1040-1070, 1364-1394do_in,do_outstl/inc/xlocalelines 965-1150, 1264-1394; crt.vc12src/xlocalelines 1081-1255, 1405-1525do_unshift,do_max_length,do_encoding,do_always_noconvsrc/xlocalelines 1257-1265, 1299-1314, 1527-1532, 1566-1581; microsoft/STLchar32_tdo_unshift(noconv) lines 1396-1400src/xlocalelines 1073-1075, 1397-1399; Itanium C++ ABI 5.1.4, "deleting destructor"do_lengththrows: the two releases differsrc/xlocalelines 1267-1297, 1534-1564; microsoft/STLstl/inc/xlocalelines 850-891data/stubs/by_library/libc.txtlines 35, 91, 547, 557, 660, 720, 765, 1127, 1162, 1217, 1246, 1355, 1462, 1839, 1972, 2201, 2306, 2317, 2663, 2737, 2804, 2895tools/check_conventions.pycompute_nidgives each listed NID from its namecore/libs/CMakeLists.txtlines 144-149 and 218libc.prxcore/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpplines 180-207core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cppline 293Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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:tools/check_conventions.pypassed.guest_codecvt_utf_conversion_tests,guest_codecvt_utf_facets_testsbuilt cleanly.guest_codecvt_utf_conversion,guest_codecvt_utf_facets):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.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
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:tools/check_conventions.pypassed.guest_codecvt_utf_conversion_tests,guest_codecvt_utf_facets_testsbuilt cleanly.guest_codecvt_utf_conversion,guest_codecvt_utf_facets):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.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me