fix(relinker): keep host prx references out of guest modules on Linux #672
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/672"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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#guestto 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, as9cfdbff1intends, 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-Bsymbolictest failures listed in the issue don't come up.sceKernelDlsymon 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_namesrelinker 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_loadernow 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.prxexporting the 782 NIDs our libc exports, and it's relinked and run withLD_BIND_NOW=1 LD_DEBUG=bindingsagainstbuild/core/libs/libs. On main, 194 references from the hostlibc.prxand 14 fromlibkernel.prxbind into the guest libc,2sWzhYqFH4E(_Stdout) from the host libc among them. With this change none do, and the title's own import of_Stdoutstill 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-05T14:24:14Z.
The Linux failure is
agc_driver_flat_cache_bitshitting 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?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.
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-05T18:05:43Z.
Tested
e1c4e194with a title that bundles its ownlibc.prx: LEGO Horizon Adventures (PPSA14632, Unreal Engine), Arch Linux, GCC 16.2, Release, on top of main0518f0e0.On main the title segfaults on its first
printf: the bundled libc'sfwritecopies into a null buffer because its_Stdouthas been overwritten. A hardware watchpoint on the guest_Stdoutshows the writes come from_GLOBAL__sub_I_RuntimeSupport.cppin ourlibc.prx, i.e. theFileStream _Stdout_nid_postfix{stdout}constructor binding to the guest copy.With this PR the guest
_Stdoutis left alone and the title's ownprintfworks: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 underprx/, which all exportg_pAKPluginList, convert with the#guestsuffix. Loading them needed a local relinker change allowing duplicate guest exports that nothing imports, as on Windows in #684.guest_symbol_names,guest_module_directoriesandguest_dynamic_loaderpass on this combination.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).
main(681f83e5): segfaults a few seconds in, right after the first savedatadirNameSearch, the same place as in #476.With
LD_BIND_NOW=1 LD_DEBUG=bindings,2sWzhYqFH4E(_Stdout) now binds from the hostlibc.prxto itself, and the executable's import binds to2sWzhYqFH4E#guestin the bundledlibc.prx.guest.prx, as described.Minecraft I'll try later: on
mainit currently stops before this point for unrelated reasons (an unsupported relocation type in the relinker and a missinglibSceNpAuthAuthorizedAppDialog.prx), so it needs more work before it can say anything about this change.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_namesnow covers that case. Full ctest on lavapipe: 319/319.