fix(relinker): reject a needed module name that several bundled modules match only by extension #11479

Merged
roboterspinne merged 3 commits from upstream-pr/11479 into main 2026-11-02 10:28:35 +00:00
roboterspinne commented 2026-10-26 16:29:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-26T16:29:31Z.


What

A needed name with no exact filename match (on Windows, no case-folded match) is aliased to a bundled module whose name differs only in its .prx, .sprx, .suprx or .debug_prx extension (1a9ef2f25d; .suprx since 0a324d8ccb), and when two discovered modules share that stem, std::find_if in GuestModuleBuilder::Build takes the first module in the order they are passed in (the CLI sorts them by path) without checking for a second. On untouched 4017310678 with --module-dir Media, Media/needed.prx and Media/needed.sprx and an executable needing needed.debug_prx converted with exit 0 and the Linux executable's DT_NEEDED named only $ORIGIN/app0/Media/needed.prx.guest.prx; with Media/needed.sprx and Media/needed.suprx and needed.prx it named only needed.sprx.guest.prx, so the started module followed byte order of the paths. 1a9ef2f25d's message calls two candidates for one needed name ambiguous, but only the recursive outside-directory search threw Ambiguous needed module, and 41126bfa5b removed it; the other resolution paths in Build reject ambiguity (Ambiguous guest dependency name, Ambiguous guest module identity).

  • Rule. Next to neededAliases, Build records a second module with the same ModuleStem (Windows folding as before) for each aliased name. In the alias loop, after the existing if (guestNames.contains(name)) continue;, it throws Ambiguous needed module: <name> (<first path> and <second path>); the CLI exits 2 and writes no output. A module whose filename or SONAME equals the needed name still claims it, a single stem match is still aliased, and guest-module dependencies, which never use the stem alias, are unchanged. The rule covers every scanned module directory (sce_module, sce_modules, prx and --module-dir) and the modules the online converter passes.
  • Tests. test_guest_needed_modules.py gets two cases for Linux and --windows, after debug-name-ambiguous (whose first/ is not a module directory and is unchanged): sce_module/needed.prx with sce_module/needed.sprx carrying SONAME needed.debug_prx must still convert, and the same pair without the SONAME, needing needed.debug_prx, must exit 2 with the message and no output.
  • Overlap. pr_overlap.py reports no shared lines with open pull requests that merge with main. It cannot compare this branch with #10861 (GuestModuleBuilder.cpp), because that pull request does not merge with main. Checked by hand: #10861 changes only the syscall scan of the code segments in Build (lines 403 to 433 on main, 412 to 442 here), not the neededAliases lookup and alias loop that this PR changes (lines 112 to 180 here, 112 to 171 on main). A trial merge of this branch with #10861 conflicts in the same three files and regions as main with #10861 (GuestModuleBuilder.cpp, RelinkerPipeline.cpp and docs/dev/debt/relinker.md). In GuestModuleBuilder.cpp both conflicts are in the unwind range setup and the masked syscall scan that #8076 added (lines 404 to 408 and 414 to 423 on main, 413 to 417 and 423 to 432 here). Apart from the conflict labels, the conflicted GuestModuleBuilder.cpp of the two trial merges differs only in the lines of this PR, which merge cleanly, and the other two conflicted files are identical. #10997 also edits GuestModuleBuilder.cpp; it merges with this branch without conflict and appends RemoveBackupCopies after Build (which ends at line 499 here), far from those lines.

Tested

Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew.

  • Counter-check: guest_needed_modules with the new cases on untouched 4017310678 fails at the Linux same-stem case with AssertionError: (<stdout>, ''), return code 0 and output written, after the SONAME control passed. Run directly with the same inputs, untouched Linux and --windows both exit 0 for both cases; the untouched Windows program runs and exits 42. With the change the same-stem case exits 2 for both targets with no output, the SONAME case still exits 0 and its Windows program exits 42, and the two --module-dir Media inputs above exit 2, as does sce_module/needed.prx with Media/needed.sprx under --module-dir Media for both targets (untouched: exit 0, Linux DT_NEEDED lists both). With the change guest_needed_modules passed in 3.5 s on 3a2c51afd2, which has no relinker changes since 4017310678.
  • Merged current main (265f77bf99) into the branch without conflicts (ab4eb259b6; the earlier merge of 518d36eaec is f15e9852d1); since 3a2c51afd2 main changed both files of this PR (#8076, #10607, #9513, #10732), none of them in lines of this PR, and neither file since 518d36eaec; tools/check_main_sync.py --base upstream/main reports 0 behind and a clean merge at 265f77bf99. On ab4eb259b6, ctest -R 'guest_module_directories|needed|guest_|module' -j 6 (run next to a second build): 34 tests passed, among them guest_needed_modules (5.4 s), guest_module_dir (8.0 s), guest_module_directories (3.3 s), guest_module_identity (8.7 s), guest_needed_nested_modules (5.0 s), guest_deferred_dependencies (1.3 s), guest_runpath (3.3 s) and linux_guest_named_imports (1.1 s).
  • Full suite on ab4eb259b6: ctest --test-dir build-relinker -j 6: 309 tests, 306 passed, long_paths skipped; failures known on this machine on main as well: select_tests (Windows symlink fixture) and patch_advisor_unit (path with spaces, which open #10667 fixes); both failed again alone.
  • python tools/check_conventions.py --base upstream/main with this title and description passed on ab4eb259b6.
  • Not tested on Linux or macOS; CI runs the tests on all three hosts.

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 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5020981843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11479). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-26T16:29:31Z. --- ### What A needed name with no exact filename match (on Windows, no case-folded match) is aliased to a bundled module whose name differs only in its `.prx`, `.sprx`, `.suprx` or `.debug_prx` extension (1a9ef2f25d; `.suprx` since 0a324d8ccb), and when two discovered modules share that stem, `std::find_if` in `GuestModuleBuilder::Build` takes the first module in the order they are passed in (the CLI sorts them by path) without checking for a second. On untouched 4017310678 with `--module-dir Media`, `Media/needed.prx` and `Media/needed.sprx` and an executable needing `needed.debug_prx` converted with exit 0 and the Linux executable's `DT_NEEDED` named only `$ORIGIN/app0/Media/needed.prx.guest.prx`; with `Media/needed.sprx` and `Media/needed.suprx` and `needed.prx` it named only `needed.sprx.guest.prx`, so the started module followed byte order of the paths. 1a9ef2f25d's message calls two candidates for one needed name ambiguous, but only the recursive outside-directory search threw `Ambiguous needed module`, and 41126bfa5b removed it; the other resolution paths in `Build` reject ambiguity (`Ambiguous guest dependency name`, `Ambiguous guest module identity`). - **Rule.** Next to `neededAliases`, `Build` records a second module with the same `ModuleStem` (Windows folding as before) for each aliased name. In the alias loop, after the existing `if (guestNames.contains(name)) continue;`, it throws `Ambiguous needed module: <name> (<first path> and <second path>)`; the CLI exits 2 and writes no output. A module whose filename or SONAME equals the needed name still claims it, a single stem match is still aliased, and guest-module dependencies, which never use the stem alias, are unchanged. The rule covers every scanned module directory (`sce_module`, `sce_modules`, `prx` and `--module-dir`) and the modules the online converter passes. - **Tests.** `test_guest_needed_modules.py` gets two cases for Linux and `--windows`, after `debug-name-ambiguous` (whose `first/` is not a module directory and is unchanged): `sce_module/needed.prx` with `sce_module/needed.sprx` carrying SONAME `needed.debug_prx` must still convert, and the same pair without the SONAME, needing `needed.debug_prx`, must exit 2 with the message and no output. - **Overlap.** `pr_overlap.py` reports no shared lines with open pull requests that merge with `main`. It cannot compare this branch with #10861 (`GuestModuleBuilder.cpp`), because that pull request does not merge with `main`. Checked by hand: #10861 changes only the syscall scan of the code segments in `Build` (lines 403 to 433 on `main`, 412 to 442 here), not the `neededAliases` lookup and alias loop that this PR changes (lines 112 to 180 here, 112 to 171 on `main`). A trial merge of this branch with #10861 conflicts in the same three files and regions as `main` with #10861 (`GuestModuleBuilder.cpp`, `RelinkerPipeline.cpp` and `docs/dev/debt/relinker.md`). In `GuestModuleBuilder.cpp` both conflicts are in the unwind range setup and the masked syscall scan that #8076 added (lines 404 to 408 and 414 to 423 on `main`, 413 to 417 and 423 to 432 here). Apart from the conflict labels, the conflicted `GuestModuleBuilder.cpp` of the two trial merges differs only in the lines of this PR, which merge cleanly, and the other two conflicted files are identical. #10997 also edits `GuestModuleBuilder.cpp`; it merges with this branch without conflict and appends `RemoveBackupCopies` after `Build` (which ends at line 499 here), far from those lines. ### 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. --> Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`); synthetic fixtures only, no title or homebrew. - Counter-check: `guest_needed_modules` with the new cases on untouched 4017310678 fails at the Linux same-stem case with `AssertionError: (<stdout>, '')`, return code 0 and output written, after the SONAME control passed. Run directly with the same inputs, untouched Linux and `--windows` both exit 0 for both cases; the untouched Windows program runs and exits 42. With the change the same-stem case exits 2 for both targets with no output, the SONAME case still exits 0 and its Windows program exits 42, and the two `--module-dir Media` inputs above exit 2, as does `sce_module/needed.prx` with `Media/needed.sprx` under `--module-dir Media` for both targets (untouched: exit 0, Linux `DT_NEEDED` lists both). With the change `guest_needed_modules` passed in 3.5 s on 3a2c51afd2, which has no relinker changes since 4017310678. - Merged current `main` (265f77bf99) into the branch without conflicts (ab4eb259b6; the earlier merge of 518d36eaec is f15e9852d1); since 3a2c51afd2 `main` changed both files of this PR (#8076, #10607, #9513, #10732), none of them in lines of this PR, and neither file since 518d36eaec; `tools/check_main_sync.py --base upstream/main` reports 0 behind and a clean merge at 265f77bf99. On ab4eb259b6, `ctest -R 'guest_module_directories|needed|guest_|module' -j 6` (run next to a second build): 34 tests passed, among them `guest_needed_modules` (5.4 s), `guest_module_dir` (8.0 s), `guest_module_directories` (3.3 s), `guest_module_identity` (8.7 s), `guest_needed_nested_modules` (5.0 s), `guest_deferred_dependencies` (1.3 s), `guest_runpath` (3.3 s) and `linux_guest_named_imports` (1.1 s). - Full suite on ab4eb259b6: `ctest --test-dir build-relinker -j 6`: 309 tests, 306 passed, `long_paths` skipped; failures known on this machine on `main` as well: `select_tests` (Windows symlink fixture) and `patch_advisor_unit` (path with spaces, which open #10667 fixes); both failed again alone. - `python tools/check_conventions.py --base upstream/main` with this title and description passed on ab4eb259b6. - Not tested on Linux or macOS; CI runs the tests on all three hosts. ### 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 - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-26 16:46:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T16:46:58Z.

Review: CHANGES_REQUESTED


The Linux, Windows, macOS arm64/x86_64 and relinker ASan checks pass, and the current merge preview is clean. The branch is now 80 commits behind current main, though, and the repository requires pull request branches to stay up to date. Please rebase onto current main and rerun the checks; I’ll recheck the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5655731170 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11479#pullrequestreview-5655731170). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T16:46:58Z. **Review:** CHANGES_REQUESTED --- The Linux, Windows, macOS arm64/x86_64 and relinker ASan checks pass, and the current merge preview is clean. The branch is now 80 commits behind current main, though, and the repository requires pull request branches to stay up to date. Please rebase onto current main and rerun the checks; I’ll recheck the updated head.
THEMANnt commented 2026-10-26 16:52:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T16:52:12Z.

Review: APPROVED


Reviewed f15e9852d169 against 427dd36164bb. No actionable findings.

The alias path records a second same-stem module and rejects an unresolved needed-name alias instead of choosing by path order. Exact filename and SONAME matches still claim the request, while guest-module dependencies remain unchanged. This prevents order-dependent aliasing while retaining single suffix matches.

Validation: Hosted relinker CTests passed on the pinned head: Windows 309, Ubuntu 313, and both macOS jobs 303 each; ASan’s 34 TLS-coverage tests passed. Full-product Windows/Linux jobs were skipped. Locally, the current-main-plus-patch relinker and test targets built with GCC 15.3; the focused 34-test selection passed with filesystem access for the unrelated hard-link fixture. A 12-run review-only sweep covered four suffix/directory ambiguity paths in Linux and Windows modes, reversed creation order, exact filename claims, input preservation, and no output on rejection. Unpatched main accepted the ambiguous fixture and wrote output.

The local tree lacked the pinned PR objects; relevant patch and fixture paths were unchanged across its 190-commit gap, but local execution is not the exact PR head. Hosted jobs tested exact head f15e9852d169.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5655803024 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11479#pullrequestreview-5655803024). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T16:52:12Z. **Review:** APPROVED --- Reviewed `f15e9852d169` against `427dd36164bb`. No actionable findings. The alias path records a second same-stem module and rejects an unresolved needed-name alias instead of choosing by path order. Exact filename and SONAME matches still claim the request, while guest-module dependencies remain unchanged. This prevents order-dependent aliasing while retaining single suffix matches. **Validation:** Hosted relinker CTests passed on the pinned head: Windows 309, Ubuntu 313, and both macOS jobs 303 each; ASan’s 34 TLS-coverage tests passed. Full-product Windows/Linux jobs were skipped. Locally, the current-main-plus-patch relinker and test targets built with GCC 15.3; the focused 34-test selection passed with filesystem access for the unrelated hard-link fixture. A 12-run review-only sweep covered four suffix/directory ambiguity paths in Linux and Windows modes, reversed creation order, exact filename claims, input preservation, and no output on rejection. Unpatched main accepted the ambiguous fixture and wrote output. The local tree lacked the pinned PR objects; relevant patch and fixture paths were unchanged across its 190-commit gap, but local execution is not the exact PR head. Hosted jobs tested exact head `f15e9852d169`.
MarcZX10 commented 2026-10-28 22:07:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T22:07:16Z.

Review: APPROVED


Reviewing exact head ab4eb259b6da3aaeff8f6d671322b24226d88394.

What I ran

  • Inspected the exact production and test changes, overlap report, review discussion, and current hosted checks.
  • The branch's last synced base is 265f77bf99; current main has not changed GuestModuleBuilder.cpp or test_guest_needed_modules.py since that sync.
  • Hosted relinker checks pass on macOS arm64/x86_64, Linux, and Windows; ASan, conventions, labels, and eligibility pass.
  • I did not run a local build or tests.

Results

Check Result Evidence
Ambiguous suffix alias behavior Reviewed Exact PR diff
Focused regression and adjacent guest-module tests Pass, author-reported 34/34 on synced head; independent macOS focused and full suite pass
Hosted relinker platform matrix Pass macOS arm64/x86_64, Linux, Windows
Hosted ASan and policy checks Pass GitHub Actions
Local build and CTest Not run This review

Findings

Blocking

None.

Non-blocking

  • The resolver now collects all matching suffix stems, but only rejects ambiguity after exact filename/SONAME matches have had a chance to claim the needed name. Single suffix matches and exact SONAME matches are covered, along with ambiguous matches on Linux and Windows. This removes the prior path-order-dependent choice.
  • #10861 overlaps in GuestModuleBuilder.cpp and has broader merge conflicts. The PR discussion manually reconciles the changed regions; retain both the TLS scan changes and this alias resolution when merging.

Sources

Not verified

  • I did not run the relinker build or CTest locally; the author and independent reviewer reports plus hosted jobs provide the test evidence.

To get this to a good state

No blocking issue remains in the reviewed head. Preserve both PRs' changes when resolving the #10861 overlap.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5690331166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11479#pullrequestreview-5690331166). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T22:07:16Z. **Review:** APPROVED --- Reviewing exact head `ab4eb259b6da3aaeff8f6d671322b24226d88394`. ## What I ran - Inspected the exact production and test changes, overlap report, review discussion, and current hosted checks. - The branch's last synced base is `265f77bf99`; current main has not changed `GuestModuleBuilder.cpp` or `test_guest_needed_modules.py` since that sync. - Hosted relinker checks pass on macOS arm64/x86_64, Linux, and Windows; ASan, conventions, labels, and eligibility pass. - I did not run a local build or tests. ## Results | Check | Result | Evidence | |---|---|---| | Ambiguous suffix alias behavior | Reviewed | Exact PR diff | | Focused regression and adjacent guest-module tests | Pass, author-reported | 34/34 on synced head; independent macOS focused and full suite pass | | Hosted relinker platform matrix | Pass | macOS arm64/x86_64, Linux, Windows | | Hosted ASan and policy checks | Pass | GitHub Actions | | Local build and CTest | Not run | This review | ## Findings ### Blocking None. ### Non-blocking - The resolver now collects all matching suffix stems, but only rejects ambiguity after exact filename/SONAME matches have had a chance to claim the needed name. Single suffix matches and exact SONAME matches are covered, along with ambiguous matches on Linux and Windows. This removes the prior path-order-dependent choice. - #10861 overlaps in `GuestModuleBuilder.cpp` and has broader merge conflicts. The PR discussion manually reconciles the changed regions; retain both the TLS scan changes and this alias resolution when merging. ## Sources - [Repository relinker build and test rules](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/BUILD.md) - [Current pull request and focused test evidence](https://github.com/boykopovar/AnyPS5/pull/11479) ## Not verified - I did not run the relinker build or CTest locally; the author and independent reviewer reports plus hosted jobs provide the test evidence. ## To get this to a good state No blocking issue remains in the reviewed head. Preserve both PRs' changes when resolving the #10861 overlap.
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!11479
No description provided.