fix(relinker): retain qualified Linux guest import providers #15942

Merged
nikhilpanchal1 merged 4 commits from upstream-pr/15942 into main 2026-11-12 21:53:24 +00:00
nikhilpanchal1 commented 2026-11-05 01:57:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikhilpanchal1 on 2026-11-05T01:57:11Z.


What

A Linux executable or guest module could explicitly import from module B but bind to module A when both exported the same name. The converter selected B for its dependency graph, then gave both exports the same lookup name. Qualified executable imports could also be rejected as ambiguous.

Bind qualified imports through deterministic provider-specific aliases. Keep generic exports for dlsym, preserve symbol metadata and zero-address thunk identity, and retain compatibility with ordinary STT_NOTYPE definitions. Actual type/TLS mismatches still reject.

Related to #5927. Undeclared-import ambiguity policy and existing macOS behavior remain unchanged.

Tested

Debian 13 x86-64, GCC 14.2, Python 3.12.14, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON. Base: acac7c854182; reviewed head: ccbfff364c.

  • Build and all 49 focused tests pass. Full suite: 708/709; clean upstream: 707/708. Both fail only the unchanged title_run child-process cleanup test.
  • Native fixtures cover functions, objects, weak/protected symbols, TLS, zero-address exports, self imports, module identities, dependency graphs, multiple executables and deterministic API input permutations. Baseline selects 11 instead of the requested 22; the fix selects 22. Two-provider execution returns the order-sensitive 132, and swapped relocation bindings fail the test.
  • Successful Windows/macOS conversion probes are byte-identical to baseline. Native Windows/macOS execution, console measurements and real titles were not tested; macOS limitations are recorded in technical debt.
  • Conventions and whitespace pass. The overlap scan checked 1,881 PR heads; base-conflicted peers were reviewed manually. Merge probes introduce no new conflicting files, and no duplicate implementation was found.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5164751132 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15942). Originally posted by [nikhilpanchal1](https://github.com/nikhilpanchal1) on 2026-11-05T01:57:11Z. --- ### What A Linux executable or guest module could explicitly import from module B but bind to module A when both exported the same name. The converter selected B for its dependency graph, then gave both exports the same lookup name. Qualified executable imports could also be rejected as ambiguous. Bind qualified imports through deterministic provider-specific aliases. Keep generic exports for `dlsym`, preserve symbol metadata and zero-address thunk identity, and retain compatibility with ordinary `STT_NOTYPE` definitions. Actual type/TLS mismatches still reject. Related to #5927. Undeclared-import ambiguity policy and existing macOS behavior remain unchanged. ### Tested Debian 13 x86-64, GCC 14.2, Python 3.12.14, Release, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`. Base: `acac7c854182`; reviewed head: `ccbfff364c`. - Build and all 49 focused tests pass. Full suite: 708/709; clean upstream: 707/708. Both fail only the unchanged `title_run` child-process cleanup test. - Native fixtures cover functions, objects, weak/protected symbols, TLS, zero-address exports, self imports, module identities, dependency graphs, multiple executables and deterministic API input permutations. Baseline selects 11 instead of the requested 22; the fix selects 22. Two-provider execution returns the order-sensitive 132, and swapped relocation bindings fail the test. - Successful Windows/macOS conversion probes are byte-identical to baseline. Native Windows/macOS execution, console measurements and real titles were not tested; macOS limitations are recorded in technical debt. - Conventions and whitespace pass. The overlap scan checked 1,881 PR heads; base-conflicted peers were reviewed manually. Merge probes introduce no new conflicting files, and no duplicate implementation was found. <!-- 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. --> ### 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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
gabichuuuuu commented 2026-11-07 00:52:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T00:52:32Z.

Review: COMMENTED


Tested on Windows 11 x64 with WinLibs GCC 15.2.0 15.2.0posix-14.0.0-ucrt-r7 (as in CI), its CMake 4.3.1 and Ninja 1.13.2, and Python 3.15.0. Relinker-only Release build, head 433570f4 merged into main 9ade3ed8.

  • Full ctest --timeout 120 --parallel 4: 794 tests. Nine timed out in that run while the machine was under other load, and all nine passed when rerun alone, both on this head and on main. main alone passed 793/793.
  • This PR's test_linux_guest_qualified_imports.py fails against the main relinker at assert len(aliases) == 1 ({'shared#guest': (18, 0, 1, 4096, 6)}) and passes with this PR.

Interaction with #16384. #16384 also accepts, on Linux, identical ordinary function exports that share a stripped name. Linux conversion built with the guest_symbols and convert helpers of test_guest_export_lookup.py, with a.prx exporting entry#A#A and entry#B#A (both 0x12, same address):

Relinker b.prx exports entry b.prx exports other
main, and this PR alone Duplicate or empty export after stripping #: entry same
#16384 alone converts converts
this PR + #16384 Duplicate or empty guest binding alias: entry#module0#guest converts

Both copies of entry in a.prx are exported and entry is in sharedExports, so the new BindingAliases.emplace_back in GuestModuleBuilder.cpp adds entry#module0#guest once per symbol index, and LinuxGuestModuleWriter rejects the second. Keeping one alias per name and module fixes it:

            auto& image = images[module];
            std::set<std::string> aliased;
            for (std::size_t index = 1; index < image.Symbols.size(); ++index) {
                ...
                if (!macos && exported && shared != sharedExports.end() && shared->second.contains(module) && aliased.insert(symbol.Name).second)

I applied that change to the merge of both PRs. Both cases above then convert, and these 10 tests pass: guest_needed_modules, guest_module_directories, linux_guest_stack, guest_symbol_names, guest_host_libc, linux_guest_qualified_imports, linux_guest_zero_address_exports, guest_unused_import_dependencies, guest_export_lookup and linux_guest_named_imports. Whichever of the two PRs lands second needs it.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5808994168 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15942#pullrequestreview-5808994168). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T00:52:32Z. **Review:** COMMENTED --- Tested on Windows 11 x64 with WinLibs GCC 15.2.0 `15.2.0posix-14.0.0-ucrt-r7` (as in CI), its CMake 4.3.1 and Ninja 1.13.2, and Python 3.15.0. Relinker-only Release build, head `433570f4` merged into `main` `9ade3ed8`. - Full `ctest --timeout 120 --parallel 4`: 794 tests. Nine timed out in that run while the machine was under other load, and all nine passed when rerun alone, both on this head and on `main`. `main` alone passed 793/793. - This PR's `test_linux_guest_qualified_imports.py` fails against the `main` relinker at `assert len(aliases) == 1` (`{'shared#guest': (18, 0, 1, 4096, 6)}`) and passes with this PR. **Interaction with #16384.** #16384 also accepts, on Linux, identical ordinary function exports that share a stripped name. Linux conversion built with the `guest_symbols` and `convert` helpers of `test_guest_export_lookup.py`, with `a.prx` exporting `entry#A#A` and `entry#B#A` (both `0x12`, same address): | Relinker | `b.prx` exports `entry` | `b.prx` exports `other` | |---|---|---| | `main`, and this PR alone | `Duplicate or empty export after stripping #: entry` | same | | #16384 alone | converts | converts | | this PR + #16384 | `Duplicate or empty guest binding alias: entry#module0#guest` | converts | Both copies of `entry` in `a.prx` are exported and `entry` is in `sharedExports`, so the new `BindingAliases.emplace_back` in `GuestModuleBuilder.cpp` adds `entry#module0#guest` once per symbol index, and `LinuxGuestModuleWriter` rejects the second. Keeping one alias per name and module fixes it: ```cpp auto& image = images[module]; std::set<std::string> aliased; for (std::size_t index = 1; index < image.Symbols.size(); ++index) { ... if (!macos && exported && shared != sharedExports.end() && shared->second.contains(module) && aliased.insert(symbol.Name).second) ``` I applied that change to the merge of both PRs. Both cases above then convert, and these 10 tests pass: `guest_needed_modules`, `guest_module_directories`, `linux_guest_stack`, `guest_symbol_names`, `guest_host_libc`, `linux_guest_qualified_imports`, `linux_guest_zero_address_exports`, `guest_unused_import_dependencies`, `guest_export_lookup` and `linux_guest_named_imports`. Whichever of the two PRs lands second needs it. AI-assisted: yes.
gabichuuuuu commented 2026-11-08 01:33:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T01:33:24Z.

Review: COMMENTED


Windows check of head 433570f454, merged onto main 210676ad86 (clean merge).

Setup: Windows 11, WinLibs GCC 15.2, Release, relinker-only.

  • Focused CTest set passes 10/10: linux_guest_qualified_imports, guest_symbol_names, guest_export_lookup, guest_needed_modules, guest_host_libc, guest_module_directories, guest_symbolic_modules and the linux_guest_* tests.
  • Negative control: the new test_linux_guest_qualified_imports.py and the updated test_guest_symbol_names.py both fail against the main relinker, so they cover the change.

Interaction with #16384. Each PR passes on its own, and the two merge cleanly, but together they reject a module that #16384 alone accepts. #16384 lets a Linux module export the same stripped name twice when both entries are identical functions. This PR then emits one BindingAliases entry per exported symbol index, so that module gets two aliases with the same name, and LinuxGuestModuleWriter throws.

Repro on main + #15942 + #16384, using the guest_symbols helper from test_guest_export_lookup.py:

  • a.prx exports entry#A#A and entry#B#A (both FUNC, section 1); b.prx exports entry.
  • Result: exit 2, Duplicate or empty guest binding alias: entry#module0#guest.
  • Control (b.prx exports other instead): exit 0. With #16384 alone, both cases convert.

A per-module set in the alias loop of GuestModuleBuilder::Build avoids it: declare std::set<std::string> aliased; before the inner symbol loop and add && aliased.insert(symbol.Name).second to the BindingAliases condition. Whichever of the two PRs lands second should carry that guard, plus a duplicate-entry case in the test.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815956970 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15942#pullrequestreview-5815956970). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T01:33:24Z. **Review:** COMMENTED --- Windows check of head `433570f454`, merged onto `main` `210676ad86` (clean merge). **Setup:** Windows 11, WinLibs GCC 15.2, Release, relinker-only. - Focused CTest set passes 10/10: `linux_guest_qualified_imports`, `guest_symbol_names`, `guest_export_lookup`, `guest_needed_modules`, `guest_host_libc`, `guest_module_directories`, `guest_symbolic_modules` and the `linux_guest_*` tests. - Negative control: the new `test_linux_guest_qualified_imports.py` and the updated `test_guest_symbol_names.py` both fail against the `main` relinker, so they cover the change. **Interaction with #16384.** Each PR passes on its own, and the two merge cleanly, but together they reject a module that #16384 alone accepts. #16384 lets a Linux module export the same stripped name twice when both entries are identical functions. This PR then emits one `BindingAliases` entry per exported symbol index, so that module gets two aliases with the same name, and `LinuxGuestModuleWriter` throws. Repro on `main` + #15942 + #16384, using the `guest_symbols` helper from `test_guest_export_lookup.py`: - `a.prx` exports `entry#A#A` and `entry#B#A` (both `FUNC`, section 1); `b.prx` exports `entry`. - Result: exit 2, `Duplicate or empty guest binding alias: entry#module0#guest`. - Control (`b.prx` exports `other` instead): exit 0. With #16384 alone, both cases convert. A per-module set in the alias loop of `GuestModuleBuilder::Build` avoids it: declare `std::set<std::string> aliased;` before the inner symbol loop and add `&& aliased.insert(symbol.Name).second` to the `BindingAliases` condition. Whichever of the two PRs lands second should carry that guard, plus a duplicate-entry case in the test.
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!15942
No description provided.