fix(relinker): load libraries searched for unmatched Windows imports #3970
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3970"
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-11T20:10:57Z.
What
Carries David's fix for #3369, preserving his original commit author. Windows relinking now retains host libraries in the load list when an unmatched import can be searched in any host library and its module name does not identify a needed library. This fixes the case where a provider such as
libSceAppContent.prxwas omitted because the import module had a different name.The change leaves the existing optional diagnostic for a missing, unused dependency available. A follow-up commit restores its string because the skip path still references it.
Tested
tools/check_conventions.py --base upstream/mainandgit diff --checkpass.windows_import_modulesandguest_module_identitypassed five repetitions, and the relinker-only suite passed 105/105 on Windows. Their title check reports Middle Ages Ping Pong progressed beyond its prior unresolved import and stopped later on a shared-memory limitation; it was not a complete title run.Checklist
mainDepends on: none
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-11T22:05:50Z.
Windows relinker CI fails:
relinker (windows-latest, g++)fails inwindows_import_moduleson this PR:The new
std::fill(imported.begin() + guestModules.size(), imported.end(), true)marks every host library for loading, including the missingunused.prxthatmaincorrectly skips. The PR's own run was Linux-only, so this Windows-only failure didn't show up there.The condition is also very broad: one unmatched module with no placed library, plus one host import, loads every DT_NEEDED library. Could it be narrowed to the libraries that actually export one of the unmatched NIDs?
AI-assisted: yes. Written with AI assistance (Claude Code); I reviewed it.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T22:09:43Z.
The previous Windows run exposed that an unscoped import with no declared module could leave an empty entry in UnmatchedImportModules, causing the startup stub to load unrelated native dependencies. I changed the reader to ignore empty declared-module names. Locally, the relinker builds with GCC 12.2 and the windows_import_modules test passes under Linux CTest (1/1). That Linux run does not execute the test Windows-only generated executable case; the new Windows CI run will validate that path.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T22:32:36Z.
I traced the Windows CI failure to unscoped imports whose guest export names include symbol suffixes (for example,
shared#A#B) while the executable import uses the base name (shared). The startup stub now matches guest exports by that base name, so unrelated missing dependencies are not loaded for a guest-resolved import. Linux Release relinker build succeeded, andwindows_import_modulespassed locally (1/1). The updated Windows CI run is queued and will verify the platform-specific execution.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T23:02:35Z.
Follow-up pushed as
2cade4516. The Windows failure was caused by marking every native dependency as required for unscoped imports, which made a missing optionalunused.prxfatal. Those libraries remain in the symbol search order, but an absent optional dependency can now be skipped. Local Linux release build andwindows_import_modulespass; awaiting the Windows CI rerun.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T23:40:35Z.
The Windows CI failure was from the skip-SCE-module host import case: an absent native dependency must stay fatal when no guest module provider is known. This follow-up passes the skip-SCE-module mode into the Windows entry stub and keeps that strict check scoped to unplaced unscoped host imports.\n\nValidation: the Linux relinker CTest suite passed 114/114, including
windows_import_modules; current Ubuntu and Windows relinker CI jobs and conventions pass. The macOS relinker and Intel context jobs are still queued.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T00:10:58Z.
Review: COMMENTED
Verified on Linux — the effect is visible in the produced artifact (6 of the 9 new cases emit a different PE), and the Windows job in this PR's own CI is what runs the assertions that catch it.
Head
036aa2dd, merged onto my checkout'supstream/mainat752db7da(145 commits ahead of this PR's own GitHub base0a8b1d32). The API reportsMERGEABLE.What the change does, measured rather than read
I built
relinkertwice — once at the head, once with all nine implementation files atupstream/main(everything except the test) — and ran the test's own fixture machinery with a persistent work directory in place of itsTemporaryDirectory, then hashed every produced file:All six are cases this PR adds (the whole
host-provider-0..8loop is new); the other 288 of the 294 files are byte-identical, which is the regression statement for the surrounding behaviour. Sizes match for every one of the six (275,968 and 310,784 bytes). Besides the stub body, exactly two derived fields move — both by the same 20 bytes:and in the stub body itself, at file offset 269074:
So the control's stub guards the load behind
cmp eax,0x7e; je …where the head's reaches the call directly — the retained entry changes which path the stub takes. That is a static reading; the runtime difference is exactly what the assertions below test. Note that no library-name string is added to the PE (I checkedunused.prxin both ASCII and UTF-16 — absent in both), so an assertion on the name would find nothing here.What the Linux arms do and do not prove
ctest --test-dir build -R '^windows_import_modules$'→ head 1/1 Passed (~0.10 s) and control 1/1 Passed — identical, because the new outcome assertions sit insideif os.name == 'nt'. The block'sassert result.returncode == 0calls do run on Linux (the relink still has to succeed), but nothing on Linux asserts the retention itself, so the Linux suite is not coverage for this change.guest_module_identity,guest_needed_modules,guest_symbol_names,windows_working_directory→ 4/4 Passed.--skip-sce-moduleis not new: it is already parsed onmain(core/relinker/main.cpp), so the test does not depend on the flag arriving with this change.The coverage is better than the description says — and this PR's own job has already proved it bites
"The Windows-only import-loading scenarios are not exercised on Linux" is true, but it reads as though nothing runs them. The
relinkerjob is not gated the waylinux/windowsare (those reportskippingon a PR); it runs onwindows-latesthere, with-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, and the file registerswindows_import_moduleswith no OS guard. From this PR's head run (38184891028, job114605106512):1.41 s against ~0.10 s locally is the produced
.exes being executed — the part only Windows can do. And the job has already caught a regression in this very PR: on commit2cade451the same test failed on the same runner,which is the new assertion, failing on a real defect rather than by plumbing. That pair of lines is worth more in the description than the current caveat.
One question about intent —
bae3a2f8says "ignore empty unmatched import modules", but only the reader does. That commit touchesGuestImageReader.cppalone (it is the hunk adding&& !name.empty()), whileRelinkerPipeline.cpp:353still inserts the declared module unconditionally, so an empty string reachesUnmatchedImportModuleswhenever a ref has no library and no declared module — whichDeclaredImportModulereturns by design in both cases (domain/ImportModule.hpp:21-23). On the stub side the set's emptiness is itself a condition (WindowsEntryStubBuilder.cpp:184,unmatched.empty() || …): an empty member cannot flip the already-empty case (that disjunct was already true), but where every real unmatched module is among the searched libraries, the disjunct is false and theany_ofat:185finds no library whose stem is"", sounplacedModulebecomes true. I could not reach that state from the suite, and the Windows job is green, so this is a question about intent rather than a defect I can demonstrate: was the pipeline's unconditional insert meant to keep the empty value, or to drop it the way the reader now does?Not verified, so it is not claimed: the title run (the issue reports a partial one that stopped later on a shared-memory limitation), and Windows execution by me — the Windows evidence here is the CI log above.
Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T00:11:19Z.
One clarification to my review above, having now read the thread. @MarcZX100's account of the earlier Windows failure already names this area — "an unscoped import with no declared module could leave an empty entry in
UnmatchedImportModules, causing the startup stub to load unrelated native dependencies". My question is narrower than that and is not answered by it, so here is the delta precisely:bae3a2f8guards the consumer:GuestImageReader.cppnow computes the declared module only for a non-empty name.RelinkerPipeline.cpp:353, which still inserts whateverDeclaredImportModulereturns — and that returns{}by design when the modules map is empty or the symbol has no#(domain/ImportModule.hpp:21-23).So an empty member can still reach the set the stub reads at
WindowsEntryStubBuilder.cpp:184. If the intent is that no empty member ever arrives there, the pipeline's insert is where I would drop it; if the pipeline is meant to keep it and the stub meant to ignore it, that answers the question and I will leave it.Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T00:35:29Z.
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/include/elfpatcher/windows/WindowsElfPatcher.hppL11, L17core/relinker/elfpatcher/src/windows/WindowsPePatcher.cppL44core/relinker/main.cppL151Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T07:36:47Z.
Closing: #3369 is fixed on main by #3365 (the run on main
8b679d8din the issue loadslibSceAppContent.prx), and this adds a second load rule on top of it for--skip-sce-moduleonly. Reopen with a title that still stops on an unmatched import on current main.Pull request closed