fix(relinker): keep host prx references out of guest modules on Linux #672

Merged
NahuelGenchi merged 1 commit from upstream-pr/672 into main 2026-10-06 00:15:50 +00:00
NahuelGenchi commented 2026-10-05 13:58:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-05T13:58:54Z.


What

Refs #476, the interposition half. #618 already fixed the load failure.

On Linux all modules resolve through one global scope and the guest modules come first in it, so when a title bundles its own libc.prx, every host prx reference to a NID that the guest libc also exports binds to the guest libc. That's how the host libc ends up building its streams on top of the guest _Stdout.

Instead of -Bsymbolic, which breaks the copy relocations and the personality check the tests rely on, this keeps the host prx from ever seeing guest names. On Linux the relinker now appends #guest to every guest module export, and to every import in the guest modules and in the executable that a guest module satisfies. The title's own imports still reach the guest modules first, as 9cfdbff1 intends, and a host prx can only bind to host definitions, which is what Windows already gets from explicit DLL imports. Names no guest module exports are left alone, so __error, __stack_chk_* and the other guest imports from host prx resolve as before. The host prx are built and patched exactly as before, so the -Bsymbolic test failures listed in the issue don't come up.

sceKernelDlsym on Linux also tries the suffixed name and the suffixed NID, so a title looking up symbols in its own modules still finds them. Windows is unchanged.

Tested

Ubuntu 26.04, GCC 15.2.

New guest_symbol_names relinker test with two guest modules and an executable. It checks that the guest exports and the imports they satisfy get the suffix, and that the imports left for the host keep their names. On main it fails with ['AAAAAAAAAAA', 'BBBBBBBBBBB', 'CCCCCCCCCCC']. guest_dynamic_loader now also looks up two fixture exports that only exist under the suffixed name and the suffixed NID, and it aborts without the libkernel change.

I don't have any of the affected titles, so I reproduced the binding with the real patched host prx instead. A synthetic title bundles a libc.prx exporting the 782 NIDs our libc exports, and it's relinked and run with LD_BIND_NOW=1 LD_DEBUG=bindings against build/core/libs/libs. On main, 194 references from the host libc.prx and 14 from libkernel.prx bind into the guest libc, 2sWzhYqFH4E (_Stdout) from the host libc among them. With this change none do, and the title's own import of _Stdout still binds to the guest libc.

Full ctest on lavapipe with ANYPS5_REQUIRE_VULKAN=1: 289/289. On RADV (R9 380) the only failures are the three wave64 pixel tests that fail on main too.

@Pacuka you offered to try a proper fix with Dreaming Sarah and Minecraft, and @Amielle-Inside's Tales of Xillia run stops at the same place, so a run with any of those would show whether this is enough on its own.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4746048635 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/672). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-05T13:58:54Z. --- ### What Refs #476, the interposition half. #618 already fixed the load failure. On Linux all modules resolve through one global scope and the guest modules come first in it, so when a title bundles its own `libc.prx`, every host prx reference to a NID that the guest libc also exports binds to the guest libc. That's how the host libc ends up building its streams on top of the guest `_Stdout`. Instead of `-Bsymbolic`, which breaks the copy relocations and the personality check the tests rely on, this keeps the host prx from ever seeing guest names. On Linux the relinker now appends `#guest` to every guest module export, and to every import in the guest modules and in the executable that a guest module satisfies. The title's own imports still reach the guest modules first, as 9cfdbff1 intends, and a host prx can only bind to host definitions, which is what Windows already gets from explicit DLL imports. Names no guest module exports are left alone, so `__error`, `__stack_chk_*` and the other guest imports from host prx resolve as before. The host prx are built and patched exactly as before, so the `-Bsymbolic` test failures listed in the issue don't come up. `sceKernelDlsym` on Linux also tries the suffixed name and the suffixed NID, so a title looking up symbols in its own modules still finds them. Windows is unchanged. ### Tested Ubuntu 26.04, GCC 15.2. New `guest_symbol_names` relinker test with two guest modules and an executable. It checks that the guest exports and the imports they satisfy get the suffix, and that the imports left for the host keep their names. On main it fails with `['AAAAAAAAAAA', 'BBBBBBBBBBB', 'CCCCCCCCCCC']`. `guest_dynamic_loader` now also looks up two fixture exports that only exist under the suffixed name and the suffixed NID, and it aborts without the libkernel change. I don't have any of the affected titles, so I reproduced the binding with the real patched host prx instead. A synthetic title bundles a `libc.prx` exporting the 782 NIDs our libc exports, and it's relinked and run with `LD_BIND_NOW=1 LD_DEBUG=bindings` against `build/core/libs/libs`. On main, 194 references from the host `libc.prx` and 14 from `libkernel.prx` bind into the guest libc, `2sWzhYqFH4E` (`_Stdout`) from the host libc among them. With this change none do, and the title's own import of `_Stdout` still binds to the guest libc. Full ctest on lavapipe with `ANYPS5_REQUIRE_VULKAN=1`: 289/289. On RADV (R9 380) the only failures are the three wave64 pixel tests that fail on main too. @Pacuka you offered to try a proper fix with Dreaming Sarah and Minecraft, and @Amielle-Inside's Tales of Xillia run stops at the same place, so a run with any of those would show whether this is enough on its own. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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
NahuelGenchi commented 2026-10-05 14:24:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-05T14:24:14Z.


The Linux failure is agc_driver_flat_cache_bits hitting the 120 s timeout on lavapipe. The same test timed out today on #593, #545 and #668 as well, and here it finishes in under 3 s on lavapipe (Mesa 26.0.8, 25 runs with 4 lavapipe threads pinned to 4 cores), so it doesn't look related to this change. Could someone re-run the job?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5996450420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/672#issuecomment-5996450420). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-05T14:24:14Z. --- The Linux failure is `agc_driver_flat_cache_bits` hitting the 120 s timeout on lavapipe. The same test timed out today on #593, #545 and #668 as well, and here it finishes in under 3 s on lavapipe (Mesa 26.0.8, 25 runs with 4 lavapipe threads pinned to 4 cores), so it doesn't look related to this change. Could someone re-run the job?
adriadam10 commented 2026-10-05 15:04:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T15:04:58Z.


That test is ours (#495), sorry for the noise. It is slow only on CI's lavapipe (Ubuntu Mesa 25.2.8, LLVM 20), which takes about 3 s to compile each BDA access per shader and wave size. Newer Mesa doesn't, which is why it finishes in under 3 s on your 26.0.8. On main it already took 113 s of the 120 s limit, so on a slower runner it times out, as on #545, #593, #668 and here.

#677 trims it to one wave32 kernel with 5 BDA accesses (was 19, run as wave32 and wave64), with the expected values measured again on HW. On its Linux job the test takes 5.6 s cold (113 s on main), and the job is green. Once it's merged, a rebase or a re-run of this job should pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5997182869 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/672#issuecomment-5997182869). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T15:04:58Z. --- That test is ours (#495), sorry for the noise. It is slow only on CI's lavapipe (Ubuntu Mesa 25.2.8, LLVM 20), which takes about 3 s to compile each BDA access per shader and wave size. Newer Mesa doesn't, which is why it finishes in under 3 s on your 26.0.8. On main it already took 113 s of the 120 s limit, so on a slower runner it times out, as on #545, #593, #668 and here. #677 trims it to one wave32 kernel with 5 BDA accesses (was 19, run as wave32 and wave64), with the expected values measured again on HW. On its Linux job the test takes 5.6 s cold (113 s on main), and the job is green. Once it's merged, a rebase or a re-run of this job should pass.
alfalfa-star commented 2026-10-05 18:05:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-05T18:05:43Z.


Tested e1c4e194 with a title that bundles its own libc.prx: LEGO Horizon Adventures (PPSA14632, Unreal Engine), Arch Linux, GCC 16.2, Release, on top of main 0518f0e0.

On main the title segfaults on its first printf: the bundled libc's fwrite copies into a null buffer because its _Stdout has been overwritten. A hardware watchpoint on the guest _Stdout shows the writes come from _GLOBAL__sub_I_RuntimeSupport.cpp in our libc.prx, i.e. the FileStream _Stdout_nid_postfix{stdout} constructor binding to the guest copy.

With this PR the guest _Stdout is left alone and the title's own printf works:

Memory va range 7f235fe00000 - 7fa31fe00000
Frame Buffer va range 7fa31fe00000 - 7fa35fe00000
FBootAllocator used 2192936 out of 2195456 bytes of memory, wasting 2520 bytes.
Used memory before allocating anything was 316.06MB

Together with #580, #722, #723 and local throwing stubs for the title's other missing imports, it gets on to start Unreal Engine (command line, config, crash report client, localization, worker threads) and stops at sceVoiceQoSInit, which is not implemented and unrelated to this change. The 36 Wwise plugins under prx/, which all export g_pAKPluginList, convert with the #guest suffix. Loading them needed a local relinker change allowing duplicate guest exports that nothing imports, as on Windows in #684. guest_symbol_names, guest_module_directories and guest_dynamic_loader pass on this combination.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000233738 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/672#issuecomment-6000233738). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-05T18:05:43Z. --- Tested `e1c4e194` with a title that bundles its own `libc.prx`: LEGO Horizon Adventures (PPSA14632, Unreal Engine), Arch Linux, GCC 16.2, Release, on top of main `0518f0e0`. On main the title segfaults on its first `printf`: the bundled libc's `fwrite` copies into a null buffer because its `_Stdout` has been overwritten. A hardware watchpoint on the guest `_Stdout` shows the writes come from `_GLOBAL__sub_I_RuntimeSupport.cpp` in our `libc.prx`, i.e. the `FileStream _Stdout_nid_postfix{stdout}` constructor binding to the guest copy. With this PR the guest `_Stdout` is left alone and the title's own `printf` works: ``` Memory va range 7f235fe00000 - 7fa31fe00000 Frame Buffer va range 7fa31fe00000 - 7fa35fe00000 FBootAllocator used 2192936 out of 2195456 bytes of memory, wasting 2520 bytes. Used memory before allocating anything was 316.06MB ``` Together with #580, #722, #723 and local throwing stubs for the title's other missing imports, it gets on to start Unreal Engine (command line, config, crash report client, localization, worker threads) and stops at `sceVoiceQoSInit`, which is not implemented and unrelated to this change. The 36 Wwise plugins under `prx/`, which all export `g_pAKPluginList`, convert with the `#guest` suffix. Loading them needed a local relinker change allowing duplicate guest exports that nothing imports, as on Windows in #684. `guest_symbol_names`, `guest_module_directories` and `guest_dynamic_loader` pass on this combination.
Pacuka commented 2026-10-05 21:02:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-05T21:02:13Z.


Tested e1c4e194 with Dreaming Sarah (PPSA02929, Construct, bundles its own libc.prx) on CachyOS, Linux 7.2, GCC, AMD GPU (RADV).

  • Current main (681f83e5): segfaults a few seconds in, right after the first savedata dirNameSearch, the same place as in #476.
  • This PR: the title boots and keeps running (menu with sound) until I stopped it after 90 s.

With LD_BIND_NOW=1 LD_DEBUG=bindings, 2sWzhYqFH4E (_Stdout) now binds from the host libc.prx to itself, and the executable's import binds to 2sWzhYqFH4E#guest in the bundled libc.prx.guest.prx, as described.

Minecraft I'll try later: on main it currently stops before this point for unrelated reasons (an unsupported relocation type in the relinker and a missing libSceNpAuthAuthorizedAppDialog.prx), so it needs more work before it can say anything about this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6002859500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/672#issuecomment-6002859500). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-05T21:02:13Z. --- Tested e1c4e194 with Dreaming Sarah (PPSA02929, Construct, bundles its own libc.prx) on CachyOS, Linux 7.2, GCC, AMD GPU (RADV). - Current `main` (681f83e5): segfaults a few seconds in, right after the first savedata `dirNameSearch`, the same place as in #476. - This PR: the title boots and keeps running (menu with sound) until I stopped it after 90 s. With `LD_BIND_NOW=1 LD_DEBUG=bindings`, `2sWzhYqFH4E` (`_Stdout`) now binds from the host `libc.prx` to itself, and the executable's import binds to `2sWzhYqFH4E#guest` in the bundled `libc.prx.guest.prx`, as described. Minecraft I'll try later: on `main` it currently stops before this point for unrelated reasons (an unsupported relocation type in the relinker and a missing `libSceNpAuthAuthorizedAppDialog.prx`), so it needs more work before it can say anything about this change.
NahuelGenchi commented 2026-10-05 22:59:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-05T22:59:05Z.


Thanks @alfalfa-star and @Pacuka for running it on real titles, and @adriadam10 for the CI fix.

Rebased on main now that #733 and #677 are in. #733 parses the executable's symbol names too, so the rename moved into that loop instead of keeping a second copy of it. Exports that #733 lets several modules share get the suffix in every module, and guest_symbol_names now covers that case. Full ctest on lavapipe: 319/319.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6004930717 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/672#issuecomment-6004930717). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-05T22:59:05Z. --- Thanks @alfalfa-star and @Pacuka for running it on real titles, and @adriadam10 for the CI fix. Rebased on main now that #733 and #677 are in. #733 parses the executable's symbol names too, so the rename moved into that loop instead of keeping a second copy of it. Exports that #733 lets several modules share get the suffix in every module, and `guest_symbol_names` now covers that case. Full ctest on lavapipe: 319/319.
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!672
No description provided.