fix(relinker): resolve kernel-family exports for libkernel-declared imports #12430
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12430"
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 akkadbakkad89 on 2026-10-28T13:26:04Z.
What
Windows scoped imports resolve through a per-import search order over the modules the converted executable actually loads. For kernel-family symbols that order had a one-way fallback added in #8853: a
libkernel_sys.prxorlibkernel_web.prximport also searcheslibkernel.prx. Nothing covers the other direction — alibkernel.prx-declared import never seeslibkernel_sys.prx/libkernel_web.prxexports, even though the same NIDs are resolved on console and, on Linux, through the dynamic linker's global symbol scope.Two places make up the search path on Windows and both learn the whole family:
WindowsImportBuilder::ReadLibraries— the DT_NEEDED augmentation now loads all oflibkernel.prx,libkernel_sys.prx,libkernel_web.prx(andlibc.prx) whenever any family member is needed, not only for the sys/web variants.WindowsEntryStubBuilder— a scoped import declared on any family member searches the other two members before falling through tolibc.prx.GTA V (PPSA04264) hits this through its bundled
libSceAmpr.sprx, which declareslibkernel.prxfor thesceKernelWrite*Command/sceKernelCallIndirectBuffer*/sceKernelGiveDirectMemoryToMapper/sceKernelWaitCommandBufferCompletionfamily — all implemented inlibkernel_sys.prx. On Windows those imports died at startup (unresolved ELF import ... from libkernel.prx), forcing either diagnostic stubs or--lazy-binding --skip-sce-module. With the change the executable binds them to the reallibkernel_sysimplementations.Tested
Windows 11, MinGW GCC.
ctest -R "windows|entry_stub|kernel": 31/31 pass, includingwindows_kernel_variant_sysandwindows_kernel_variant_webwith three new cases —kernel-requests-variant(libkernel-declared import resolves through the variant),variant-requests-other(sys-declared resolves through web and vice versa) andkernel-prefers-declared(the declared module still wins).entry_stubandwindows_dependency_diagnostics_testsexpectations updated for the augmented dependency lists. Fullbuild-relinkersuite: 377/388 pass; the 11 failures are environmental — Windows Security quarantines freshly linked executables mid-test (relinker.exe, temp test binaries;WinError 225/FileNotFoundError), nested configures lack ninja on PATH, and two tools tests need GNU objdump / a git repository visible to the Windows toolchain. None touch the changed code.GTA V PPSA04264 v01.011.001 on Windows:
relinker --windows eboot.elfwith the bundled module set converts cleanly and the game boots past the previous ~5 s unresolved-import/module-init stop — RAGE worker threads spawn, texture writebacks flow, controller connects; run killed at 90 s while still alive. Zerounresolved ELF importlines. (The title's later story-mode blocker is a separate guest-side issue tracked in #12247.)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)WindowsEntryStubBuilder.cpp; this branch lands after it and is rebased on currentmainmeanwhile)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T13:54:59Z.
Review: COMMENTED
Review of 47fef9040f, run on macOS arm64 (Apple clang). The Windows lane ran the generated PE startup stubs under Wine 11.0. The fix direction looks right to me, but there is one blocking regression in what the startup has to load.
What I ran
ctest378/378. Off Windows onlyentry_stubcovers this change;windows_dependency_diagnosticsandwindows_kernel_variant_*are registeredif(WIN32)only.test_windows_kernel_variant_imports.pyrun unchanged except for two harness edits: the startup executables go throughwine, and themissing-style checks matchexception 0xc0000139in stderr, because Wine exits with 57 instead of the NTSTATUS. With bothlibkernel_sys.prxandlibkernel_web.prxit printsruntime, precedence and isolation checks passed, and all 12 labels match the expected values (11/22/33/44 and the unresolved cases).kernel-requests-variantcase FAILS withunresolved ELF import shared from libkernel.prx, and the search list there is only libkernel.prx plus libc.prx. The test does exercise the change.check_conventions --base upstream/maingives 0 errors. The one warning isdebt-length: relinker.md line 25 is 945 characters on main and 1016 here. Trimming it under 1000 would clear it. merge-tree onto750cf6cf48is clean. pr_overlap: 32 file-sharers merged clean. #5021, #10861 and #11192 conflict with main ondocs/dev/debt/relinker.mdonly.Blocking: the variants become mandatory loads
Buildsetsimported[index] = truefor every entry of a scoped import's search order. When a library isimported, the startup does a hardLoadLibraryExWand fails withFailed to load module. The GetFileAttributesW-optional path only covers libraries that are not imported. With this PR, everylibkernel.prximport putslibkernel_sys.prxandlibkernel_web.prxinto its search order. Alibkernel_sysimport also puts inlibkernel_web, and the other way round. So all three become required.I reproduced it under Wine with a
libs/that has the variant,libkernel.prxandlibc.prx, i.e. the settest_windows_timed_join_imports.pystages:libkernel_sys.prxFailed to load module ...\libs\libkernel_web.prxlibkernel_web.prxFailed to load module ...\libs\libkernel_sys.prxlibkernel.prx(libs: libkernel + libc)Failed to load module ...\libs\libkernel_sys.prxA release
libs/has all three, so packaged runs and your GTA V run don't hit this. A partiallibs/does: tests that stage a subset, and users with a trimmed or self-built folder.guest_timed_join_import_libkernel_{sys,web}copy exactly variant + libkernel + libc, so I expect them to break on the Windowswindowsjob. I could not run them here because they need the full libs build.Suggested fix: a family member reached only through the fallback should be optional, the way
libc.prxalready is when it isn't imported directly. The declared module keeps its hard requirement.libkernel.prxstays required as on main, because a variant import has always required it.Results with the diff applied:
entry_stuband the full ctest pass, 378/378.A regression test would be one more case in
test_windows_kernel_variant_imports.pythat leavesotherout oflibs/and still expects 11. The second loop already writesother, so the case only has to skip that file.Non-blocking
ReadLibrariesnow addslibkernel_sys.prxandlibkernel_web.prxfor everylibkernel.prxdependency. That adds them to the DT_NEEDED-derived list of almost every title (see the updatedWindowsDependencyDiagnosticsTestsexpectations). With the fix above that costs a probe, not a failure.ReadLibrarieshunk is needed for this case: I reverted only it and kept the stub change, andkernel-requests-variantgoes RED. The search order cannot reach a library that is not in the list.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T14:02:16Z.
Review: CHANGES_REQUESTED
The new family search order makes sibling variants mandatory DLLs during startup. In
WindowsEntryStubBuilder::Build, every entry in a scoped import'sorderis markedimported[index] = true; the load loop then hard-loads imported host modules withLoadLibraryExW. Since this change adds both sibling variants to each kernel-family order, an executable importing fromlibkernel_sys.prxnow fails whenlibkernel_web.prxis absent, and alibkernel.prximport fails when either sibling is absent. This is a regression for partiallibs/directories and the test staging pattern used by the timed-join imports.A reviewer reproduced this with the variant + canonical kernel + libc set: startup succeeds on
mainbut fails on this head withFailed to load module ...libkernel_web.prx(or the other sibling), even though that fallback provider need not be present to satisfy any import. The existing new scenarios always write the sibling variant intolibs/, so they do not cover this case. Please keep fallback family members optional when they are not directly required, while still probing/searching them if present, and add a regression case that omits the unused sibling. The declared import library should remain a hard dependency. I am requesting changes for this startup regression; the bidirectional lookup itself is otherwise a useful fix.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T14:12:58Z.
Review: CHANGES_REQUESTED
Thanks, the bidirectional lookup is the right direction. One blocking regression, already reproduced by @rooklz under Wine and flagged by @MarcZX10:
core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp:242-245— every entry of a scoped import'sordersetsimported[index] = true, and imported host modules are hard-loaded withLoadLibraryExW. Now that each kernel-family order contains both siblings, an import fromlibkernel_sys.prxfails withFailed to load module ...libkernel_web.prxwhen that file is absent (and vice versa); alibkernel.prximport fails when either variant is absent. Onmainthe samelibs/(variant +libkernel.prx+libc.prx, asguest_timed_join_import_libkernel_{sys,web}stage it) starts fine. Fix: family members reached only through the fallback must stay optional (probed and searched if present, skipped if absent), while the declared module andlibkernel.prxfor variant imports stay required as onmain. @rooklz posted a working diff in the thread (a separatefamilyFallbacksflag consulted by the load loop and the searched-libraries listing); it passed all 12 labels and the full ctest for them.core/relinker/relinker/tests/test_windows_kernel_variant_imports.py:50,83— every case writesotherintolibs/. Add a case that omits the unused sibling and still expects 11 (variant) / 22 (libkernel.prx), so this regression is pinned.docs/dev/debt/relinker.md:25— the entry is now 1016 characters and trips thedebt-lengthwarning; please trim it under 1000.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T15:30:45Z.
Review: CHANGES_REQUESTED
The latest head
4aea329a24a89bf6ce9c6ab87a93c07303338abeadds the sibling-provider precedence case, but the blocking missing-sibling startup regression is still present in the production diff.ReadLibrariesstill unconditionally appends all three kernel-family names when any one is present, andWindowsEntryStubBuilderstill places every sibling in the import search order. The startup stub therefore treats those fallback modules as required DLLs. The new synthetic case has all three family members present, so it does not cover the reported partial-libs/failure.Please make fallback family members optional when absent, while keeping the declared library and the existing required dependency hard-loaded, and add a case that omits an unused sibling. The bidirectional lookup and new sibling-precedence case can remain; this review is for the unresolved startup regression only.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T18:01:09Z.
Review: CHANGES_REQUESTED
The new commit only adds the sibling-precedence case, with all three kernel-family modules present, so the blocking point from the previous review is unchanged:
core/relinker/elfpatcher/src/windows/WindowsImportBuilder.cpp:59-63andcore/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp:186-190—ReadLibrariesstill appendslibkernel_sys.prxandlibkernel_web.prxunconditionally, and the entry stub puts them inorder, which marks them imported and hard-loads them withLoadLibraryExW. With a partiallibs/(variant +libkernel.prx+libc.prx, as onmain) startup fails withFailed to load module ...for the absent sibling. Confirmed by @rooklz (Wine) and by @eliasbruno124-dev on native Windows (test_windows_timed_join_imports.pyfails for both variants with this patch, passes with thefamilyFallbacksflag @rooklz proposed). Family members reached only through the fallback must stay optional (searched if present, skipped if absent); the declared module andlibkernel.prxfor variant imports stay required.core/relinker/relinker/tests/test_windows_kernel_variant_imports.py:50,85— every case writes the unused sibling intolibs/. Add a case that omits it and still expects 11 (variant) / 22 (libkernel.prx).docs/dev/debt/relinker.md:25— the entry is over 1000 characters and tripsdebt-length; please trim it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T00:38:37Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The new head fixes the missing-sibling load regression and adds the corresponding cases, but merge order with four overlapping PRs is unresolved and this branch is behind current
main.What I ran
d87be8bac8b81f4282009884dd670bbddface349; its merge base with currentmain3a2b91981651569163768854a1fcdc7193b6667bis750cf6cf487f948017295b1f3717af6f886f0f85. The merge preview against currentmainis clean, with no changed-path overlap since that base.6.1.190-1; GCC 12.2.0, CMake, Ninja, Python 3.11.2. No Wine was available for local Windows runtime tests.Results
entry_stubCTestILLEGALmaingit diff --checkmainmainWindowsEntryStubBuilder.cppRaw output
Build completion:
Focused CTest:
Full CTest summary:
Conventions:
git diff --checkexited 0 with no output. The current-main merge preview was clean; its tree hash wascc3f5dde54fcce439f7842fe6753c84b6783596f.Overlap scan excerpt:
Pairwise merge-preview conflicts:
The exact-head GitHub check run reports
relinker (ubuntu-latest, g++),relinker (windows-latest, g++), bothrelinker (macos-latest, clang++)jobs,relinker-asan,eligibility,labels, andconventionsas success. The standalonewindows,linux,register-context, andwrite-watchchecks are skipped.Negative control
Findings
Blocking
WindowsEntryStubBuilder.cpp. The PR checklist currently saysDepends on: none, and I found no recorded merge-order agreement in this thread. Please agree with the affected authors which change lands first and record the applicable sequence inDepends on; the current conflicts need to be resolved on the selected integration order.750cf6cf487f948017295b1f3717af6f886f0f85, while currentmainis3a2b91981651569163768854a1fcdc7193b6667b. Although the preview is clean and no touched path changed onmain,CONTRIBUTING.mdrequires branches to stay up to date withmain. Please rebase onto currentmainand refresh CI before merge.Non-blocking
entry_stubtest passes locally; exact-head hosted relinker CI passes on Linux, Windows, and macOS.ILLEGAL; the changedentry_stubtest passes. I did not treat these failures as defects in this PR.Sources
Not verified
ILLEGALfailures remain unexplained locally and are outside the changed test path.To get this to a good state
Agree and record an integration order for the four overlapping PRs, then rebase onto current
mainand resolve the resulting conflicts. Keep the missing-sibling tests and rerun the same build, CTest, conventions, overlap, and hosted checks on the new head; I will re-run the local checks listed above.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:20:12Z.
Review: APPROVED
Re-checked — looks good
The author’s new dependency order resolves the overlap blocker, the rebase preserves the reviewed patch, and the exact-head focused tests plus GTA V bring-up evidence support the reverse kernel-family fallback; I found no remaining blocking issue in the current-main preview.
What I ran
f2b7333ae28c4b36613fa094ce9a18fa17eb31efagainst currentmain52c09d567d2fa453494dd720fcf53a98149468e4.git merge-tree --write-treeand inspected changed paths since the merge base.Results
3d6ba0ff33...docs/dev/debt/relinker.md, with a clean merged previewwindows,entry_stub, andkernelcases pass, including the three new kernel-family routing casesRaw output
Negative control
Findings
Blocking
Non-blocking
Sources
Not verified
To get this to a good state
Land the four declared GS-access prerequisites first, then refresh this branch onto current
main, rerun the focused tests/conventions on that final stack tip, and update the bring-up discussion when the result changes.