fix(relinker): accept weak duplicate guest exports #755
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/755"
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 julienlgy on 2026-10-05T20:41:56Z.
What
The relinker rejected games whose guest modules export the same NID as a weak symbol:
Cause
HqLRpV9pAhcwithSTB_WEAKbinding (st_info = 0x22,STV_PROTECTED), asHqLRpV9pAhc#C#AinPSNCommon.prxandHqLRpV9pAhc#Y#AinPSNCore.prx.48 8b 4e 10 48 89 f8 48 89 4f 10 c5 f8 10 06 c5 f8 11 07 c3, a 24-byte struct copy). This is ordinary C++ output: inline functions and template instantiations are emitted in every module that uses them and marked weak so that the linker keeps one copy.#library#modulesuffix keeps them in separate namespaces.GuestModuleBuilderstrips that suffix and puts every guest export in one global table, so any duplicate, weak or not, was a hard error.Change (
GuestModuleBuilder::Build)Duplicate guest exports now follow ELF symbol binding rules:
STT_*typeThe provider map only drives dependency ordering and the import/export type check. At run time the generated loader resolves an import with a linear search over the loaded modules, so the first definition wins, the same as
ld.sowithoutLD_DYNAMIC_WEAK. Each guest module still exports its own copy;WindowsGuestModuleWriterdeduplicates exports per module only, so it needs no change.test_guest_module_directories.pygets aweakflag on the fixture symbol and covers the weak/weak, weak/global and global/weak cases on Linux and Windows output. The existing global/global case still has to fail.Tested
relinkeron top of currentmain.test_guest_module_directories.py,test_guest_tls.py,test_guest_host_libc.pyandtest_guest_intel_trampolines.pypass.PSNCommon.prx/PSNCore.prxinapp0/prx: the relinker no longer stops on the duplicate and produceseboot.exeplus all 8 guest modules. The game still exits early with0xC0000139(entry point not found), which is a separate missing-export issue outside this PR.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 oneandonlydean on 2026-10-05T22:56:55Z.
Thanks for this. #733 has landed and changed the same block in
GuestModuleBuilder::Build, so this now conflicts withmain. The two changes overlap in what they allow, so the rebase needs a small merge of the rules rather than taking one side:mainnow accepts any duplicate guest export that no module imports, and fails with "Ambiguous guest import" when one does (sharedExportsandrejectSharedImport). Windows still fails on every duplicate.sharedExports. Otherwise an import of a weak symbol likeHqLRpV9pAhcstill fails as ambiguous on Linux. Two global definitions keepmain's behaviour on both platforms.main'sexisting->second == images.size()check (a duplicate inside one module) ahead of thefind_if. In that caseimages.at(existing->second)is out of range, because the current image isn't inimagesyet.Your weak test cases import the symbol through
consumer.prx, so they cover the Linux import path once they run againstmain's code.Pull request closed