fix(libc): add missing Unity engine static imports #3648
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3648"
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-11T14:44:32Z.
What
During the boot sequence of Unity Engine titles like God of War: Sons of Sparta (PPSA28997),
eboot.elfand associated game guest PRXs (Il2cppUserAssemblies.prx,lib_burst_generated.prx,PS5Util.prx, etc.) statically import symbols fromlibc.prx.Without these exports in
libc.prx, the Windows loader startup stub fails at boot:This PR implements the missing static exports for
libc.prx:c+4r-T-tEIc=nearbyintf: implemented incore/libs/prx/libc/src/Math.cppviastd::nearbyint(x).k6pGNMwJB08=_Mtx_trylock: implemented incore/libs/prx/libc/src/Threads.cppoverDinkumwareMutexmatching_Mtx_locksemantics.jfRI3snge3o=_Thrd_sleep: implemented incore/libs/prx/libc/Export.cppaslibc__Thrd_sleeptaking(const Xtime*, Xtime*)and looping onnanosleepuntil the deadline.H2e8t5ScQGc=__cxa_finalize: exported inlibc.prxaslibc___cxa_finalizeforwarding directly toCxaFinalize_nid_no_patch(dsoHandle).guest_libc_static_imports(core/libs/tests/GuestLibcStaticImports.cpp) registered in ctest pinningnearbyintf(±0.5, ±1.5, ±2.5, -0.0, ±inf, NaN),_Mtx_trylock(free, held, and recursive mutex), and_Thrd_sleep(deadline checks).Tested
guest_libc_static_importspasses via ctest.libc.prx, startup aborts immediately withFAIL: unresolved ELF import c+4r-T-tEIc from libc.prx.libc.prx, all 1813 external PRX imports resolve cleanly, and the title boots through early runtime initialization.Checklist
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T14:44:53Z.
Progress report (
24865e8→b8a1cbe)📈 System libraries: 86.21% (+0.01%, +4 implemented, -1 removed functions)
✅ 4 implemented
_Mtx_trylock_nid_postfix_Thrd_sleep_nid_postfixlibc___cxa_finalizenearbyintf_nid_postfix🗑️ 1 removed
_Thrd_sleep_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T14:47:55Z.
Review: CHANGES_REQUESTED
Thanks for tracking this down. Some of these NIDs are already exported on
main, so the stubs would duplicate them:802pFCwC9w0=__udivti3: implemented incore/libs/prx/libc/src/RuntimeSupport.cpp:158(__udivti3_nid_postfix).VUzjXknPPBs=mbstowcs: implemented incore/libs/prx/libc/src/Multibyte.cpp:162.KuOuD58hqn4=malloc_stats_fast: implemented incore/libs/prx/libc/src/FileAndHeap.cpp:267(covered byApplicationHeapStats).A second
APS5_EXPORTfor the same NID exports it twice; the Windows PE patcher rejects that (duplicate patched export name), and a stub must never shadow a real implementation. Please drop these three. Yourimport_audit.pyrun was probably against a registry/build older than currentmain; please re-run it on a freshmainbuild and keep only what is still absent.For the rest:
H2e8t5ScQGc=__cxa_finalizeis exported bylibSceLibcInternal(Export.cpp:112). Check which library the title imports it from before adding it tolibc.jfRI3snge3o=_Thrd_sleephas an implementation inlibSceAmpr/Export.cpp:946. Check the same (and whether it belongs inlibc).c+4r-T-tEIc=nearbyintfandk6pGNMwJB08=_Mtx_trylockare not implemented anywhere, so a throwing stub is fine there if they are still absent after the re-run.Also, use the real names (
nearbyintf,_Mtx_trylock) with the actual signatures instead oflibcUnknown_*(void), perdocs/dev/CONVENTIONS.md/docs/dev/TechnicalDebt.md, and add the stubs' lines to TechnicalDebt (stubs that throw).Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:19:44Z.
Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON.tools/check_conventions.py --base origin/mainpasses.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T15:28:32Z.
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)core/libs/prx/libSceAmpr/Export.cppL228-231, L241-256docs/dev/TechnicalDebt.mdL392-393docs/dev/TechnicalDebt.mdL55Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-11T15:29:51Z.
Thanks for the thorough review @adriadam10.
I've rebased on current
mainand addressed all points:Dropped the 3 duplicates:
802pFCwC9w0(__udivti3),VUzjXknPPBs(mbstowcs), andKuOuD58hqn4(malloc_stats_fast) were removed from this PR since they are already implemented onmain.Checked import sources:
H2e8t5ScQGcandjfRI3snge3oare indeed imported fromlibc.prxby the title:eboot.elfexplicitly importsjfRI3snge3o(_Thrd_sleep) fromlibc.prx.Il2cppUserAssemblies.prx,lib_burst_generated.prx,PS5Util.prx, etc.) explicitly importH2e8t5ScQGc(__cxa_finalize) fromlibc.prx.H2e8t5ScQGc,libc___cxa_finalizeis now exported inlibcforwarding directly to the existingCxaFinalize_nid_no_patch(dsoHandle).Function names, signatures, and TechnicalDebt:
libcUnknown_*stubs with their actual signatures:float APS5_VABI nearbyintf_nid_postfix(float x)(c+4r-T-tEIc)int APS5_VABI _Mtx_trylock_nid_postfix(void** handle)(k6pGNMwJB08)libc__Thrd_sleep(jfRI3snge3o)docs/dev/TechnicalDebt.mdunderUnknown function info.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T15:31:06Z.
Review: CHANGES_REQUESTED
Thanks for dropping the duplicates and rebasing. Three of the four exports can be exact instead of throwing, and
mainalready has the pieces:_Mtx_trylock(core/libs/prx/libc/Export.cpp:41):libcalready implements_Mtx_init/_Mtx_lock/_Mtx_unlockoverDinkumwareMutex(core/libs/prx/libc/src/Threads.cpp:93). Add_Mtx_trylocknext to_Mtx_lockthere (sameResolveMutex,native.try_lock(), same owner/recursive handling,threadBusywhen it is held), not a throwing stub inExport.cpp._Thrd_sleep(Export.cpp:52): an exact implementation already exists as_Thrd_sleep_nid_postfixincore/libs/prx/libSceAmpr/Export.cpp:946(takesconst Xtime*, loops onnanosleepuntil the deadline). Reuse that logic/signature for thelibcexport instead of a new(const void*, void*)stub.nearbyintf(Export.cpp:35): this is plain C99 (round to integer in the current rounding mode, default round-half-even). Implement it withstd::nearbyintfrather than throwing; the TechnicalDebt entry for it is then not needed.nearbyintfat ±0.5, ±1.5, ±2.5, -0.0, ±inf, NaN;_Mtx_trylockon a free, held (other thread) and recursive mutex;_Thrd_sleepreturning after the deadline. It must fail without the change._Mtx_trylockand_Thrd_sleephere are the Dinkumware_Mtx_*/_Thrd_*internals, not<threads.h>).__cxa_finalizeforwarding toCxaFinalize_nid_no_patchlooks fine.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-11T15:53:17Z.
Thanks for the guidance @adriadam10.
I have updated the PR with exact implementations and guest test coverage:
_Mtx_trylock(k6pGNMwJB08):core/libs/prx/libc/src/Threads.cppright next to_Mtx_lock.ResolveMutex,native.try_lock(), handles caller ownership and recursive mutexes, returningthreadBusy(3) when held by another thread.nearbyintf(c+4r-T-tEIc):core/libs/prx/libc/src/Math.cppviastd::nearbyintf(x)._Thrd_sleep(jfRI3snge3o):core/libs/prx/libc/Export.cppaslibc__Thrd_sleeptaking(const Xtime* target, Xtime* remaining).XtimeDeadlinenormalization andnanosleeploop checkingclock_gettime(CLOCK_REALTIME).TechnicalDebt:
docs/dev/TechnicalDebt.mdsince all three are now fully implemented rather than stubs.Guest Test:
guest_libc_static_importsincore/libs/tests/GuestLibcStaticImports.cppand registered in ctest undercore/libs/prx/libc/CMakeLists.txt.nearbyintfat ±0.5, ±1.5, ±2.5, -0.0, ±inf, and NaN (including signbit checks)._Mtx_trylockon free, held (cross-thread), and recursive mutexes._Thrd_sleepverifying return after the deadline and rejection of null target.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T20:51:23Z.
Review: DISMISSED
Checked on Linux (build +
guest_libc_static_importspass; without the change the test does not link, so it pins the new code). The NIDs match aerolib. Two things left:_Thrd_sleep(core/libs/prx/libc/Export.cpp:11-35,72-88) is a copy of the one already inlibSceAmpr(core/libs/prx/libSceAmpr/Export.cpp:221-259,946-960: sameXtime,XtimeDeadline, loop and error strings). Please don't duplicate it: libc is the module the title imports it from andlibSceAmpralready linkslibc, so keep a single implementation (in libc, next to the other thread code) and havelibSceAmprstop exporting its own copy, as in the duplicate-exports cases of #228/#241. Move the_Thrd_sleeppart of the "Dinkumware thread exports" TechnicalDebt line along with it._Mtx_trylock(busy for a non-recursive mutex already owned by the caller, assumed to match_Mtx_lock's ownership handling),nearbyintf(host rounding mode, not the console's) and_Thrd_sleeponce moved.Minor:
nanosleepreturningEINTRcurrently throws; since the loop rechecks the deadline, retry onEINTRand throw only on other errors.Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-11T22:14:24Z.
Thanks for the feedback @adriadam10.
I've rebased on current
mainand addressed the remaining items:Deduplicated
_Thrd_sleep:_Thrd_sleep_nid_postfixalong withXtimeandXtimeDeadlineintocore/libs/prx/libc/src/Threads.cppalongside the other thread functions.core/libs/prx/libSceAmpr/Export.cpp.core/libs/prx/libc/Export.cppso it only containslibc___cxa_finalize.Handle
EINTRin_Thrd_sleep:errno == EINTRcheck onnanosleepfailure tocontinuethe deadline loop, throwing only on other errors.TechnicalDebt.md:
libSceAmprDinkumware thread exports entry to remove_Thrd_sleep.### Unknown function infofor:_Mtx_trylock: busy return for a non-recursive mutex already held by the caller;nearbyintf: host rounding mode rather than the console's;_Thrd_sleep: Dinkumware threads library origin andEINTRretry behavior.All relevant tests (
guest_libc_threads,guest_libc_static_imports,guest_ampr_threads) andtools/check_conventions.pypass.