Skip to content

fix(relinker): bind SDK guest module imports on Linux - #9261

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
wail-arch:fix/linux-sdk-homebrew-imports
Oct 24, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
wail-arch:fix/linux-sdk-homebrew-imports

Conversation

@wail-arch

@wail-arch wail-arch commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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.sprx and libSceLibcInternal.sprx and import strncpy, getpid or snprintf by name. On Linux, with #9234 alone:

  • the module's DT_NEEDED keeps libkernel_web.sprx, because GuestModuleBuilder writes the module before LinuxElfPatcher renames the executable's dependencies, so the loader stops on it (error while loading shared libraries: libkernel_web.sprx);
  • the module's named imports are left as written: with the .sprx names aliased by hand, LD_DEBUG=bindings shows strncpy, getpid and snprintf bound to the host's /lib/x86_64-linux-gnu/libc.so.6 instead of libs/libc.prx and libs/libkernel.prx.

Changes, Linux output only (Windows and macOS are unchanged):

  • GuestImageReader marks, in a module whose DT_NEEDED names a .sprx, .suprx or .debug_prx file, the undefined symbols named without a # qualifier: the rule fix(relinker): resolve symbol-name imports through NIDs on Linux #9234 applies to the executable.
  • GuestModuleBuilder rewrites those to the NID of their name after guest linking (BindNamedImportsByNid). A name another bundled module exports keeps its #guest binding, and a name the executable exports keeps binding by name.
  • Host dependencies of bundled modules, and the executable's host list the guest builder writes, use the .prx library of the same stem (Domain::NeededLibraryName, as LinuxElfPatcher does for the executable), so libSceLibcInternal.sprx also adds libc.prx as libSceLibcInternal.prx already did. Bundled modules are still found first.
  • The fix(relinker): resolve symbol-name imports through NIDs on Linux #9234 debt entry now covers bundled modules.

Found while testing, not in scope: the SDK's own hello_so sample, which stops on libSceLibcInternal.sprx with #9234 alone, now loads its modules and stops on libtest.so.guest.prx: undefined symbol: libB_random#guest. The SDK links a shared object's .text at address 0, so its first function is exported with st_value 0, and glibc's loader skips such a definition (check_match in elf/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, on be51ab7 plus this commit.

  • New linux_guest_named_imports: a module needing libkernel_web.sprx gets 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 dependencies libSceLibcInternal.sprx and libkernel_web.sprx become .prx with libc.prx added, 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 imports shared from available.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']).
  • Homebrew built with the SDK (a7685ce, clang 18): probe_so.elf (-nostartfiles, its own _start) calls probe_line from libprobe.so, a shared object built with the SDK that calls strncpy, getpid and snprintf by name and needs libkernel_web.sprx, libSceLibcInternal.sprx and libSceNet.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's DT_NEEDED still naming libkernel_web.sprx, libSceLibcInternal.sprx and libSceNet.sprx; with those aliased in libs/, it prints its line, its three imports bound in the host libc.so.6. This branch: prints module imports resolved, pid valid and exits 9; LD_DEBUG=bindings shows the module's 6sJWiWSRuqk (strncpy) and eLdDw6l0-bU (snprintf) bound in libs/libc.prx and HoLVWNanBBc (getpid) in libs/libkernel.prx.
  • Full ctest -j4: 1801 of 1808 pass, linux_named_imports, loadexec_arguments and the new test among them. The 7 failures fail the same way without this change in this container: net_dontwait_blocking_send, _sendto and _sendmsg (the sandbox's network stack never fills the send buffer), guest_socket_stream_options, guest_socket_address_length and guest_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/main passes. Merged into current main (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

@github-actions github-actions Bot added the fix error Closes an issue (Fixes #N) label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7822 docs/dev/debt/relinker.md L17-18

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.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 6044 core/relinker/CMakeLists.txt
PR 7918 docs/dev/debt/relinker.md
PR 8076 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
PR 9408 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md

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.
@wail-arch
wail-arch force-pushed the fix/linux-sdk-homebrew-imports branch from d9de0a6 to 03fae5d Compare October 21, 2026 18:08
@wail-arch wail-arch changed the title fix(relinker): resolve SDK homebrew dependencies and named imports on Linux fix(relinker): bind SDK guest module imports on Linux Oct 21, 2026
@github-actions github-actions Bot added build relinker docs and removed fix error Closes an issue (Fixes #N) labels Oct 21, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@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.
@wail-arch

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Done in 75212ed: ExportedNames now keeps only defined GLOBAL or WEAK symbols that are not INTERNAL or HIDDEN, with the same test RelinkerPipeline applies when it copies the executable's symbols (st_other & 3). test_linux_guest_named_imports.py relinks the same module against an executable whose FixtureExport is global, weak or protected (the import keeps its name) and internal, hidden or local (the import gets its NID).

These cases also pass on 03fae5d: RelinkerPipeline already leaves local, internal and hidden symbols out of the executable's dynamic symbol table (the DT_OS_SYMTABSZ loop), so DefinedNames never saw them. The predicate now holds on its own instead of relying on that filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants