feat(libc): add missing Unity IL2CPP runtime imports and Dinkumware helpers #4164
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4164"
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 hamb3r on 2026-10-12T00:18:44Z.
What
During the boot sequence of Unity IL2CPP titles such as God of War: Sons of Sparta (PPSA28997),
eboot.elfand guest modules (Il2cppUserAssemblies.prx,lib_burst_generated.prx,PS5Util.prx, etc.) statically import Dinkumware and libc runtime symbols fromlibc.prx.This branch implements the missing Dinkumware, backtrace, and RTTI typeinfo imports in
libc.prx, and deduplicates overlapping stubs previously placed inlibSceAmpr:core/libs/prx/libc/src/Math.cpp):b-xTWRgI1qw->_Dtest: Dinkumware double floating-point classification matching_FDtest(finite -1, denormal -2, zero 0, infinite 1, NaN 2).HIhqigNaOns->_Inf: Dinkumware CRT double infinity constant.core/libs/prx/libc/src/Backtrace.cpp):sMko2YZqDNQ->sceLibcBacktraceGetBufferSize: calculates required buffer size for call stack frames.MTnuKt7HiN0->sceLibcBacktraceSelf: captures stack frames into caller buffer using host backtrace (RtlCaptureStackBackTraceon Windows,backtrace/dladdron Linux).core/libs/prx/libc/src/Threads.cpp):0uuqgRz9qfo->_Cnd_signal: wakes one waiter on condition variable.core/libs/prx/libc/src/RuntimeSupport.cpp,core/libs/prx/libc/src/exception/TypeInfo.cpp):LTov9gMEqCU->_ZNSt8ios_base7_AddstdEPS_: no-op standard stream registration helper.aeHxLWwq0gQ->_ZTVN10__cxxabiv119__pointer_type_infoE: RTTI vtable for pointer types.CSEjkTYt5dw->_ZTVN10__cxxabiv120__function_type_infoE: RTTI vtable for function types.core/libs/prx/libSceAmpr/Export.cpp):NotImplementedstubs that shadowedaeHxLWwq0gQandCSEjkTYt5dw.core/libs/tests/GuestMath.cpp(CheckDoubleClassification) andcore/libs/tests/GuestLibcThreads.cpp(ConditionSignal).docs/dev/debt/libc.md.Status of PPSA28997 Imports
Imports resolved by this PR from
libc.prx:b-xTWRgI1qw(_Dtest)HIhqigNaOns(_Inf)sMko2YZqDNQ(sceLibcBacktraceGetBufferSize)MTnuKt7HiN0(sceLibcBacktraceSelf)0uuqgRz9qfo(_Cnd_signal)LTov9gMEqCU(_ZNSt8ios_base7_AddstdEPS_)aeHxLWwq0gQ(_ZTVN10__cxxabiv119__pointer_type_infoE)CSEjkTYt5dw(_ZTVN10__cxxabiv120__function_type_infoE)Imports exported only from
libSceAmpronmain:The following symbols required by PPSA28997 are implemented in
libSceAmpronmain(via #3743 / #3558). Because they are not exported fromlibc.prx, direct imports of them fromlibc.prxstill fail unless redirected or addressed in follow-up work:dGYo9mE8K2A(_ZNSt4_PadC2Ev)gjLRZgfb3i0(_ZNSt4_PadD2Ev)xZqiZvmcp9k(_ZNSt4_Pad7_LaunchEPP7pthread)a-z7wxuYO2E(_ZNSt4_Pad8_ReleaseEv)np6xXcXEnXE(_Thrd_id)W0j6vCxh9Pc(_ZSt16_Throw_Cpp_errori)Changes from Earlier Revisions
As requested during review:
std::_Padhelpers (_ZNSt4_Pad*),_Thrd_id,_Thrd_join, and_Throw_Cpp_errorwere dropped fromlibcto avoid duplicate exports withlibSceAmprmerged in #3743.guest_libc_backtracetest target were removed.docs/dev/debt/libc.md.Tested
guest_math_testsandguest_libc_threads_testspass (100%).python tools/check_conventions.py --base origin/mainpasses with 0 errors.git diff --check origin/mainclean.guest_math_testsandguest_libc_threads_testspass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-12T00:25:52Z.
Hi @adriadam10 @oneandonlydean,
Following up on the deduplication approach discussed in #3648, this PR implements the remaining
libc.prxstatic imports required by the Unity IL2CPP runtime (God of War: Sons of Sparta, PPSA28997):libc: As noted during #3648 review, Dinkumware thread helpers (std::_Pad,_Cnd_signal, etc.) belong inlibcwhere Unity titles actually import them from, rather thanlibSceAmpr(as done in #3743 / #3742). Duplicate stubs inlibSceAmprhave been removed._Dtest,_Inf,sceLibcBacktrace*,_ZNSt4_Pad*,_Cnd_signal,_Thrd_id,_Thrd_join,_ZSt16_Throw_Cpp_errori,_Addstd, and C++ ABI RTTI vtables.sinhfis intentionally excluded as it is tracked in #3725.guest_math,guest_libc_threads,guest_libc_backtrace) passes (100%), andtools/check_conventions.pypasses with 0 errors.Whenever you have a chance, would appreciate your review!
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T00:28:35Z.
Progress report (
0214069→8652dbe)📈 System libraries: 88.16% (+0.01%, +4 implemented, +3 declared, -4 removed functions)
✅ 4 implemented
IsFunctionTypeInfoTrueIsPointerTypeInfoTrue_Cnd_signal_nid_postfix_Dtest_nid_postfix⚪ 2 behaviourally empty (constant return or throw)
IsFunctionTypeInfoTrueIsPointerTypeInfoTrue🆕 3 declared as stubs
_ZNSt8ios_base7_AddstdEPS__nid_postfixsceLibcBacktraceGetBufferSize_nid_postfixsceLibcBacktraceSelf_nid_postfix🗑️ 4 removed
_Cnd_signal_nid_postfix_ZNSt8ios_base7_AddstdEPS__nid_postfix_ZTVN10__cxxabiv119__pointer_type_infoE_nid_postfix_ZTVN10__cxxabiv120__function_type_infoE_nid_postfixImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T09:14:56Z.
_Pad::_Launchstarts a host thread (core/libs/prx/libc/src/Threads.cpp:328,334) and runs the guest_Goon it, and_Thrd_join(Threads.cpp:356) waits on that host handle instead of joining the guestpthread_tas main's does. Guest code has to run on a guest thread: please create it throughpthread_create_nid_postfix, as #3743 does for the same four_Padexports, and keep main's_Thrd_join. libc is the right place for them.Two more things before this can go in:
_Thrd_idreturning the host thread id (Threads.cpp:344),_Thrd_join(nullptr)returning success (Threads.cpp:357),ios_base::_Addstdas a no-op (RuntimeSupport.cpp:187) and_Throw_Cpp_errorthrowing the host'sstd::system_error(Threads.cpp:352) are guesses. PPSA28997 only needs the exports to exist to load, so leave them throwingNotImplemented_nid_no_patchuntil a title calls them.sceLibcBacktraceGetBufferSizeandsceLibcBacktraceSelf: where does the record layout come from?guest_libc_backtraceonly checks the return value. Either give the source and test the records, or keep these throwing too.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-12T09:53:06Z.
Thanks for the review @oneandonlydean! I've addressed all points in commit aa27a61:
_Pad::_Launch: Switched it to create a guest thread viapthread_create_nid_postfixwith thePadEntry_nid_no_patchtrampoline executing_Go()._Thrd_join: Keptmain's implementation inlibSceAmprand removed the custom version fromlibc._Thrd_id,_Throw_Cpp_error, and_Addstdnow throwNotImplemented_nid_no_patch(__func__).sceLibcBacktraceGetBufferSizeandsceLibcBacktraceSelfthrowingNotImplemented_nid_no_patch(__func__).I've also updated the unit tests (
guest_libc_threads,guest_libc_backtrace,guest_ampr_threads) andTechnicalDebt.mdaccordingly.check_conventions.pypasses with 0 errors.Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-12T16:16:48Z.
I checked the PS5 SDK implementation of
_Thrd_idwhile investigating Astro Bot (PPSA21564, 01.007.000). The locally unwrapped shippedlibc.prxhas SHA-25631a0e9af83bc5b95b8f81949dd575b7708e90bd774f5ed3925843282bf98b54e.Export
np6xXcXEnXE#D#A, ELF vaddr0x4f20(11 bytes), calls the PLT at0x115600and returns with RAX unchanged. The PLT jumps through0x192358; that JMPREL entry resolves symbol 499,aI+OeCz8xrQ#A#B, which hashes toscePthreadSelf. It does not callscePthreadGetthreadid(EI-5-jlq2dE). This supports preserving the guest pthread handle, including its upper bits, rather than using the Microsoft STL Windows 32-bit thread-ID representation. The original C++ declared type and console allocation/reuse policy remain unmeasured.I tested a local
Pthreadwrapper returningscePthreadSelf()on maind592d54e1, with eight simultaneous guest pthreads, one adopted host thread and the caller. The regression checks stable, distinct live identities, equality withscePthreadSelf, and equality with each created pthread handle. The same regression fails against unchanged main at_Thrd_id_nid_postfix not implemented. On Windows 11, WinLibs GCC 15.2, Release, all four focused checks passed (guest_ampr_threads,guest_libc_threads,patched_libraries,progress_report) after building the complete library set. This is emulator validation, not a PS5 hardware run or an Astro Bot gameplay fix.The current diff here relocates
_Thrd_idinto libc as a throwing stub. Its canonical placement needs coordination with that relocation. Would you prefer to incorporate the observed behavior here, or have a separate follow-up after the relocation lands? My tested local wrapper currently lives in AMPR; a libc implementation would need access to the same kernel thread identity without adding a library dependency cycle.No game files or captured binaries are included. Investigation and tests were assisted by Codex.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T18:06:04Z.
One import-source check before removing
_ZSt16_Throw_Cpp_errori_nid_postfixfromlibSceAmpr: issue #3346 reports Deathloop and Minecraft Legends importing this exactlibSceAmprexport, and open PR #3679 implements it there. This PR adds alibcexport, but imports are resolved from their named library, so that would not satisfy an import requestinglibSceAmpr. Could you confirm whether those titles really import it fromlibSceAmpr, and preserve the AMPR export if they do? That would let the Unitylibccase and the reported AMPR case coexist.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T18:13:37Z.
The
scePthreadSelftrace and focused Windows regression described above are useful evidence for_Thrd_idreturning the guest pthread identity. Since this PR currently leaves_Thrd_idthrowing and the implementation may need dependency/placement work, a focused follow-up after the libc export location is settled seems easiest to review. Please coordinate with p3n1cillin on the tested wrapper and preserve the stated limitation: this is emulator validation, not a PS5 hardware result.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-12T20:07:06Z.
@oneandonlydean Quick update: rebased cleanly on current
main(resolving conflicts from the recent debt restructuring intodocs/dev/debt/libc.md). All review feedback remains addressed, conventions and guest test suites pass.@p3n1cillin Thanks a lot for investigating the PS5
libc.prxand verifying_Thrd_id! ThescePthreadSelffinding is very valuable evidence. I agree with Marc that keeping_Thrd_idas a throwing stub in this PR and doing the full implementation (along with managing thelibc<->libkernelthread identity linkage) in a focused follow-up PR is the cleanest path forward for review and merge.@MarcZX100 Thanks for bringing up the AMPR import case! Regarding keeping the exports in both libraries:
tools/check_conventions.pystrictly flags[duplicate-export]when the sameAPS5_VABIsymbol is exported by multiple libraries. However,libSceAmprimporters like Deathloop and Minecraft Legends won't break: the relinker's host import resolution inWindowsEntryStubBuilder.cpp:112-114automatically appendslibc.prxto the search order for all host module imports. So an import requesting_ZSt16_Throw_Cpp_errorifromlibSceAmpr.prxfalls back tolibc.prxand resolves cleanly at runtime. Once this PR lands, your PR #3679 can rebase the fullstd::system_errorimplementation directly intolibc.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-12T21:11:09Z.
@oneandonlydean Rebased on latest main and resolved the conflict again.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:12:04Z.
Thanks for clarifying the import-resolution behavior and the duplicate-export convention. Follow-up: #3679 has since merged, so _ZSt16_Throw_Cpp_errori is now provided from libc and the overlap should be resolved on current main. Your rebased PR can keep the throwing AMPR import resolution through the relinker's libc search fallback, as you describe.
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:49:17Z.
Linux build (Arch, GCC 16.2.1, Release,
BUILD_TESTING=ON), this PR's headd0d38e789merged ontomain7e181fcc3: 137 test executables fail to link, for exampleguest_mktime_tests,guest_math_tests,guest_libc_backtrace_tests:On Windows
_Pad::_Launchlookspthread_create_nid_postfixup at run time withGetProcAddress, but on other systems it declares itexternand calls it directly, solibc.prxgets an undefined reference to a libkernel symbol. Test programs that link onlylibcthen fail.mainbuilds these targets on the same machine. A run-time lookup on Linux too (for exampledlsym(RTLD_DEFAULT, "pthread_create_nid_postfix")), like the Windows branch, would avoid the link-time dependency. The CIlinuxjob is skipped for this PR, so it would not show there.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T08:31:19Z.
The linker failure reported above is a real portability blocker for this PR: the non-Windows branch leaves
pthread_create_nid_postfixas a strong unresolved reference fromlibc.prx, so test executables that link libc without libkernel fail before any test can run. The WindowsGetProcAddresspath avoids that link-time dependency. Please make the non-Windows path resolve the symbol at runtime as well (or otherwise remove the libc → libkernel link-time dependency), while retaining an explicit failure if the symbol is unavailable. If usingdlsym(RTLD_DEFAULT, ...), please verify that the loaded libkernel symbol is actually visible in that lookup scope; the key requirement is that standalone libc consumers still link.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-13T10:21:37Z.
@nicolasfalesy @MarcZX100 Thanks for the diagnosis and discussion!
I have addressed both the link-time blocker and the post-patching symbol resolution in commit c95bdaba8:
extern "C"reference topthread_create_nid_postfixfromlibc.prxand linked `` incore/libs/prx/libc/CMakeLists.txt, so standalonelibcconsumers now link cleanly withoutlibkernel.CallPthreadCreate(core/libs/prx/libc/src/Threads.cpp), runtime lookup first queriesOxhIB8LB-PQ(the deterministic NID generated bynid_patcherforpthread_create), and only falls back topthread_create_nid_postfixfor in-tree unpatched test harnesses.guest_libc_threadsunit tests pass against the unpatched test harness.nid_patcherruns onlibkernel.prx,pthread_create_nid_postfixis stripped from exports and_Pad::_LaunchresolvesOxhIB8LB-PQdynamically at runtime.python tools/check_conventions.py --base origin/mainpasses with 0 errors.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T10:32:02Z.
CallPthreadCreate(core/libs/prx/libc/src/Threads.cpp) now tries the NID, then the name, thenLoadLibraryA/dlopen; fallback chains like this aren't allowed here. libkernel already links libc, so have libkernel register itspthread_createwith libc when it loads, and make_Launchthrow when nothing was registered.Also please drop
guest_libc_backtrace: it only checks that the stubs throw.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-13T13:01:44Z.
@oneandonlydean Thanks for the architectural guidance!
I've updated the implementation accordingly (commit
fb151594c):libkernelnow registers itspthread_createwithlibcupon loading (RegisterPthreadCreate_nid_no_patch)._Launch:_ZNSt4_Pad7_LaunchEPP7pthread_nid_postfixchecks thatpthread_createhas been registered and explicitly throwsstd::runtime_errorif called without a registered callback. Added a unit test inGuestLibcThreads.cppvalidating this throwing behavior when unregistered as well as successful launch when registered.LoadLibrary/dlopenlogic, and${CMAKE_DL_LIBS}linkage inlibc/CMakeLists.txt. Standalonelibcconsumers link cleanly withoutlibkernel.guest_libc_backtrace: RemovedGuestLibcBacktrace.cppand its test target as requested.check_conventions.pypasses with 0 errors.guest_math,guest_libc_threads) pass on Windows (MinGW GCC 15).Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-13T13:43:02Z.
@adriadam10 @oneandonlydean Rebased onto current
main. As requested following the merge of #3743, dropped thestd::_Padand_Thrd_idexports fromlibcto avoid duplicate exports. The remaining additions (_Dtest,_Inf,sceLibcBacktrace*,_Cnd_signal,_ZNSt8ios_base7_AddstdEPS_, and typeinfo vtables) build and pass all unit tests and conventions on both Windows and Linux.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-13T16:06:10Z.
@adriadam10 @oneandonlydean Rebased onto current main again
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T20:26:19Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL67-68Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T20:28:49Z.
The latest overlap check only reports a shared hunk in
docs/dev/debt/libc.mdwith #5454; it reports no shared exports or source files. These changes appear independent, so I don't see a dependency to add. If #5454 merges first, this PR will likely need the debt-doc hunk refreshed on rebase.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T21:05:05Z.
Please update the description to what this branch does now: the
_Pad,_Thrd_id,_Thrd_joinand_Throw_Cpp_errorparts, the backtrace layout andguest_libc_backtraceare gone, and the debt entry is indocs/dev/debt/libc.md. Also list which of the PPSA28997 imports it resolves:dGYo9mE8K2A,gjLRZgfb3i0,xZqiZvmcp9k,a-z7wxuYO2E,np6xXcXEnXEandW0j6vCxh9Pcare exported only from libSceAmpr on main, so imports of them fromlibc.prxstill fail.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-13T21:17:08Z.
Thanks @oneandonlydean! I have updated the PR description to accurately reflect what the branch does now:
_Pad,_Thrd_id,_Thrd_join,_Throw_Cpp_error, custom backtrace layout, andguest_libc_backtrace).docs/dev/debt/libc.md.libc.prx, as well as the 6 symbols that remain exported only fromlibSceAmpronmain.