feat(libc): export the num_get and time_get locale objects as data #8880
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8880"
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 ycbuzi on 2026-10-21T04:15:12Z.
What
The public SDK's libSceLibcInternal table declares
num_get<char>::id(-mLzBSk-VGs),time_get<char>::id(a54t8+k7KpY) and thenum_get<char>vtable (KfcTPbeaOqg) as objects. libSceAmpr exported those NIDs asint(void)functions callingNotImplemented, which a data consumer reads as code bytes rather than a trap (#8875).libc now defines the three the way it keeps the other facet ids and the
num_putandcodecvtvtables: the ids as zerouint64, the vtable as 17 zeroeduintptr_tslots, the 136-byte size ofKfcTPbeaOqgthat mazen320 read from the console's libSceLibcInternal symbol table. mazen320 mapped its relocated slots: the offset-to-top and typeinfo entries, the two destructors,locale::facet::_Increfand_Decref, and the elevendo_getthat Dinkumware'ssrc/xlocnumat crt.vc12f1d47126declares, the reference the other libc entries cite. libSceAmpr drops the three functions. An import qualified tolibSceAmpr.prxis searched there and then in libc (WindowsEntryStubBuilder.cpp), so each object has one identity across the two modules, which is what the report asked about. A debt entry says what the objects are and that a facet call through the vtable faults.Not changed: the
time_getfunctions libSceAmpr keeps (get,_Getcat) are functions in the SDK table and stay as they are.Tested
Windows 11, MinGW GCC 15.2.0, Release,
BUILD_TESTING=ON, onmain7ab4b2e561:guest_locale, extended: both ids read zero, take a value and read it back, and are reset; every vtable slot reads zero. Passes. Onmainthe executable cannot link, since libc has no such symbols there.tools/import_audit.pywith the three NIDs qualified tolibSceLibcInternal.prx:implemented 3, absent 0(exit 1 only to note that--libshas no file of that name, whichlibc.prxserves). Qualified tolibSceAmpr.prx:implemented 3, absent 0, exit 0, through the fallback to libc.windows_import_identity(new, Windows): two probes built with the entry stub builder and run beside the patched libraries.same.exeimports the three NIDs qualified tolibSceAmpr.prxand tolibc.prxand exits 0 only if each pair resolved to one address;different.execompares the first withgetpagesizeand must exit 1. Passes (0.2 s).entry_stub(extended by MarcZX10's cherry-picked7157ebb4e8): the generated search order of alibSceAmpr.prx-qualified import is Ampr then libc, and alibc.prx-qualified one goes to libc directly. Passes on Windows; passes on Linux per the author.python tools/check_conventions.py --base origin/main --head HEADpasses.LocaleSupport.cppand #7081 touches other lines of the Ampr file; both conflict withmainalready, and whichever lands second re-adds a few lines.Checklist
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T04:15:53Z.
Progress report (
8c26eac→2a796cb)📈 System libraries: 42.34% (+0.01%, -3 removed functions)
🗑️ 3 removed
_ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE_nid_postfix_ZNSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE_nid_postfix_ZTVSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE_nid_postfixImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:16:26Z.
Code review location:
core/libs/tests/GuestLocale.cpp; line 64The PR description relies on
libSceAmpr.prx-qualified imports falling back to the same libc object, but these tests only check the objects through the direct libc-linked test and import_audit provider inventory. Could you add a resolver/entry-stub regression with a scopedlibSceAmpr.prximport that verifies its search order reaches libc (or a Windows runtime probe showing both qualified imports resolve to the same address)? That would pin the cross-module identity claim independently of the current resolver implementation.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:17:53Z.
On the progress report's "3 removed functions": those are libSceAmpr's
int(void)stubs fornum_get<char>::id,time_get<char>::idand thenum_get<char>vtable, which threwNotImplementedwhen called but were never callable in the first place: the SDK declares the three NIDs as objects, so a guest reads the address as data, and resolving it to code gave neither a trap nor an object (#8875). They are replaced by data objects in libc, which the report does not count as functions, and the NIDs still resolve for both qualifications:tools/import_audit.pyreportsimplemented 3, absent 0with the registry qualified tolibSceLibcInternal.prxand, through the fallback to libc, also qualified tolibSceAmpr.prx.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:23:12Z.
Code review location:
core/libs/tests/GuestLocale.cpp; line 64I checked the current fallback path: on Windows a host import qualified to
libSceAmpr.prxsearches that module and thenlibc.prx, so the intended shared provider looks plausible by inspection. A narrow regression could useWindowsEntryStubBuilderwithlibraries = {"libSceAmpr.prx", "libc.prx"}and one of these NIDs qualified to Ampr, then assert the search table contains both indexes in that order; the libc-qualified case should resolve directly to the same libc index. That would exercise the resolver plan without needing a proprietary title.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:26:25Z.
Code review location:
core/libs/tests/GuestLocale.cpp; line 64I added the resolver-plan regression on my fork at
MarcZX10:codex/pr-8880-ampr-libc-resolver-test(commitbabde2b5bd). It asserts that an Ampr-qualifiednum_get::idimport searches Ampr then libc, while the libc-qualified import searches libc directly. On this PR head,entry_stub_testsbuilds and passes on Linux;python tools/check_conventions.py --base upstream/main --head HEADandgit diff --checkalso pass. This verifies the generated search order, not a runtime address comparison; the branch is available to cherry-pick since direct push to your PR branch is unavailable.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:28:00Z.
Review: COMMENTED
I manually checked the incomparable overlaps the bot listed. #6044 only relocates GuestLocale.cpp and its CMake/test registration as part of suite organization; it does not change the test logic in this PR. #7081 changes shared Sony CRT handler/localeconv plumbing, #7648 changes thread error dispatch, #8352 adds different locale facets/exports (, , ), and #8711 changes string/thread ABI; none duplicates these three , , or vtable objects. #6565's debt entry is unrelated; both documentation entries need to be retained if rebasing/merging. These look like independent changes, though Git may require routine conflict resolution around shared files.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:28:07Z.
Review: COMMENTED
I manually checked the incomparable overlaps the bot listed. #6044 only relocates GuestLocale.cpp and its CMake/test registration as part of suite organization; it does not change the test logic in this PR. #7081 changes shared Sony CRT handler/localeconv plumbing, #7648 changes thread error dispatch, #8352 adds different locale facets/exports (codecvt, numpunct, time_put), and #8711 changes string/thread ABI; none duplicates these three num_get::id, time_get::id, or num_get vtable objects. #6565's debt entry is unrelated; both documentation entries need to be retained if rebasing/merging. These look like independent changes, though Git may require routine conflict resolution around shared files.
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:30:37Z.
Code review location:
core/libs/tests/GuestLocale.cpp; line 64Both are in now. Your search-order regression is cherry-picked as
7157ebb4e8with your authorship; on this headentry_stub_testspasses on Windows as well. The runtime side is2657a81218:windows_import_identity(core/relinker/elfpatcher/tests/WindowsImportIdentityTests.cpp, registered next towindows_dependency_diagnostics). It generates two probes withWindowsEntryStubBuilder,WindowsImportBuilderandWindowsPeWriter, the way #8853's generator and the diagnostics test do, and runs them beside the patched libraries (core/libs/libs, so it depends onlibs):same.exeimports the three NIDs twice each, qualified tolibSceAmpr.prxand tolibc.prx, into six GOT slots, and its entry compares each pair (mov rax,[a]; cmp rax,[b]; jne fail), exiting 0 only if all three resolved to one address.different.execompares the first NID fromlibSceAmpr.prxwithgetpagesizefromlibkernel.prxand must exit 1, so a comparison that could not tell addresses apart would fail the test.A failed probe's stub output lands in the test's message (an empty library folder gives
Failed to load module: ...libSceAmpr.prx,GetLastError: 126). Qualifying the second import tolibSceLibcInternal.prxis not possible at this layer, the stub builder only accepts modules from its load list, and the relinker addslibc.prxfor that name before this stage (GuestModuleBuilder.cpp), solibc.prxis the direct reference here.Result on this PC (Windows 11, MinGW GCC 15.2.0, Release):
windows_import_identitypasses (ctest -R windows_import_identity, 0.2 s) afterninja windows_import_identity_tests, which buildslibsfirst. The description's Tested section lists both.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:39:19Z.
The new Windows
relinkerCI job currently fails during CMake generation: withANYPS5_RELINKER_ONLY=ON, top-levelCMakeLists.txtreturns before addingcore/libs, so the newadd_dependencies(windows_import_identity_tests libs)atcore/relinker/CMakeLists.txtreferences a nonexistent target. The logged failure isThe dependency target "libs" ... does not existbefore compilation. Could this test be gated out of relinker-only mode, or be restructured to consume built patched libraries only in the full build while keeping the pure stub-builder coverage in the relinker-only test? The standaloneentry_stubassertion is useful but does not exercise actual object-address identity.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:42:27Z.
Gated out in
0c8fb06573: thewindows_import_identitytarget and test are registered only whenANYPS5_RELINKER_ONLYis off, since they need the patched libraries that a relinker-only tree never builds. A relinker-only configure with the job's options (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Ninja, g++) now generates here, and the full build keeps the runtime test (ctest -R windows_import_identitypasses). The address identity itself stays covered by that test in the full build;entry_stubkeeps the search-order assertion in both configurations.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:45:13Z.
Thanks, that addresses the relinker-only configure failure and keeps the actual address-identity test in the full-build configuration. The rerun has passed the Linux/macOS register-context jobs so far; I will check the remaining CI results before treating the PR checks as clean.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:03:54Z.
The rerun is now fully green for the applicable jobs: conventions, eligibility/labels, Debug and Release register-context on Ubuntu and macOS, relinker on Linux/macOS/Windows, relinker ASan, and write-watch on both macOS runners all pass. Linux and Windows broad build jobs are skipped by this workflow configuration.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:56:54Z.
I checked the current head and found the Ampr-qualified locale-object fallback regression already included (
windowsLibSceAmprObjectImportsFallBackToTheLibcProvider, added in the updated PR history). I configured a fresh Linux relinker-only build on head0c8fb06573, builtentry_stub_tests, and ranctest --test-dir build -R "^entry_stub$" --output-on-failure: 1/1 passed. The conventions checker andgit diff --check upstream/main...HEADalso pass. No additional commit is needed for that coverage.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T06:28:22Z.
Review: APPROVED
The earlier relinker-only configure failure is fixed, and I independently built and ran
entry_stubon Linux (1/1 pass). Current applicable CI checks are green. The PR covers the three data exports identified by #8875 and keeps the unverified facet-call behavior documented as debt. Approved.Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-21T20:39:20Z.
Console measurement (jailbroken PS5 FTP
192.168.0.144,libSceLibcInternal.sprxSHA-256a2d70cc64c3abc3927662cbe0c3765b74b2385b4b2ad80eb7b942a891f9259fb, parsed with the module's ownDT_SYMTAB/DT_STRTAB; no Ghidra).st_infost_size-mLzBSk-VGsnum_get<char>::idSTT_OBJECTSTB_WEAKa54t8+k7KpYtime_get<char>::idSTT_OBJECTSTB_WEAKKfcTPbeaOqgnum_get<char>vtableSTT_OBJECTSTB_WEAKlibSceAmpr.sprxfrom the same console has no dynsym entries for these three NIDs (Ampr is 152STT_FUNC+ 2 unrelatedSTT_OBJECT). That matches moving the providers into libc and dropping the Amprint(void)stubs.Mismatch with this PR head: the vtable is exported as 15
uintptr_tslots (120 bytes). On the console the symbol size is 136 (17 slots). Ids of size 8 and zero-init match what you already have. Suggest sizing_ZTVSt7num_get...to[17]sost_sizematches the console export; a 15-slot object is short by two pointers relative to the firmware symbol.REA: Ghidra/Hopper not usable for these ELF SPRX on Windows here; sizes come from the ELF symbol table only. No title run.
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T20:46:01Z.
@mazen320 thanks, that settles the size.
428e9cb5f3exports thenum_get<char>vtable (KfcTPbeaOqg) as 17 zeroed slots, the 136 bytes you read, and the debt entry and the description now give that size and its source instead of the 15 I had derived from Dinkumware's crt.vc12xlocnum. Which two virtual functions the console's build adds is not known, so the entry doesn't name them.guest_locale(which reads every slot),windows_import_identityandentry_stubpass on Windows 11 on both repeats.If you still have the module at hand: the sizes of the
num_put<char>vtable (_ZTVSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE) and thecodecvt<char, char, _Mbstatet>vtable (_ZTVSt7codecvtIcc9_MbstatetE) would show whether the two extra slots are common to every facet. libc onmainkeeps those as 12 and 16 slots, and 12 is what the same crt.vc12 count gives fornum_put.Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-21T21:42:43Z.
Follow-up after installing Ghidra 12.1.4 and re-checking the same console
libSceLibcInternal.sprx:KfcTPbeaOqgare all zero;R_X86_64_RELATIVEfixups fill the object. After applyingDT_RELA, the symbol is stillst_size136 and expands to 17 qwords:[0]=0(offset-to-top)[1]=0x1af350(typeinfo)[2]..[16]= 15 method pointersuintptr_t[15]is two slots short of the firmware symbol.uintptr_t[17]{}matchesst_size(headers + 15 methods). Slot contents can stay zeroed as debt until facet methods are wired; sizing should still match the console export.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T21:45:25Z.
Thanks, that matches
428e9cb5f3(17 zeroed slots). If the 15 relocation targets in[2]..[16]resolve to symbol names, they would show which two virtual functions the console'snum_get<char>adds beyond Dinkumware's two destructors and elevendo_get; the debt entry leaves that open.Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-21T21:54:13Z.
@ycbuzi Mapped the 15 relocation targets in
[2]..[16](plus typeinfo at[1]) on the same consolelibSceLibcInternal.sprxafter applyingR_X86_64_RELATIVE. Slot[0]is the Itanium offset-to-top word (0); a dynsym entry also sits at VA0and is not part of this vtable.6ddOFPDvuCotypeinfo for std::num_get<char, …>kAay0hfgDJsnum_get<…>::~num_get()-1G1iE3KyGInum_get<…>::~num_get()(deleting)-EgSegeAKl4locale::facet::_IncrefAgxEl+HeWRQlocale::facet::_Decrefdo_get×11SmtBNDda5qU…VKdXFE7ualwbool,unsigned short,unsigned,long,unsigned long,long long,unsigned long long,float,double,long double,void*So the console layout is 2 header words + 4 non-
do_getmethods + 11do_getoverloads = 17 qwords. There are not two extrado_gets beyond eleven; the earlier “15 slots total” count was collapsing the headers. Names fromtools/nid_names.pyagainst the relocated targets; no title run.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T21:57:28Z.
Thanks, that answers it:
locale::facet::_Increfand_Decref. I checked the five non-do_getNIDs by hash (6ddOFPDvuCo,kAay0hfgDJs,-1G1iE3KyGI,-EgSegeAKl4,AgxEl+HeWRQ) and they match those names.6287af9657names the slots in the debt entry and the description. If the console's other facets carry the same two entries, libc's 12-slotnum_putvtable onmain, counted from crt.vc12 the same way as my 15, may be two short as well; its symbol size would settle that.