fix(relinker): keep the host libc.prx loadable when a title bundles its own #480

Closed
carrosio wants to merge 1 commit from upstream-pr/480 into main
carrosio commented 2026-10-03 20:41:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by carrosio on 2026-10-03T20:41:14Z.


Refs #476 (Problems 1 and 2; the optional DT_RUNPATH=$ORIGIN hardening is not included).

Cause

GuestModuleBuilder::addHost skips any host dependency whose name matches a bundled guest module, so on Linux a title that ships sce_module/libc.prx ends up without the host libc.prx in DT_NEEDED. The host PRX libraries still need it, and a DT_RUNPATH does not apply to a dependency's own dependencies, so the loader fails with libc.prx: cannot open shared object file. The guest copy cannot stand in for it: its DT_SONAME is libc.prx.guest.prx.

Changes

  • GuestModuleBuilder.cpp: on Linux, when a guest libc.prx exists and the executable imports libSceLibcInternal.prx, append the host libc.prx as the last DT_NEEDED. This is the same condition WindowsImportBuilder already uses.
  • core/libs/CMakeLists.txt: link the host libc.prx with -Wl,-Bsymbolic on Linux, so a bundled libc (same NIDs, loaded first) cannot take over the host libc's own references.
  • test_guest_libc.py (guest_libc): relinks an executable importing libkernel.prx and libSceLibcInternal.prx with and without a bundled libc.prx and checks the output DT_NEEDED.

Testing

Linux x86-64, GCC 13.3, Ninja, Release; built only the relinker and libc targets.

  • guest_libc fails without the GuestModuleBuilder.cpp change (['$ORIGIN/app0/sce_module/libc.prx.guest.prx', 'libkernel.prx', 'libSceLibcInternal.prx']) and passes with it.
  • The other 10 relinker Python tests pass (11/11 in total).
  • readelf -d shows SYMBOLIC on the host libc.prx before NID patching.

Not verified

  • I have no title that bundles libc.prx, so the loader fix and the -Bsymbolic fix were not exercised end to end. The -Bsymbolic effect rests on the result reported in #476, and I have not checked that nothing in libc relies on interposing its own exports.
  • The NID-patched libc.prx was not inspected for the flag.
  • The three C++ relinker tests (buffer_bounds, amd64_only_converter, strict_nid_filter) and the rest of the suite were not run.

AI disclosure

Written with Claude (Claude Code); I reviewed and am responsible for every line.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4729537904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/480). Originally posted by [carrosio](https://github.com/carrosio) on 2026-10-03T20:41:14Z. --- Refs #476 (Problems 1 and 2; the optional `DT_RUNPATH=$ORIGIN` hardening is not included). ## Cause `GuestModuleBuilder::addHost` skips any host dependency whose name matches a bundled guest module, so on Linux a title that ships `sce_module/libc.prx` ends up without the host `libc.prx` in `DT_NEEDED`. The host PRX libraries still need it, and a `DT_RUNPATH` does not apply to a dependency's own dependencies, so the loader fails with `libc.prx: cannot open shared object file`. The guest copy cannot stand in for it: its `DT_SONAME` is `libc.prx.guest.prx`. ## Changes - `GuestModuleBuilder.cpp`: on Linux, when a guest `libc.prx` exists and the executable imports `libSceLibcInternal.prx`, append the host `libc.prx` as the last `DT_NEEDED`. This is the same condition `WindowsImportBuilder` already uses. - `core/libs/CMakeLists.txt`: link the host `libc.prx` with `-Wl,-Bsymbolic` on Linux, so a bundled libc (same NIDs, loaded first) cannot take over the host libc's own references. - `test_guest_libc.py` (`guest_libc`): relinks an executable importing `libkernel.prx` and `libSceLibcInternal.prx` with and without a bundled `libc.prx` and checks the output `DT_NEEDED`. ## Testing Linux x86-64, GCC 13.3, Ninja, Release; built only the `relinker` and `libc` targets. - `guest_libc` fails without the `GuestModuleBuilder.cpp` change (`['$ORIGIN/app0/sce_module/libc.prx.guest.prx', 'libkernel.prx', 'libSceLibcInternal.prx']`) and passes with it. - The other 10 relinker Python tests pass (11/11 in total). - `readelf -d` shows `SYMBOLIC` on the host `libc.prx` before NID patching. ## Not verified - I have no title that bundles `libc.prx`, so the loader fix and the `-Bsymbolic` fix were not exercised end to end. The `-Bsymbolic` effect rests on the result reported in #476, and I have not checked that nothing in libc relies on interposing its own exports. - The NID-patched `libc.prx` was not inspected for the flag. - The three C++ relinker tests (`buffer_bounds`, `amd64_only_converter`, `strict_nid_filter`) and the rest of the suite were not run. ## AI disclosure Written with Claude (Claude Code); I reviewed and am responsible for every line. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
carrosio commented 2026-10-03 20:43:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by carrosio on 2026-10-03T20:43:13Z.


Closing, sorry for the noise.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5973303939 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/480#issuecomment-5973303939). Originally posted by [carrosio](https://github.com/carrosio) on 2026-10-03T20:43:13Z. --- Closing, sorry for the noise.

Pull request closed

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!480
No description provided.