feat(libc): wire the num_put<char> and codecvt<char> facet vtables #21220
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21220"
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-16T00:30:39Z.
What
libc exports the
num_put<char>vtable (_ZTVSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE, NID1kZFcktOm+s) and thecodecvt<char,char,_Mbstatet>vtable (_ZTVSt7codecvtIcc9_MbstatetE, NIDaK1Ymf-NhAs) as data. Onmainboth are all zeros, so a facet that a title builds on one of them jumps to address 0 on its first virtual call. This change fills both vtables, asc66f61ff52did forcollate<char>.Titles reach them. The executables of Minecraft Legends (PPSA05510, #268), Deathloop (PPSA01670, #272) and Dreaming Sarah (PPSA02929, #265) import the
num_put<char>vtable. Minecraft Legends and PPSA21564 (#271) import thecodecvt<char>vtable. Importing a vtable means the title's own code refers to it, for example to construct the facet, and a facet constructed that way makes its virtual calls through the exported slots. (These lists hold only the NIDs that were new at the time; #268, for example, leaves out 259 known-missing ones. So they don't show whether the titles also import the_Getcats.) I know of no run that reaches such a call: Deathloop's bring-up thread (#11484) gets in game, so the scenes tested there do not call through it. The Dreaming Sarah (#3003, #3018) and Astro Bot (PPSA21564, #357) threads mention no null call or facet, and I found no thread for Minecraft Legends. So this PR claims no unblocked title.num_put<char>: slots 2 to 13 hold the functions ofg_numPutVtable, the vtablenum_put<char>::_Getcatinstalls. That is the shared facet base (DestroyCollate,DeleteCollate,RetainFacet,ReleaseFacet), then the eightdo_putoverloads in the console order thatGuestLocale::NumPutVtablerecords:bool,long,unsigned long,long long,unsigned long long,double,long double,const void*.codecvt<char>: slots 2 to 12 hold the functions ofg_codecvtVtable, the vtablecodecvt<char>::_Getcatinstalls. That is the same base, thendo_always_noconv,do_max_length,do_encoding,do_in,do_out,do_unshiftanddo_length, in the orderGuestLocale::CodecvtVtablerecords.collate. No new function is added; facets built on the exported vtables behave exactly like the_Getcatfacets and share their recorded gaps.What still throws, and why:
_Getcatfacets already throw. That is thenum_putfloating-point precision checks and the null facet in the deleting destructor, as onmain.num_get<char>vtable (KfcTPbeaOqg), which stays zeroed. None of its elevendo_getvirtuals is implemented in this tree yet, so there is nothing to put in it.Debt:
docs/dev/debt/changes/feat-num-put-codecvt-vtables.mdchanges thenum_put<char> vtableandcodecvt<char,char,_Mbstatet> vtableentries inlibc.md. Both entries are under the 1000-character limit.Overlap:
tools/pr_overlap.py --namesfor the two vtables and thenum_get<char>vtable found no open pull request. A run over 33num_get,time_get,numpunctandlocalenames found none either.codecvt<wchar_t>vtable on the line directly above thecodecvt<char>vtable, so the two hunks touch. Neither changes the other's line; the resolution keeps both.tools/pr_overlap.py --branchexits 2 because #9526, #11172 and #18135 already conflict withmain.git merge-treeagainstmainand against this branch gives #11172 one more hunk (3 instead of 2, thecodecvt<char>line). #9526 has the same hunks as againstmain, and #18135 conflicts only in files this branch does not change.num_putformatting (PutFormattedFloatingand new code afterLibcTimePutPattern), not the vtables. Both vtables point at the same functions, so its changes reach facets built on the exported vtable too.messages<char>vtable two lines above this change and changesCheckMessagesVtableObjectjust aboveCheckCodecvtVtableObjectinGuestLocale.cpp. Unchanged lines separate the hunks, andgit merge-treemerges the two branches cleanly.Not in this PR:
num_get<char>vtable and itsdo_getfamily.numpunct<char>,time_put<char>andtime_put<wchar_t>have internal vtables and could be filled the same way, but I found no title that imports them.Tested
Fedora 44 x86-64, GCC 16.2.1, GNU ld 2.46.1, CMake 4.3.0, Ninja 1.13.2, Release with
-DBUILD_TESTING=ON, onmainat44b0108267. I ran no title, homebrew or console, because I have none. Nothing was built or run on Windows or macOS.cmake --build buildbuilt the whole tree.tools/select_tests.py(BUILD.md, "Selective test builds") was 5593 tests, because libc is linked into almost every test. 5592 passed and 1 failed:guest_http, which aborts the same way onmainat2454441420when rebuilt and run alone (checked for #21170); this branch does not touch libSceHttp. 59 tests skipped themselves.guest_locale(changed):CheckNumPutVtableObject: offset-to-top and typeinfo are zero, and slots 2 to 13 equal the vtable of the facetnum_put<char>::_Getcatbuilds. On a facet built on the exported vtable, destroy, retain and release work, and the deleting destructor frees it. All eightdo_putslots format through the exported vtable:bool(which callslongthrough the same vtable), signed and unsignedlongandlong long,doublewith fill and width,long doubleand the pointer.CheckCodecvtVtableObject: offset-to-top and typeinfo are zero, and slots 2 to 12 equal the vtable of the facetcodecvt<char>::_Getcatbuilds. On a facet built on the exported vtable: retain and release,always_noconv,max_lengthandencodingof 1,inandoutreturningnoconvwith both next pointers at the start,unshiftreturningok,lengthreturning the shorter of the range and the count, and the deleting destructor.guest_libc_internal_facet_put,guest_libc_internal_codecvt_charandguest_libc_internal_facet_queriespass.guest_locale_tests, ran it and restored the code. Each change made it fail:doubleandlong doubleslots;CodecvtConstantOnein thelengthslot;codecvtslots.tools/check_conventions.py --base origin/mainreports "All conventions checks passed." With--titleand--bodyset to this title and body, it also passes.tools/debt_fold.py --checkpasses.tools/pr_overlap.py --branch feat/num-put-codecvt-vtables: see Overlap above.Sources
num_put<char>and 13 forcodecvt<char>, with offset-to-top, typeinfo, two destructors and_Incref/_Decreffirstst_size112 and 104 recorded in thelibc.mdentries for these vtables;kNumPutCharVtableSlotsandkCodecvtCharVtableSlotsinGuestLocale.hppg_numPutVtableandg_codecvtVtableincore/libs/prx/libc/src/LocaleSupport.cpp, the vtables_Getcatinstalls, which follow the disassembled console vtables (thelibc.mdentry "codecvt, numpunct, num_put and time_put _Getcat")_Getcatvtable, with offset-to-top and typeinfo zeroc66f61ff52(collate<char>)1kZFcktOm+sis_ZTVSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEEandaK1Ymf-NhAsis_ZTVSt7codecvtIcc9_MbstatetEdata/stubs/by_library/libc.txtlines 166 and 17511kZFcktOm+sandaK1Ymf-NhAs; PPSA01670's and PPSA02929's import1kZFcktOm+s; PPSA21564's importsaK1Ymf-NhAsChecklist
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-16T00:51:45Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
862771e592:tools/check_conventions.pypassed;git diff --checkclean.guest_locale_testsbuilt cleanly.guest_locale):core/libs/prx/libc/src/LocaleSupport.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again._ZTVSt7codecvtIcc9_MbstatetE_nid_postfixinitializes 13std::uintptr_tslots (2 leading zeros for offset-to-top/typeinfo followed by the 4 baseFacetVtableentries and 7CodecvtVtablefunctions matchingg_codecvtVtable)._ZTVSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE_nid_postfixinitializes 14std::uintptr_tslots (2 leading zeros followed by the 4 baseFacetVtableentries and 8NumPutVtabledo_putfunctions in the exact ABI order).reinterpret_cast<std::uintptr_t>(&fn)) and test assertions (std::int64_t/std::uint64_tlimits andstd::uintptr_tslot sizes).docs/dev/debt/changes/feat-num-put-codecvt-vtables.mdproperly documents both exported vtables, their sizes, NIDs, and the zeroed offset-to-top/typeinfo slots in compliance with AGENTS.md.CheckCodecvtVtableObjectandCheckNumPutVtableObjectincore/libs/tests/GuestLocale.cppvalidate byte-for-byte parity (std::memcmp) between&slots[2]and the vtable pointers installed by_Getcat, exercise all virtual slots on a heap-allocatedGuestLocale::Facet, and clean up all allocations.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T02:51:14Z.
Review: APPROVED
Reviewed — looks good
The change wires both exported facet vtables to the same handlers used by their
_Getcatfacets, and the inspected code and reported checks support merging at head862771e5926db9e46edc40a32df0d23b35bb3b5d.What I ran
No commands or tests were run in this review. I read all changed lines and targeted definitions/call sites at the pinned head. The description reports a successful build, selected tests, focused locale tests, negative controls, and convention/debt checks; these are author-reported, not independently run.
Results
Findings
Blocking
None.
Non-blocking
None.
Sources
core/libs/prx/libc/src/LocaleSupport.cpp:759–773wires thecodecvt<char>slots to the functions ing_codecvtVtable(:301);:775–:790wiresnum_put<char>tog_numPutVtable(:554).core/libs/tests/GuestLocale.cpp:139–:166and:672–:697exercise the exported tables and their virtual calls.docs/dev/debt/changes/feat-num-put-codecvt-vtables.md:1–:9records the corresponding debt entries.Not verified
No build, tests, negative controls, console or title runs were performed independently. Files read:
core/libs/prx/libc/src/LocaleSupport.cpp(changed lines and handler/table context),core/libs/tests/GuestLocale.cpp(changed lines),docs/dev/debt/changes/feat-num-put-codecvt-vtables.md(all lines), and the prepared review description, commits, manifest, diff, and README.review/files.jsonwas not present in the prepared review folder; the review file list was checked with its directory listing.To get this to a good state
Nothing is required.