Repository navigation
fix(relinker): bind SDK guest module imports on Linux - #9261
Conversation
|
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.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
Homebrew built with the ps5-payload-dev SDK names its system libraries with .sprx and imports by symbol name, while the libraries in libs/ are .prx files that export NIDs. On Linux such an executable converted but stopped at load time on the first .sprx dependency and, once that was found, on the first symbol name. The Linux patcher now loads a dependency named with .sprx, .suprx or .debug_prx as the .prx library of the same stem. In an executable that names such a dependency, an import without a module that is named by symbol gets the NID of that name. A name that a bundled module exports still binds to that module. There is no lookup by the name as written, because the host loader also searches the host C library. Other executables keep their unqualified imports as written.
A bundled module that names a console file dependency (.sprx, .suprx, .debug_prx) imports by symbol name, as homebrew built with the ps5-payload-dev SDK does. Bind those imports to the NID of the name, except names another bundled module or the executable exports, and name the module's host dependencies with the .prx library of the same stem.
d9de0a6 to
03fae5d
Compare
|
@wail-arch DefinedNames currently includes every defined DynSym entry, so a local or hidden executable malloc suppresses bundled-module NID binding even though the loader cannot resolve that name externally. Could you restrict executableExports to visible defined GLOBAL/WEAK symbols, excluding LOCAL/INTERNAL/HIDDEN as the existing exported predicate does, and add hidden/local same-name regressions alongside a visible-export control? |
A bundled module's import keeps its name only when the executable exports it as a visible global or weak symbol, as the dynamic loader can bind it. Test local, internal and hidden executable symbols of the same name next to global, weak and protected ones.
|
@oneandonlydean Done in 75212ed: These cases also pass on 03fae5d: |
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 fix(relinker): resolve symbol-name imports through NIDs on Linux #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 fix(relinker): resolve symbol-name imports through NIDs on Linux #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 .. fix(relinker): resolve symbol-name imports through NIDs on Linux #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 fix(relinker): resolve symbol-name imports through NIDs on Linux #9234 already shares with fix(relinker): guard length-changing rewrites around truncated branches #7822.Checklist
main; no other open PR implements the same functions (stacked on fix(relinker): resolve symbol-name imports through NIDs on Linux #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)