fix(relinker): keep Linux imports declared from host modules off guest exports #1529
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1529"
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 johnmaia on 2026-10-08T11:20:10Z.
What
Fixes #1497.
On Linux,
GuestModuleBuilderrenamed every import whose NID a guest module exports to its guest-suffixed name, whatever module the import declares: the executable's imports (GuestModuleBuilder.cpp:180onmain) and the guest modules' own (:218). A title that bundles a module exporting system NIDs then had those imports bound to it.DOOM PPSA99666 declares
snprintf,vsnprintf,strlen,memcpy,mallocandfopenfromlibSceLibcInternal(#G#H, module 7) and nothing fromlibc. Thelibc.prxloader shim it bundles (ps5-native-app-boilerplate) exports placeholder functions under the same NIDs, so 71 imports became<nid>#guestand returned 0: no notification text, 27 opens of uninitialized paths, no WAD. Windows already binds by the declared module (WindowsEntryStubBuilder) and was not affected.An import now binds to a guest export only when the module it declares is a guest module:
ImportModulesthrough its relocation. A symbol declared from a module that is not a guest keeps its plain name and binds to the host library.GuestSymbol::Library; such an import is not searched among guest exports, renamed, or counted as a guest dependency.libc.prximported fromlibcstill binds to it, as in7103f390andtest_guest_host_libc.py), and Windows (declaresHostis false there).test_guest_symbol_namesgets two cases, using the qualified-import fixtures fromtest_windows_import_modules: an executable that declares one NID fromlibc(a guest) and one fromlibSceLibcInternal(a host), both exported by the guestlibc.prx; and a guest module importingsharedfromlibSceLibcInternalwhile another guest exports it. Onmainthe first fails with{'EEEEEEEEEEE#guest', 'AAAAAAAAAAA#guest'}.Overlap: #1462 edits the lines next to the executable import loop, so whichever merges second needs a small rebase. #1403 and #1249 merge cleanly.
Tested
ctest433/433, and the 152 guest/relinker tests again on the final revision;guest_symbol_namesfails onmainwith the new cases and passes with this change.windows_import_modules) again on the final revision.eboot.binandlibc.prx), relinked with its bundledlibc.prxand no--exclude-sce-module, on this branch plus #1278 (poll), #1279 and #1307: 0 imports bound to the guest module (71 onmain); the title opens/app0/wads/doom1.wadand stops at window creation on this headless machine, as with--exclude-sce-module libc.prx. Not run to E1M1 here (no display).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)poll)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:20:50Z.
Review: APPROVED
Excellent fix for a subtle but important relinker issue. The problem of guest modules incorrectly binding to imports declared from host modules is well-documented and the solution is clean.
Strengths:
GuestModuleBuilderwas renaming all imports matching exported NIDs regardless of declaring moduleTechnical notes:
declaresHostlambda is a clean way to encapsulate the host vs. guest module distinctionexecutableModulesmapping from relocation tables is the right approach for determining import provenanceThis will significantly improve compatibility with titles that bundle libc.prx loader shims. Ready to merge.
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T15:06:23Z.
Confirmed on Linux with a display and a discrete GPU, on top of current
main.main4b005b22+ d06fafd3 (clean merge), CachyOS (kernel 7.2.9, GCC 16.2.1), NVIDIA RTX 3080 (driver 615.71.09), full build withBUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ON.ctest466/466; the 167 relinker and guest tests again on their own.eboot.binandsce_module/libc.prxunwrapped from their SELF containers), relinked with the bundledlibc.prxas a guest module, no--exclude-sce-module:LD_DEBUG=bindings: 0 executable imports bind tolibc.prx.guest.prx; 77 bind to the hostlibc.prx. The guest module's own 101 imports bind to host prx as before./app0/wads/doom1.wad, writes/download0/doom.logand shows the game list at 59.93 FPS (window-title counter, 1412 frames in 25 s). Run without input, so not played to E1M1.main4b005b22relinker, same host libraries: 70 executable imports bind to the guest module,[notification]has no text,doom.logstays empty and the process exits with code 0 within a second (the failure in #1497).AI-assisted: yes (Claude Code); the runs and counts above were checked by hand.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T22:43:12Z.
This conflicts with main after today's merges; could you rebase? It's otherwise ready.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:16:32Z.
Merged with current main,
guest_symbol_namesfails attest_guest_symbol_names.py:175:Since #1102 every guest module also imports those two
__aps5_*symbols. Please rebase and checksharedagainst the module's imports without requiring it to be the only one.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T11:13:27Z.
I reproduced the reported current-main failure on
b5f5362d: the implementation passes its focused behavior once the test stops requiringsharedto be the only import.maininjects__aps5_get_pending_module_args_nid_no_patchand__aps5_set_module_init_result_nid_no_patchinto each guest module, so the useful assertion here is thatsharedis present andshared#guestis absent (or an equivalent membership check), rather than exact list equality.\n\nOn a detached worktree atb5f5362d, I applied the PR diff and that test-only assertion adjustment; the full Linux relinker-only build succeeded and CTest passed 97/97. Conventions andgit diff --checkalso pass. The official PR checks still need to run on the updated head after you rebase.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-10T11:31:29Z.
@johnmaia @oneandonlydean the rebase and the test change asked for above are on
DavidSamir:fix/relinker-declared-host-imports(12cd7d17, onmainb5f5362d), in case it saves a round trip. Take it into this PR or carry it, whichever is easier.8f5a66f9: this PR's commit, cherry-picked unchanged (author kept). It applied without conflicts.8ce04ddd: the consumer check no longer requiressharedto be the module's only symbol, since every guest module imports the two__aps5_*helpers after #1102. It checks thatsharedis there andshared#guestis not.12cd7d17: the declared-module case is converted with--macosas well.GuestModuleBuildertakes the non-Windows path for macOS, so the same binding happened there. The test reads the Mach-O bind names.Tested
macOS 26.7.1 (Apple silicon M2), Apple clang 21.0.0, relinker-only Release build:
GuestModuleBuilder.cpprestored tomain,guest_symbol_namesfails and the other 89 pass._EEEEEEEEEEE#guestis bound. With the fix:_EEEEEEEEEEE.tools/check_conventions.py --base origin/main: passed.libc.prx: 70 of 170 onmainb5f5362dand 0 with the branch for Linux output; 70 of 171 and 0 for--macosoutput.macos-port92d7098flibraries, relinker with and without this PR's change): without it, two empty notifications and exit after 7 s; with it,doom1.wadopens and the demo loop runs. Details in https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6096952968.Not tested: Linux and Windows runs (no such host here).
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:21:23Z.
Rebased on current
main(one conflict:Io::Utf8Pathin therejectSharedImportcalls) and added one commit on top, as asked by @oneandonlydean:test_guest_symbol_names.py: the guest-module consumer check now assertssharedis present andshared#guestis absent, instead of requiringsharedto be the only import (every guest module also imports the two__aps5_*helpers since #1102). Same change as proposed by @MarcZX100 / @DavidSamir.Checked: relinker build + 89 relinker tests green on the rebased tree;
guest_symbol_namesfails with theGuestModuleBuilder.cppchange reverted. Confirmed on a display + RTX 3080 by @SleglJan. Merging on green CI.