fix(relinker): resolve Linux guest NID providers #16384

Merged
farosch merged 4 commits from upstream-pr/16384 into main 2026-11-15 19:27:30 +00:00
farosch commented 2026-11-06 14:06:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by farosch on 2026-11-06T14:06:05Z.


What

Allow Linux guest conversion of identical SCE-qualified function aliases while retaining symbol indices for relocations and rejecting conflicting duplicates. When the runtime path contains libkernel_sys.prx and the title needs libkernel.prx, add the split provider to the process dependency graph so its NID exports are visible to guest modules.

Tested

Linux x86-64: relinker target built; CTests guest_host_libc, guest_export_lookup, and guest_module_directories passed; tools/check_conventions.py --base origin/main passed. GoY relinked with seven modules and its dependency graph includes libkernel_sys.prx. A short local smoke run passed symbol resolution but used a temporary category implementation that was removed after finding the firmware-based implementation in open PR 14216; the PR branch still needs that separate change. The run then reached the known sceRegMgrNonSysGetInt not implemented stub. /dev/gc is unavailable, so gameplay and GPU behavior were not tested.

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: #14216
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5189045258 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16384). Originally posted by [farosch](https://github.com/farosch) on 2026-11-06T14:06:05Z. --- ### What Allow Linux guest conversion of identical SCE-qualified function aliases while retaining symbol indices for relocations and rejecting conflicting duplicates. When the runtime path contains libkernel_sys.prx and the title needs libkernel.prx, add the split provider to the process dependency graph so its NID exports are visible to guest modules. ### 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. --> Linux x86-64: relinker target built; CTests guest_host_libc, guest_export_lookup, and guest_module_directories passed; tools/check_conventions.py --base origin/main passed. GoY relinked with seven modules and its dependency graph includes libkernel_sys.prx. A short local smoke run passed symbol resolution but used a temporary category implementation that was removed after finding the firmware-based implementation in open PR 14216; the PR branch still needs that separate change. The run then reached the known sceRegMgrNonSysGetInt not implemented stub. /dev/gc is unavailable, so gameplay and GPU behavior were not tested. ### 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: #14216 <!-- #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 -->
ahmadmuj commented 2026-11-06 15:15:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T15:15:17Z.

Review: COMMENTED


Checked head b0bc8c92e3a3d4f130426d0b8e6efaf9d47974a4 against main 7383be1a19c7fc2f8f1b8e8de1f1843e4a312976 on Ubuntu 24.04.2/WSL2, GCC 13.3, Release. PR base: 6ed10ccd1fd35e950f42ce9614981fb94d52ef6e.

The new provider scan misses a valid later directory when the first run-path directory does not exist.

I used the actual relinker CLI with the existing test_guest_host_libc fixture helpers: a main declaring a libkernel.prx dependency, one other.prx guest module, and the test's libkernel_sys.prx marker. Each call passes --rpath with two absolute components.

Run path Head's final DT_NEEDED entries
existing empty / provider libkernel.prx, libkernel_sys.prx
missing / provider libkernel.prx only
provider / missing libkernel.prx, libkernel_sys.prx
missing / existing empty libkernel.prx only, as expected

Every list starts with exactly $ORIGIN/app0/sce_module/other.prx.guest.prx. All calls exit 0 and retain both components, in order, in DT_RUNPATH.

The directory loop stops when runDirectoriesExist becomes false. The new scan therefore never sees the later provider. glibc's search continues after absent directories.

Please collect all Linux run-path components while keeping the separate existence flag cumulative. A temporary two-line control does that and passes all four cases. Three extra --omit-unavailable-dependencies cases also pass: an unused dependency disappears when both directories exist, but stays when either directory is missing. Restoring and rebuilding the exact head reproduces only the missing/provider failure; its binary hash matches the original.

Exact head commands
cmake -S /home/ahmad/work/anyps5/worktrees/anyps5-pr-16384 -B /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON
cmake --build /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head --target relinker -j 4
ctest --test-dir /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head -R '^(guest_host_libc|guest_export_lookup|guest_module_directories)$' --output-on-failure -V
python3 /home/ahmad/work/anyps5/runs/coordinator-20261106T102326Z/042-review-16384/LinuxKernelProviderRunpathProbe.py /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head/core/relinker/relinker /home/ahmad/work/anyps5/worktrees/anyps5-pr-16384/core/relinker/relinker/tests /home/ahmad/work/anyps5/runs/coordinator-20261106T102326Z/042-review-16384/probe-head.json
python3 tools/check_conventions.py --base origin/main

The conventions command runs inside the head worktree. Main uses worktrees/anyps5-pr-16384-main and builds/anyps5-pr-16384-main. The correction and restoration rebuild the head target and rerun the focused tests and probe with separate receipts.

The three existing tests pass on head, main, the temporary control and restored head. Conventions pass on restored head. Main omits the provider in all three positive cases because it lacks this feature.

The marker checks dependency selection only. No emitted guest program, runtime symbol binding, title, console, Windows or GPU execution is tested. No source change is included with this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5802243506 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16384#pullrequestreview-5802243506). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-06T15:15:17Z. **Review:** COMMENTED --- Checked head `b0bc8c92e3a3d4f130426d0b8e6efaf9d47974a4` against main `7383be1a19c7fc2f8f1b8e8de1f1843e4a312976` on Ubuntu 24.04.2/WSL2, GCC 13.3, Release. PR base: `6ed10ccd1fd35e950f42ce9614981fb94d52ef6e`. The new provider scan misses a valid later directory when the first run-path directory does not exist. I used the actual relinker CLI with the existing `test_guest_host_libc` fixture helpers: a main declaring a `libkernel.prx` dependency, one `other.prx` guest module, and the test's `libkernel_sys.prx` marker. Each call passes `--rpath` with two absolute components. | Run path | Head's final DT_NEEDED entries | | --- | --- | | existing empty / provider | `libkernel.prx`, `libkernel_sys.prx` | | missing / provider | `libkernel.prx` only | | provider / missing | `libkernel.prx`, `libkernel_sys.prx` | | missing / existing empty | `libkernel.prx` only, as expected | Every list starts with exactly `$ORIGIN/app0/sce_module/other.prx.guest.prx`. All calls exit 0 and retain both components, in order, in DT_RUNPATH. The [directory loop](https://github.com/boykopovar/AnyPS5/blob/b0bc8c92e3a3d4f130426d0b8e6efaf9d47974a4/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L373) stops when `runDirectoriesExist` becomes false. The new scan therefore never sees the later provider. [glibc's search](https://github.com/bminor/glibc/blob/glibc-2.41/elf/dl-load.c#L1859) continues after absent directories. Please collect all Linux run-path components while keeping the separate existence flag cumulative. A temporary two-line control does that and passes all four cases. Three extra `--omit-unavailable-dependencies` cases also pass: an unused dependency disappears when both directories exist, but stays when either directory is missing. Restoring and rebuilding the exact head reproduces only the missing/provider failure; its binary hash matches the original. <details> <summary>Exact head commands</summary> ```sh cmake -S /home/ahmad/work/anyps5/worktrees/anyps5-pr-16384 -B /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON cmake --build /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head --target relinker -j 4 ctest --test-dir /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head -R '^(guest_host_libc|guest_export_lookup|guest_module_directories)$' --output-on-failure -V python3 /home/ahmad/work/anyps5/runs/coordinator-20261106T102326Z/042-review-16384/LinuxKernelProviderRunpathProbe.py /home/ahmad/work/anyps5/builds/anyps5-pr-16384-head/core/relinker/relinker /home/ahmad/work/anyps5/worktrees/anyps5-pr-16384/core/relinker/relinker/tests /home/ahmad/work/anyps5/runs/coordinator-20261106T102326Z/042-review-16384/probe-head.json python3 tools/check_conventions.py --base origin/main ``` The conventions command runs inside the head worktree. Main uses `worktrees/anyps5-pr-16384-main` and `builds/anyps5-pr-16384-main`. The correction and restoration rebuild the head target and rerun the focused tests and probe with separate receipts. </details> The three existing tests pass on head, main, the temporary control and restored head. Conventions pass on restored head. Main omits the provider in all three positive cases because it lacks this feature. The marker checks dependency selection only. No emitted guest program, runtime symbol binding, title, console, Windows or GPU execution is tested. No source change is included with this review.
gabichuuuuu commented 2026-11-08 01:33:26 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Windows check of head 482c9af7ae, merged onto main 210676ad86 (clean merge). #14216, listed under Depends on, is already merged.

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

  • Focused CTest set passes 10/10: windows_guest_export_aliases, guest_export_lookup, guest_host_libc, guest_module_directories, guest_needed_modules, guest_symbolic_modules, needed_libraries and the linux_guest_* tests.
  • Negative control against the main relinker: test_guest_export_lookup.py, test_guest_host_libc.py and test_guest_module_directories.py from this PR fail, so they cover the change. test_guest_needed_modules.py passes on main too.

Interaction with #15942. The two merge cleanly, but together they reject a module this PR accepts on its own. Here a Linux module may export the same stripped name twice when both entries are identical functions. #15942 emits one binding alias per exported symbol index, so that module gets two aliases with the same name and LinuxGuestModuleWriter throws Duplicate or empty guest binding alias: entry#module0#guest. Repro: a.prx exports entry#A#A and entry#B#A (both FUNC, section 1), and b.prx exports entry. That converts with this PR alone and fails with both. Details and a two-line guard are in my comment on #15942.

Minor, not blocking: the Linux provider rule adds libkernel_sys.prx only when libkernel.prx is needed. The Windows import builder covers the whole kernel family (libkernel, libkernel_sys, libkernel_web), so a title that needs only libkernel_sys.prx or libkernel_web.prx takes a different path on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815957052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16384#pullrequestreview-5815957052). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T01:33:26Z. **Review:** COMMENTED --- Windows check of head `482c9af7ae`, merged onto `main` `210676ad86` (clean merge). #14216, listed under Depends on, is already merged. **Setup:** Windows 11, WinLibs GCC 15.2, Release, relinker-only. - Focused CTest set passes 10/10: `windows_guest_export_aliases`, `guest_export_lookup`, `guest_host_libc`, `guest_module_directories`, `guest_needed_modules`, `guest_symbolic_modules`, `needed_libraries` and the `linux_guest_*` tests. - Negative control against the `main` relinker: `test_guest_export_lookup.py`, `test_guest_host_libc.py` and `test_guest_module_directories.py` from this PR fail, so they cover the change. `test_guest_needed_modules.py` passes on `main` too. **Interaction with #15942.** The two merge cleanly, but together they reject a module this PR accepts on its own. Here a Linux module may export the same stripped name twice when both entries are identical functions. #15942 emits one binding alias per exported symbol index, so that module gets two aliases with the same name and `LinuxGuestModuleWriter` throws `Duplicate or empty guest binding alias: entry#module0#guest`. Repro: `a.prx` exports `entry#A#A` and `entry#B#A` (both `FUNC`, section 1), and `b.prx` exports `entry`. That converts with this PR alone and fails with both. Details and a two-line guard are in my comment on #15942. Minor, not blocking: the Linux provider rule adds `libkernel_sys.prx` only when `libkernel.prx` is needed. The Windows import builder covers the whole kernel family (`libkernel`, `libkernel_sys`, `libkernel_web`), so a title that needs only `libkernel_sys.prx` or `libkernel_web.prx` takes a different path on Linux.
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!16384
No description provided.