fix(relinker): relink the modules that found needed modules need #1782

Closed
MathiasDevelopes wants to merge 1 commit from upstream-pr/1782 into main
MathiasDevelopes commented 2026-10-08 19:06:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-08T19:06:33Z.


What

When the executable needs a module that is not in sce_module, sce_modules or prx, the relinker searches the input tree for it and relinks it. The modules that this found module needs in turn were not looked up. They were left as host libraries, which no host provides, so the title failed to load.

The needed names of every module found this way are now searched for the same way, round by round, until no new module turns up. Each name is searched once, so a dependency cycle ends the search. Names that nothing in the input provides stay host libraries, as before. Ambiguity, exclusion (--exclude-sce-module) and the skipped module directories work as before. Each found module is parsed once, and the parsed image is reused when the modules are relinked.

The scope is kept narrow. Only modules found by this search have their needs followed. Modules in sce_module, sce_modules and prx are unchanged, and their needs resolve as before.

Example: Planet Coaster (PPSA01736) needs libcohtml.Prospero.prx at the package root, and that module needs libChakraCore.prx and libRenoirCore.PS5.prx beside it. Before, only cohtml was relinked; now all three are.

Tested

Windows 11, MinGW-w64 15.2.0. test_guest_needed_modules.py adds two cases, each for both Linux ELF and Windows PE output:

  • A found module needs a second module elsewhere in the tree: both are relinked. The Linux DT_NEEDED order puts the dependency first, and the Windows output runs and returns 42.
  • The second module needs a library the input lacks: it stays a host library in DT_NEEDED.

The first case fails without the fix. The relinker-only build passes its tests (36/36), and so does the full build (476/476). tools/check_conventions.py --base origin/main passes. Converting PPSA01736 now relinks cohtml, ChakraCore and RenoirCore, and the title loads them. Not built or run on Linux or macOS.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none. It touches the same lines as #1617 (module identities for needed names); whichever lands second needs a rebase.
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791549535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1782). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-08T19:06:33Z. --- ### What When the executable needs a module that is not in `sce_module`, `sce_modules` or `prx`, the relinker searches the input tree for it and relinks it. The modules that this found module needs in turn were not looked up. They were left as host libraries, which no host provides, so the title failed to load. The needed names of every module found this way are now searched for the same way, round by round, until no new module turns up. Each name is searched once, so a dependency cycle ends the search. Names that nothing in the input provides stay host libraries, as before. Ambiguity, exclusion (`--exclude-sce-module`) and the skipped module directories work as before. Each found module is parsed once, and the parsed image is reused when the modules are relinked. The scope is kept narrow. Only modules found by this search have their needs followed. Modules in `sce_module`, `sce_modules` and `prx` are unchanged, and their needs resolve as before. Example: Planet Coaster (PPSA01736) needs `libcohtml.Prospero.prx` at the package root, and that module needs `libChakraCore.prx` and `libRenoirCore.PS5.prx` beside it. Before, only cohtml was relinked; now all three are. ### Tested Windows 11, MinGW-w64 15.2.0. `test_guest_needed_modules.py` adds two cases, each for both Linux ELF and Windows PE output: - A found module needs a second module elsewhere in the tree: both are relinked. The Linux DT_NEEDED order puts the dependency first, and the Windows output runs and returns 42. - The second module needs a library the input lacks: it stays a host library in DT_NEEDED. The first case fails without the fix. The relinker-only build passes its tests (36/36), and so does the full build (476/476). `tools/check_conventions.py --base origin/main` passes. Converting PPSA01736 now relinks cohtml, ChakraCore and RenoirCore, and the title loads them. Not built or run on Linux or macOS. ### 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 - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none. It touches the same lines as #1617 (module identities for needed names); whichever lands second needs a rebase. - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-08 19:06:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-08T19:06:39Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5461580238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1782#pullrequestreview-5461580238). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-08T19:06:39Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
oneandonlydean commented 2026-10-10 03:19:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:19:00Z.


This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093232660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1782#issuecomment-6093232660). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:19:00Z. --- This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.
adriadam10 commented 2026-10-10 07:12:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:12:20Z.

Review: CHANGES_REQUESTED


The rebase isn't mechanical: since this PR was opened, #1503/#1830 changed the same block of GuestModuleBuilder.cpp (needed names matched by stem/alias and by module identity, images preloaded into discovered), so both GuestModuleBuilder.cpp and test_guest_needed_modules.py conflict.

Please rebase on current main and carry the round-by-round search over the new logic: the dependencies of each module found this way must go through the same exact/stem/identity matching, each name searched once, and the parsed image still reused when the modules are relinked. Keep both new test cases (transitive, and transitive with a host library), and check they still fail without the fix.

Dean already said it passed testing; once rebased with CI green it can go in.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5478088946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1782#pullrequestreview-5478088946). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:12:20Z. **Review:** CHANGES_REQUESTED --- The rebase isn't mechanical: since this PR was opened, #1503/#1830 changed the same block of `GuestModuleBuilder.cpp` (needed names matched by stem/alias and by module identity, images preloaded into `discovered`), so both `GuestModuleBuilder.cpp` and `test_guest_needed_modules.py` conflict. Please rebase on current `main` and carry the round-by-round search over the new logic: the dependencies of each module found this way must go through the same exact/stem/identity matching, each name searched once, and the parsed image still reused when the modules are relinked. Keep both new test cases (transitive, and transitive with a host library), and check they still fail without the fix. Dean already said it passed testing; once rebased with CI green it can go in.
SCD28 commented 2026-10-10 08:18:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SCD28 on 2026-10-10T08:18:24Z.


Rebuilt the PR changes on current main, preserving the newer exact-name, stem/alias and module-identity resolution already present in GuestModuleBuilder.
The transitive lookup now runs round by round, tracks searched dependency names so cycles terminate, and reuses parsed images already present in discovered. Missing package modules still remain host libraries.
The existing regression coverage now includes:

  • a transitive guest module found under Media/Modules;
  • a transitive dependency that is absent from the package and remains a host library.
    I also verified the regression directly: with only the transitive loop removed, guest_needed_nested_modules fails because libTransitive.prx.guest.prx is not produced. With the fix restored, the same test passes.
    Validation on Linux / WSL2 Ubuntu 24.04:
  • targeted relinker tests: 3/3 pass
  • guest_needed_nested_modules --repeat until-fail:5: 5/5 pass
  • full relinker-only suite: 96/96 pass
  • tools/check_conventions.py --base upstream/main: pass
  • tools/check_test_registration.py: pass
  • git diff --check: pass
    AI-assisted: yes. (Codex)
    Clean branch:
    SCD28/AnyPS5:fix/relinker-transitive-needed-modules
    Feel free to cherry-pick or reuse the branch if useful.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095606699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1782#issuecomment-6095606699). Originally posted by [SCD28](https://github.com/SCD28) on 2026-10-10T08:18:24Z. --- Rebuilt the PR changes on current main, preserving the newer exact-name, stem/alias and module-identity resolution already present in GuestModuleBuilder. The transitive lookup now runs round by round, tracks searched dependency names so cycles terminate, and reuses parsed images already present in discovered. Missing package modules still remain host libraries. The existing regression coverage now includes: - a transitive guest module found under Media/Modules; - a transitive dependency that is absent from the package and remains a host library. I also verified the regression directly: with only the transitive loop removed, guest_needed_nested_modules fails because libTransitive.prx.guest.prx is not produced. With the fix restored, the same test passes. Validation on Linux / WSL2 Ubuntu 24.04: - targeted relinker tests: 3/3 pass - guest_needed_nested_modules --repeat until-fail:5: 5/5 pass - full relinker-only suite: 96/96 pass - tools/check_conventions.py --base upstream/main: pass - tools/check_test_registration.py: pass - git diff --check: pass AI-assisted: yes. (Codex) Clean branch: SCD28/AnyPS5:fix/relinker-transitive-needed-modules Feel free to cherry-pick or reuse the branch if useful.
MathiasDevelopes commented 2026-10-10 09:12:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-10T09:12:23Z.


@oneandonlydean @adriadam10 Rebased onto current main. Since the needed-module search now also matches by stem and module identity, I moved that whole search into a step that reruns on the dependencies of each module it finds, until nothing new turns up. The first pass behaves exactly as on main. The two new tests (transitive, transitive-host) fail on main and pass here, and all relinker tests pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096003825 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1782#issuecomment-6096003825). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-10T09:12:23Z. --- @oneandonlydean @adriadam10 Rebased onto current main. Since the needed-module search now also matches by stem and module identity, I moved that whole search into a step that reruns on the dependencies of each module it finds, until nothing new turns up. The first pass behaves exactly as on main. The two new tests (`transitive`, `transitive-host`) fail on main and pass here, and all relinker tests pass.
MathiasDevelopes commented 2026-10-10 14:06:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-10T14:06:18Z.


Closing this one. 41126bfa removed the search for modules outside sce_module/sce_modules/prx, which is the code this PR extended. Now every module directly in those folders is relinked, so a module's own dependencies are picked up when they sit there too. I checked this on current main: a module in sce_module that needs another one relinks both in the right order, and a dependency nothing provides stays a host library. If a title turns up with modules outside those folders, I'll open a new issue for it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6098315750 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1782#issuecomment-6098315750). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-10T14:06:18Z. --- Closing this one. 41126bfa removed the search for modules outside sce_module/sce_modules/prx, which is the code this PR extended. Now every module directly in those folders is relinked, so a module's own dependencies are picked up when they sit there too. I checked this on current main: a module in sce_module that needs another one relinks both in the right order, and a dependency nothing provides stays a host library. If a title turns up with modules outside those folders, I'll open a new issue for it.

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