fix(relinker): leave weak imports of bundled modules unbound on Windows #6702
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6702"
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 karimibrahim07 on 2026-10-16T05:19:15Z.
What
On Windows, a weak import of a bundled module that no library exports stopped the title with
FAIL: unresolved ELF import.Domain::GuestImporthad no weak flag, soWindowsPePatcherhanded every guest import to the entry stub as a strong one, although the stub already binds an executable's weak imports to null (WindowsEntryStubBuilder.cppL602-L614).GuestImportnow carriesWeak.WindowsGuestModuleWritersets it from the symbol's ELF binding (STB_WEAK) forR_X86_64_64,GLOB_DATandJUMP_SLOTimports, andWindowsPePatcherpasses it on. A weak guest import that a library exports still binds to it.This is the Windows side of what #6080 does for Linux guest modules, and it merges cleanly with it. #6240 records the same binding in the guest registries, which only changes diagnostics. The test is a new file, so it doesn't touch the
test_weak_imports.pylines #6080 changes.Tested
Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release,
BUILD_TESTING=ON, onmain5d9dcc42d:New
windows_guest_weak_importstest. A bundled module importsabsent#A#Bfroma.prx, which doesn't export it, and itsDT_INITtraps unless the slot is null:a.prx.unresolved ELF import absent from a.prx.With the three source files from
main, the weak case fails with that sameunresolved ELF import absent from a.prx.The relinker tests pass, 131 of 131.
python tools/check_conventions.py --base origin/mainpasses.The Quake homebrew (#6698), relinked with
--windows --to-intel --trap-sdk-syscall-stubs --registryand itslibOSMesa.so.8insce_module/:libOSMesa.so.8stay unresolved. 10 of them are weak (STB_WEAKin its.dynsym):ZSTD_trace_compress_begin,ZSTD_trace_compress_end,ZSTD_trace_decompress_begin,ZSTD_trace_decompress_end__dlopen,__dlsym,__dladdr,__dlclose,__dlerrorkernel_mprotectqsort_sremains, a strong import that libc doesn't implement yet.Linux and macOS not affected; the change is in the Windows writer and patcher.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T05:32:35Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/relinker/tests/test_windows_guest_weak_imports.pySome comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/domain/include/domain/GuestRuntime.hppcore/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cppcore/relinker/elfpatcher/src/windows/WindowsPePatcher.cppcore/relinker/relinker/tests/test_windows_guest_weak_imports.pycore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T11:20:29Z.
Cross-validation on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2, PR head
18ecee64don main5d9dcc42d(fast-forward, no conflicts). Windows-only path, so the checks are on the relinker; I did not run Quake (not available here).windows_guest_weak_imports,--repeat until-fail:3: 3 of 3. With #6697 merged on top (no conflict) bothwindows_named_importsandwindows_guest_weak_importspass 3 of 3, and the 101 relinker tests of that tree pass.GuestRuntime.hpp,WindowsGuestModuleWriter.cppandWindowsPePatcher.cppfrom main (test and CMake kept) the weak case fails withFAIL: unresolved ELF import absent from a.prx(exit0xC0000139). With the changes it passes. Same result as your description.tools/check_conventions.py --base origin/mainandgit diff --check: pass.eboot.elf, main's relinker against this PR's (same flags, no runs): the same outcome for every title (PPSA99995 stops in both withFAIL: Unsupported Windows guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00)), no otherFAIL, noWARN, the registries are byte-identical.app.exediffers in 4 titles (PPSA28319, PPSA99109, PPSA99110, PPSA99920); the other 47 are byte-identical.unresolvedline; the logs differ only in addresses and paths.No local title has a weak import of a bundled module that nothing exports, so these runs show no regression, not the fix itself; the Quake result (11 down to 1 unresolved import) is not reproduced here.
Not checked: Quake, Linux, macOS, a full-tree build (relinker targets only).
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:50:55Z.
Checked the diff:
GuestImport::Weakis set fromSTB_WEAKfor the three import relocation kinds, passed throughWindowsPePatcher, and the entry stub already binds weak imports to null. The new test covers both the weak (exit 11) and the global (still fails) case, and @screamm's Windows run with a negative control confirms it pins the fix. Merged.