fix(relinker): bind SDK guest module imports on Linux #9261
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9261"
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 wail-arch on 2026-10-21T16:52:24Z.
What
Follow-up to #9234, stacked on its head (
be51ab7): the first commit here is #9234's, this PR's change is the last commit (fix(relinker): bind SDK guest module imports on Linux). Once #9234 merges, only that commit remains.#9234 binds the unqualified imports of a ps5-payload-dev SDK executable through NIDs on Linux and leaves bundled modules as they are (its debt entry: "imports of bundled modules, are still bound by name"). An SDK homebrew that ships its own shared objects next to the executable has those built the same way: they name
libkernel_web.sprxandlibSceLibcInternal.sprxand importstrncpy,getpidorsnprintfby name. On Linux, with #9234 alone:DT_NEEDEDkeepslibkernel_web.sprx, becauseGuestModuleBuilderwrites the module beforeLinuxElfPatcherrenames the executable's dependencies, so the loader stops on it (error while loading shared libraries: libkernel_web.sprx);.sprxnames aliased by hand,LD_DEBUG=bindingsshowsstrncpy,getpidandsnprintfbound to the host's/lib/x86_64-linux-gnu/libc.so.6instead oflibs/libc.prxandlibs/libkernel.prx.Changes, Linux output only (Windows and macOS are unchanged):
GuestImageReadermarks, in a module whoseDT_NEEDEDnames a.sprx,.suprxor.debug_prxfile, the undefined symbols named without a#qualifier: the rule #9234 applies to the executable.GuestModuleBuilderrewrites those to the NID of their name after guest linking (BindNamedImportsByNid). A name another bundled module exports keeps its#guestbinding, and a name the executable exports keeps binding by name..prxlibrary of the same stem (Domain::NeededLibraryName, asLinuxElfPatcherdoes for the executable), solibSceLibcInternal.sprxalso addslibc.prxaslibSceLibcInternal.prxalready did. Bundled modules are still found first.Found while testing, not in scope: the SDK's own
hello_sosample, which stops onlibSceLibcInternal.sprxwith #9234 alone, now loads its modules and stops onlibtest.so.guest.prx: undefined symbol: libB_random#guest. The SDK links a shared object's.textat address 0, so its first function is exported withst_value0, and glibc's loader skips such a definition (check_matchinelf/dl-lookup.c). That needs its own change in the guest module writer.Tested
Ubuntu 24.04, GCC 13.3, full build with
-DBUILD_TESTING=ON, onbe51ab7plus this commit.linux_guest_named_imports: a module needinglibkernel_web.sprxgets its named import rewritten to the NID, its qualified import and its guest-exported name (shared#guest) untouched; a module naming no console file is untouched; module dependencieslibSceLibcInternal.sprxandlibkernel_web.sprxbecome.prxwithlibc.prxadded, for the module and the executable; a module's import of a name the executable exports keeps its name. On x86-64 Linux it runs a relinked executable whose module importssharedfromavailable.sprx: a host library exporting the NID provides it (exit 42), one exporting only the name does not (the NID is reported undefined). On #9234 alone it fails at the first module check (['shared#guest', 'BBBBBBBBBBB', 'CCCCCCCCCCC']).a7685ce, clang 18):probe_so.elf(-nostartfiles, its own_start) callsprobe_linefromlibprobe.so, a shared object built with the SDK that callsstrncpy,getpidandsnprintfby name and needslibkernel_web.sprx,libSceLibcInternal.sprxandlibSceNet.sprx. Relinked with--to-intel --module-dir .. #9234 alone: exit 127,libkernel_web.sprx: cannot open shared object file, the module'sDT_NEEDEDstill naminglibkernel_web.sprx,libSceLibcInternal.sprxandlibSceNet.sprx; with those aliased inlibs/, it prints its line, its three imports bound in the hostlibc.so.6. This branch: printsmodule imports resolved, pid validand exits 9;LD_DEBUG=bindingsshows the module's6sJWiWSRuqk(strncpy) andeLdDw6l0-bU(snprintf) bound inlibs/libc.prxandHoLVWNanBBc(getpid) inlibs/libkernel.prx.ctest -j4: 1801 of 1808 pass,linux_named_imports,loadexec_argumentsand the new test among them. The 7 failures fail the same way without this change in this container:net_dontwait_blocking_send,_sendtoand_sendmsg(the sandbox's network stack never fills the send buffer),guest_socket_stream_options,guest_socket_address_lengthandguest_tcp(no IPv6:errno 47),guest_named_shm_concurrency(tests run as root). No GPU, so the Vulkan tests were skipped. Windows and macOS were not run; their output paths are unchanged.check_conventions.py --base upstream/mainpasses. Merged into currentmain(606297f), the branch adds no conflict with open pull requests beyond the debt line #9234 already shares with #7822.Checklist
main; no other open PR implements the same functions (stacked on #9234, which merges cleanly into currentmain)NotImplemented_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)