feat(relinker): relink needed modules outside the module directories #716

Merged
merwie merged 1 commit from upstream-pr/716 into main 2026-10-07 15:51:48 +00:00
merwie commented 2026-10-05 17:53:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-05T17:53:20Z.


What

Unity titles keep modules the executable needs in Media/Modules, outside sce_module, sce_modules and prx. PPSA12544 (Hollow Knight: Silksong) lists Il2cppUserAssemblies.prx and PS5Util.prx as DT_NEEDED; they were left as host libraries and startup failed with Failed to load module: ...\libs\Il2cppUserAssemblies.prx.

  • After the module directories are scanned, every DT_NEEDED name of the executable that is not among the found modules (and not excluded) is searched for under the input directory, skipping the module directories. An ELF file with that name is relinked like the other guest modules; files with other magic are ignored; two ELF candidates are Ambiguous needed module.
  • Guest outputs keep their directory relative to the input (app0/Media/Modules/Il2cppUserAssemblies.prx.guest.prx) instead of only the last directory component; the Linux DT_NEEDED entries and the printed runtime layout use the same relative path. For modules in sce_module/sce_modules/prx nothing changes.
  • New test guest_needed_modules: an executable needing needed.prx found in Media/Modules (with a non-ELF file of the same name elsewhere) relinks for Linux and Windows, the artifact lands in app0/Media/Modules, the Linux executable needs $ORIGIN/app0/Media/Modules/needed.prx.guest.prx, the Windows executable runs; two candidates fail.

Loading such a module through sceKernelLoadStartModule at run time is a separate pull request.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT.

  • ctest: 289/291 passed, including guest_needed_modules and the existing guest module tests. agc_driver_lds_atomics64 and agc_driver_vopc_compare_table fail on this machine on main as well (Vulkan device tests).
  • PPSA12544: with Media/Modules left in place (no copies in sce_module), both modules are relinked to app0/Media/Modules and startup loads them.

Not tested on Linux.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 in TechnicalDebt
  • 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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4748856626 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/716). Originally posted by [merwie](https://github.com/merwie) on 2026-10-05T17:53:20Z. --- ### What Unity titles keep modules the executable needs in `Media/Modules`, outside `sce_module`, `sce_modules` and `prx`. PPSA12544 (Hollow Knight: Silksong) lists `Il2cppUserAssemblies.prx` and `PS5Util.prx` as `DT_NEEDED`; they were left as host libraries and startup failed with `Failed to load module: ...\libs\Il2cppUserAssemblies.prx`. - After the module directories are scanned, every `DT_NEEDED` name of the executable that is not among the found modules (and not excluded) is searched for under the input directory, skipping the module directories. An ELF file with that name is relinked like the other guest modules; files with other magic are ignored; two ELF candidates are `Ambiguous needed module`. - Guest outputs keep their directory relative to the input (`app0/Media/Modules/Il2cppUserAssemblies.prx.guest.prx`) instead of only the last directory component; the Linux `DT_NEEDED` entries and the printed runtime layout use the same relative path. For modules in `sce_module`/`sce_modules`/`prx` nothing changes. - New test `guest_needed_modules`: an executable needing `needed.prx` found in `Media/Modules` (with a non-ELF file of the same name elsewhere) relinks for Linux and Windows, the artifact lands in `app0/Media/Modules`, the Linux executable needs `$ORIGIN/app0/Media/Modules/needed.prx.guest.prx`, the Windows executable runs; two candidates fail. Loading such a module through `sceKernelLoadStartModule` at run time is a separate pull request. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT. - `ctest`: 289/291 passed, including `guest_needed_modules` and the existing guest module tests. `agc_driver_lds_atomics64` and `agc_driver_vopc_compare_table` fail on this machine on `main` as well (Vulkan device tests). - PPSA12544: with `Media/Modules` left in place (no copies in `sce_module`), both modules are relinked to `app0/Media/Modules` and startup loads them. Not tested on Linux. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
011010 commented 2026-10-06 15:33:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-06T15:33:29Z.


Independent verification, since the branch is relinker-only and builds anywhere.

Built the relinker standalone from pr716 on macOS 26.6.2 (arm64), Apple Clang 21, C++20, and ran the Python integration tests against that binary:

  • test_guest_needed_modules.py passes.
  • The other 18 relinker Python tests in the tree pass.

To confirm the test exercises the new behaviour rather than passing vacuously, I ran the same test against main (5895ea7): it fails with

FileNotFoundError: .../anyps5-needed-modules-.../False-found/app0/Media/Modules/needed.prx.guest.prx

i.e. on main the module outside the module directories is not relinked, which is exactly what this PR fixes. So the branch does what the description claims, and the test is meaningful.

One note: the branch tree is based on an older main and carries 18 of the current 20 Python tests; a rebase would bring it current. GitHub reports it mergeable. I did not test a real Unity title (no dump here).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6019725092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/716#issuecomment-6019725092). Originally posted by [011010](https://github.com/011010) on 2026-10-06T15:33:29Z. --- Independent verification, since the branch is relinker-only and builds anywhere. Built the relinker standalone from `pr716` on macOS 26.6.2 (arm64), Apple Clang 21, C++20, and ran the Python integration tests against that binary: - `test_guest_needed_modules.py` passes. - The other 18 relinker Python tests in the tree pass. To confirm the test exercises the new behaviour rather than passing vacuously, I ran the same test against `main` (`5895ea7`): it fails with ``` FileNotFoundError: .../anyps5-needed-modules-.../False-found/app0/Media/Modules/needed.prx.guest.prx ``` i.e. on `main` the module outside the module directories is not relinked, which is exactly what this PR fixes. So the branch does what the description claims, and the test is meaningful. One note: the branch tree is based on an older `main` and carries 18 of the current 20 Python tests; a rebase would bring it current. GitHub reports it mergeable. I did not test a real Unity title (no dump here).
adriadam10 commented 2026-10-07 15:51:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T15:51:44Z.


Checked on Linux: build + full ctest green with this merged onto current main (398/398), guest_needed_modules fails with the relinker changes reverted, and on a real dump (Astro's Playroom) nothing outside sce_module is picked up. Merging.

Minor follow-up if you touch this again: the DT_NEEDED read loop in GuestModuleBuilder.cpp now exists twice in the same function (the new one and the addHost one); one shared helper would keep the validation in one place.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6041537846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/716#issuecomment-6041537846). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T15:51:44Z. --- Checked on Linux: build + full ctest green with this merged onto current main (398/398), `guest_needed_modules` fails with the relinker changes reverted, and on a real dump (Astro's Playroom) nothing outside `sce_module` is picked up. Merging. Minor follow-up if you touch this again: the `DT_NEEDED` read loop in `GuestModuleBuilder.cpp` now exists twice in the same function (the new one and the `addHost` one); one shared helper would keep the validation in one place.
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!716
No description provided.