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

Merged
wail-arch merged 3 commits from upstream-pr/9261 into main 2026-10-24 04:11:50 +00:00
wail-arch commented 2026-10-21 16:52:24 +00:00 (Migrated from github.com)

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.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 #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 #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 #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 .. #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 #9234 already shares with #7822.

Checklist

  • Based on current main; no other open PR implements the same functions (stacked on #9234, which merges cleanly into current main)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #9234
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955201137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9261). Originally posted by [wail-arch](https://github.com/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](https://github.com/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 #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 #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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> 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 #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 .`. #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 #9234 already shares with #7822. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions (stacked on #9234, which merges cleanly into current `main`) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #9234 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9261
No description provided.