fix(relinker): skip zero-return guest libc exports for internal libc imports #2705
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2705"
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 DariusHQ on 2026-10-10T11:39:59Z.
What
On Windows, a
libSceLibcInternalimport that no native library exports falls back to the title's ownlibc.prx(#1454). Thelibc.prxloader shim that ps5-native-app-boilerplate builds into homebrew titles (#1497) exports 1874 functions at three addresses: 0x30 and 0x40 holdxor eax, eax; ret, and 0x50, where 1872 of them point, holdspxor xmm0, xmm0; xor eax, eax; ret. A missing function then binds to an export that returns 0, and the title starts instead of stopping withunresolved ELF import. The review of #1454 relied on "an absent symbol still fails startup", which does not hold with this shim.The Windows guest module writer now records the exported functions whose code is one of these two sequences (
GuestRuntime::ZeroReturnExports), and the entry stub leaves the guestlibc.prxout of the search for those names. A guest export with code of its own still provides a missinglibSceLibcInternalfunction, as #1454 intended, and native libraries keep their priority. Guest modules' own imports go through the same search, so they are covered too. On Linux the shim intercepts imports through the guest export renaming that #1497 describes and #1529 fixes; this change is Windows only.The problem stayed hidden while a fake-signed
sce_module/libc.prxwas skipped without a message. Since #2605 the module has to be unwrapped, and then these imports bind to the shim on Windows.Homebrew catalog
ps5-homebrew-catalog at
4db487af: 51 release ZIPs downloaded with a matching sha256,eboot.binandsce_module/libc.prxunwrapped from their fSELF containers, relinked with--windows --registryonmainb5f5362d,tools/import_audit.pywith--modulesand the libraries of the same build. 42 titles relink; 7 stop onForbidden syscall instruction(#2136) and 2 ship twoeboot.bin.libc.prxwith code behind its exports.libSceLibcInternalimports thatimport_audit.pyreports as absent: 253 imports in all, for exampleatol,rewindand__isinfin Capy Mobile (PPSA92280) andlocaleconvin SymphonyStation5 (PPSA17641).mainand once with this branch. Each stops in the entry stub before any of its code runs. Onmainthe stop is the first absent import that the shim does not export; with this change it is the first absent import. 20 of the 41 stops change. ProsperoRadio (PPSA99001) stops on its missinglibSceOpusCeltDec.prxeither way, and DOOM (PPSA99666) has no absent import and was not started.main_umtx_op(04AjkP0jO9U)localeconv(0hlfW1O4Aa4)utime(1nTKA7pN1jw)ctime(0uAUs3hYuG4)_fstatfs(17Mfe1B3X6U)nextafterf(3m2ro+Di+Ck)utime(1nTKA7pN1jw)ctime(0uAUs3hYuG4)utime(1nTKA7pN1jw)rewind(3QIPIh-GDjw)dup(iiQjzvfWDq0)__fpclassifyd(qlWiRfOJx1A)utime(1nTKA7pN1jw)atoll(fLcU5G6Qrjs)utime(1nTKA7pN1jw)atoll(fLcU5G6Qrjs)_umtx_op(04AjkP0jO9U)flockfile(hGljHZEfF0U)arc4random_buf(n1KOc0lTUEs)__isinf(V02oFv+-JzA)_umtx_op(04AjkP0jO9U)atol(+my9jdHCMIQ)pthread_set_name_np(oxMp8uPqa+U)atoll(fLcU5G6Qrjs)alarm(DQXJraCc1rA)__isinf(V02oFv+-JzA)sceAudioOutExGetMonitorInfo(PhnNN0UEV6Y)__isinf(V02oFv+-JzA)sceAudioOutExGetMonitorInfo(PhnNN0UEV6Y)__isinf(V02oFv+-JzA)getifaddrs(j-gWL6wDros)localeconv(0hlfW1O4Aa4)dup2(wdUufa9g-D8)llroundf(eQhBFnTOp40)freeifaddrs(N2OjwJJGjeQ)__udivti3(802pFCwC9w0)getifaddrs(j-gWL6wDros)atol(+my9jdHCMIQ)sceAudioOutSysGetHdmiMonitorInfo(Tf9-yOJwF-A)atoll(fLcU5G6Qrjs)19 of these titles are in the Linux table of 2026-10-10 in #1578, and for each of them the new stop is the one listed there.
Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with
BUILD_TESTING=ONonb5f5362d:ctest706/706.windows_import_modulesgets three cases. A guestlibc.prxwhosesharedexport isxor eax, eax; retorpxor xmm0, xmm0; xor eax, eax; ret, with no native provider, must stop withunresolved ELF import shared. With a nativelibSceLibcInternal.prxexport, the native one still wins. Without the entry stub change, both zero-return cases start and exit with 0, the export's return value. A mutant that drops thepxorsequence and one that treats every export as zero-return both fail the test; the second stops the existing guest-only case.tools/check_conventions.py --base upstream/main,tools/check_test_registration.pyandtools/pr_overlap.py --branchpass.Linux and macOS not run here. The new cases execute only on Windows, like the existing ones in
check_internal_guest_libc.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 github-actions[bot] on 2026-10-10T11:40:10Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-10T14:16:02Z.
Independent Windows check of the zero-return libc fallback fix on
Sonic Unleashed Recompiled (PPSA99902), content version 01.003.000.
Replayed head ceae49cd4502d0e087fa50fd2730b62951cf8474 onto its base
b5f5362d3d. Local validation commit:d22ac9d105aab40c3296372facbe22c15ee65a7d.
Windows 11 Enterprise build 26200, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Relevant runtime libraries kept at the baseline for this test.
check_internal_guest_libc. The zero-return fixture reaches the ELF entry point
and exits 0 instead of reporting an unresolved import. With this fix, it passes.
libSceLibcInternal.prx, exit 0xC0000139, before guest entry.
The actual guest libc's flockfile export is at PE RVA 0x10050 with bytes
66 0f ef c0 31 c0 c3 (pxor xmm0,xmm0; xor eax,eax; ret). It shares that code
with nine other native-library-absent imports in this title. All ten symbol names
were checked by hashing them back to the NID. The module has 1874 named exports
matching the zero-return sequences (2566 named exports total).
This confirms the rejection behavior on another title; it does not unblock that
title or establish the semantics of every zero-return function. No guest call to
flockfile was observed: the failure occurs in import resolution.
No full ctest suite, Linux run or gameplay is claimed. AI-assisted investigation.
Follow-up (PPSA99902): a controlled local startup stack now provides an actual executed example of the zero-return fallback problem. The ELF's
getprognameimport (7Psx1DlAyE4) binds to the audited guest shim; the call's null result is cached and then passed tostrcmp("Project-A.exe", nullptr). The instruction/relocation trace and an isolated export call confirm that return. Changing only the runtime libc-internal library to include existing #2218's pointer-returning implementation passed this fault in five runs and reached Vulkan device/swapchain creation; restoring the old library reproduced it. Next stop is an explicit shader-registration refusal. Full evidence and comparison. This uses a conditional local stack, not unchanged main; #2705 itself was not reapplied for this comparison. No rendering/gameplay claim or new PR.Recheck after merge: PPSA99902 current-main relinker (2026-10-11)
Rechecked the merged protection on Windows 11 / RTX 5080 with the relinker source exactly matching pinned main
f60923bf, built in our experimental integrationdff875a7. This uses local/pending runtime prerequisites, not an unmodified-main startup claim.Fresh default conversion of the original PPSA99902 ELF and original guest libc succeeds. Five launches stop before guest entry at
FAIL: unresolved ELF import H-QeERgWuTM from libSceLibcInternal.prx(putc_unlocked), exit0xC0000139, 0.116–0.153 s, no timeout. Export audit of all 122 built system libraries finds no host provider; both prior and fresh guest modules export the NID. The original guest shim's zero-return code was independently checked earlier and its source hash remains unchanged.With exactly the same refreshed libraries but the prior conversion/guest module, the title still reaches the DCC multisample refusal in 31.986 s. This supports the intended protection: the older conversion's graphics progress depended on a fallback that is not a working libc implementation. No guest invocation of
putc_unlockedis observed.Full build/122 libraries; 823 full-suite passes and 5 documented display/no-Vulkan skips; 73 affected/new groups ×5 = 365 passes, no skips. Relinker/import tests are included in the full suite; no local relinker modification. Every replay restores the exact 123-library baseline population, guest module and original input hashes. No rendering/gameplay or console/Linux equivalence claim. Missing unlocked I/O is already discussed on #1578 and closed unmerged #1765; this is current validation, not a new PR or duplicate issue. AI-assisted investigation: Codex.
Source-only routing recheck (2026-10-22)
Checked current main
d6eafa54d0464258574fd2f71889754d05a5bc93without rebuilding, converting or launching a title. The zero-return protection remains in WindowsGuestModuleWriter.cpp and WindowsEntryStubBuilder.cpp: native libc-internal and native libc retain priority, and zero-return exports of the guest libc are excluded from the libc-internal fallback. The existingwindows_import_modulesfixtures still cover host priority and both zero-return shapes; they were inspected, not rerun here.Discovery clarification: the Sonic libc described in this report is a loader shim. Its export names can identify symbols, but the shared return-zero bodies cannot establish their semantics or provide working replacements. An inventory of its exports must retain that qualification.
The apparent
__tls_get_addrgap is separately covered by #9059. Current Windows import binding redirects ordinary guest TLS imports to the generated resolver when no guest resolver provides them; LinuxGuestModuleWriter.cpp redirects them to the host resolver. A static import alone therefore does not establish that this title requires #9059. No new title blocker, runtime result or duplicate issue is claimed. AI-assisted: yes.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:51:51Z.
This conflicted with
mainafterUnmatchedImportModuleswas added toGuestRuntime. Rebased onto currentmainkeeping both fields, no other change.Checked on Linux on the rebased tree (core/relinker build + ctest,
windows_import_modulesand the other relinker/import tests green). The new cases only run on Windows, so they rest on therelinker (windows-latest)job and @Amoenus's independent run.Merging once CI is green on the rebased head.