fix(relinker): resolve kernel variant imports via canonical kernel #8867
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8867"
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 MarcZX10 on 2026-10-21T03:43:24Z.
What
The Windows relinker already adds canonical
libkernel.prxwhenlibkernel_web.prxis a dependency, but not forlibkernel_sys.prx. Also, a scoped host import from either variant searched only that variant (and the existing libc fallback), even if canonical libkernel was loaded. This made a syntheticgetpagesizeimport fail when scoped tolibkernel_sys.prxorlibkernel_web.prxdespite canonical libkernel exporting it.Load canonical libkernel for either variant and search a scoped variant import in this order: the requested variant, canonical libkernel, then the existing libc fallback. This keeps requested-provider precedence and does not search guest modules as aliases. Regression coverage checks the generated search order and both variant dependency lists. The overlap report found shared source/test files with #3965, #7594 and #7532; manual diff review shows their startup-stack/MXCSR changes are separate from this provider-resolution behavior. This PR does not depend on them.
Tested
Linux x86-64, GCC 12.2, relinker-only Ninja build:
cmake -S . -B build -G Ninja -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON -DANYPS5_RELINKER_CLI=ONcmake --build build --target entry_stub_tests -j4ctest --test-dir build -R '^entry_stub$' --output-on-failure: passed.python3 tools/check_conventions.py --base upstream/main: passed.python3 tools/pr_overlap.py --branch codex/kernel-variant-host-fallback: no duplicate behavior found; reported shared files were manually reviewed as described above.Not run: Windows execution of the synthetic startup-import reproducer or a retail title.
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-21T04:20:04Z.
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/elfpatcher/tests/EntryStubTests.cppL3, L118, L128Some 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/elfpatcher/src/windows/WindowsEntryStubBuilder.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:21:29Z.
Manual overlap review for the bot warning: #3965 changes
WindowsEntryStubBuilder.cppin the startup-stack setup and unwind-table emission sections; this PR changes only import provider ordering around the earlierhostModulebranch. #7532 changes the generic Linux entry-stub builder and adds a test at the start ofEntryStubTests.cpp; this PR adds Windows-specific cases later in that same test file. The touched hunks are separate and should compose, though #3965’s new unwind entries warrant rerunning the Windows entry-stub tests after integration.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:45:03Z.
Windows run of
fef2755c76, the part the description lists as not run: the synthetic startup-import reproducer from #8853, executed.Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,
BUILD_TESTING=ON, RTX 4070 not involved. The reproducer is #8853's generator as posted there (a PE fromWindowsImportBuilder,WindowsEntryStubBuilderandWindowsPeWriterwith one strong import ofgetpagesize,k+AXqu2-eBc, an eight-byte GOT and a guest entry ofxor eax,eax; ret), built twice againstrelinker_core: once frommain7ab4b2e561and once from this head, and run beside the patchedlibkernel_sys.prx,libkernel_web.prx,libkernel.prxandlibc.prxof a full build of currentmain.mainlibkernel_sys.prxFAIL: unresolved ELF import k+AXqu2-eBc from libkernel_sys.prxlibkernel_web.prxlibkernel.prx(control)On this head
ctest -R "^(entry_stub|windows_dependency_diagnostics)$": 2 of 2 pass. Not run: a retail title.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:45:29Z.
Thanks for running the synthetic reproducer on Windows. That fills the platform gap I called out: both scoped kernel variants now resolve on the PR head, the canonical libkernel control remains green, and the two focused relinker tests pass. The retail-title limitation is clearly stated.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:34:08Z.
Thanks for running the Windows reproducer. This closes the host coverage gap I had called out: both kernel variants now reach the guest entry, while the libkernel control still passes on main. I will keep the console and title limitation clear.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:47:47Z.
Follow-up for the variant-only
__errorcases reported on #8853:ReadLibrariesappended canonicallibkernel.prxafter it had already decided whether to append the sharedlibc.prx, so variant-only loads omitted libc from the Windows startup symbol table. I added dependency-list regressions for both kernel variants, then made the inferred list include canonical kernel followed by libc (without duplicating explicitly requested providers).Validation on the updated PR head: the new
entry_stubregression failed before the source fix withlibkernel_sys.prx: canonical kernel fallback and its libc provider are not loaded, and passes after it.python3 tools/check_conventions.py --base upstream/main --head HEADandgit diff --checkpass. This is Linux relinker-only validation; I did not run the Windows-only dependency-diagnostics executable or a retail title.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T07:01:17Z.
Windows run of
7fdad075c3, the part the follow-up lists as not run: the variant-only dependency closure UnhealthyKraken reported on #8853, executed, plus the Windows-only dependency-diagnostics test.Same host and toolchain as my run above (Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 ucrt-posix-seh r7, Release,
BUILD_TESTING=ON). Each probe takes its library list fromWindowsImportBuilder::ReadLibrariesover a dynamic section with a single DT_NEEDED entry, imports one NID qualified to that module (eight-byte GOT, guest entryxor eax,eax; ret), and runs beside the patchedlibc.prx,libkernel.prx,libkernel_sys.prxandlibkernel_web.prxof a full build ofmain7ce3b1df3e. The generator is built twice againstrelinker_core: frommain7ce3b1df3eand from this head merged onto it (7e589461f5, clean).main: inferred list, resultlibkernel_sys.prx,__error(9BcDykPmo1I)[libkernel_sys], exit 0xc0000139,unresolved ELF import 9BcDykPmo1I from libkernel_sys.prx[libkernel_sys, libkernel, libc], exit 0libkernel_web.prx,__error[libkernel_web, libkernel], exit 0xc0000139, same[libkernel_web, libkernel, libc], exit 0libkernel_sys.prx,getpagesize(k+AXqu2-eBc)[libkernel_sys], exit 0xc0000139[libkernel_sys, libkernel, libc], exit 0libkernel_web.prx,getpagesize[libkernel_web, libkernel], exit 0xc0000139[libkernel_web, libkernel, libc], exit 0libkernel.prx,__error(control)[libkernel, libc], exit 0[libkernel, libc], exit 0On this head
ctest -R "^(entry_stub|windows_dependency_diagnostics)$" --repeat until-fail:3: both pass every repeat. Not run: a retail title.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T07:43:32Z.
Thanks for running the updated head against the variant-only
__errorandgetpagesizecases. The results distinguish the fix from the base on bothlibkernel_sys.prxandlibkernel_web.prx, while the canonicallibkernel.prxcontrol stays green. The repeated Windows diagnostics test adds useful coverage too; the limitation to synthetic imports rather than a retail title is clear.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T19:24:01Z.
Checked the provider order (requested variant, canonical libkernel, libc) in
WindowsEntryStubBuilderand the inferred dependency list inReadLibrariesfor both kernel variants without duplicates; both new tests fail on main. The Windows runs by @ycbuzi and @UnhealthyKraken confirm the base failing and the head resolving; merged.