Windows relinker: needed host libraries are no longer loaded when only unnamed imports use them (unresolved ELF import at start-up) #3367
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 xXPBSXx on 2026-10-11T09:09:13Z.
AI-assisted (Claude Code), reviewed by the contributor.
Regression on
main(Windows): Hotline Miami (PPSA09682, Unity, from the owner's own dump) relinks without audit gaps (0 absent imports) and then fails at start-up:VANhIWcqYakissceAppContentAddcontMount, whichlibSceAppContent.prx(built by this repository) exports. The title imports it without a library name, andlibSceAppContent.prxis one of its needed libraries.Bisect:
git bisectover the 23 relinker commits between06da1176(good) andccf9ff904(bad), relinking the same ELF each step and starting it, gives7755e1d0("leave needed libraries nothing imports from out of the start-up load list", part of #3129) as the first bad commit. It stops loading every needed host library that no named import uses (if (index >= guestModules.size() && !imported[index]) continue;). Butimportedis only set for imports that carry a library name, and an import without one can be provided by any needed library. All 19 titles I have relinked contain unnamed imports (4 to 124 each), so any title whose unnamed imports come from a host library that no named import uses is affected. I only reproduced it on Hotline Miami; I did not run the others on a build without the fix.Fix: branch https://github.com/xXPBSXx/AnyPS5/tree/fix/relinker-windows-load-needed-libraries-with-unnamed-imports (one commit on
mainccf9ff904). It goes back to loading these libraries and tolerating only a library file that does not exist (error 126), which is what the original library-skip change did and keeps the Party.prx case from #2776 working (unused.prx -> not found; nothing is imported from it). The existingtest_windows_import_modules.pyexpectation about that message is restored, and a new case (unnamed-import-from-host-library) fails on currentmainwithunresolved ELF import sharedand passes with the fix. Allwindows_*ctest targets and the conventions check pass.With the fix Hotline Miami (relinked with
--module-dir Media/Pluginsfrom #846) gets past this point and past the PSNCore start-up fault I reported on #846; it then stops later with a call through a null function pointer, which I have not analysed.Not tested: the Party.prx scenario from #2776 with the actual RE4 files on this fix (only the unit test's equivalent). Linux behavior is unchanged by this change (the code is Windows-only).
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T09:14:56Z.
Windows check of the fix (
d5c087d21, merged onto currentmain), WinLibs GCC 15.2.0 r7, Release: all 12windows_*tests pass, includingwindows_import_moduleswith the newunnamed-import-from-host-librarycase. Running the updatedtest_windows_import_modules.pyagainstmain's relinker fails exactly as you describe:a needed host library must be loaded for an import without a library name,FAIL: unresolved ELF import shared.For context, since I wrote the first two commits of #3129: they kept loading every needed library and only tolerated error 126 for a file that doesn't exist, which is what got Lodoss, RE4 and Road of Death past start-up.
7755e1d0then stopped loading needed libraries that no named import uses, andimportedonly tracks named imports, so unnamed imports lost their host libraries. Your change goes back to the load-and-tolerate-126 behaviour, which looks right to me.Thanks for bisecting it.
AI-assisted (Claude Code); I ran the above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T09:26:07Z.
One thing to sort out before this goes up as a PR: on #3129, @oneandonlydean asked for exactly the opposite of tolerating the missing file.
That review describes this regression. It was left on
mainwhen #3129 merged:imported[index]is still only set when!import.Library.empty(), andskippedModuleis still unused.So the fix that review asks for is to mark every library in an import's search order, and to keep failing on a missing needed library. In
WindowsEntryStubBuilder.cpp, that means dropping theif (!import.Library.empty())condition in front ofimported[index] = true, with no change to the 126 handling. Your newunnamed-import-from-host-librarycase covers it.The catch is #3129's own
missing-unused-dependencycases. With an unnamed import (('shared', None)), the search order includesunused.prx, so under that rule it stays in the load list and the start fails. That is the RE4Party.prxsituation from #2591/#2776 again, if RE4'sParty.prxis only searched by unnamed imports. Whether such a library may be skipped needs a decision from the maintainer: for example, resolving unnamed imports at relink time against the export tables, if the relinker has them for host libraries. That's better settled on this issue than in a PR that brings back the 126 tolerance.Happy to carry whichever version is agreed, and to run it on Windows.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T09:30:25Z.
@AchrafReyani you're right, and I should have reread #3129 before saying the 126 tolerance looked right. oneandonlydean's review there rules that fallback out, so my "looks right to me" above doesn't hold. The Windows test results stand; the approach is what needs deciding.
Reading
WindowsEntryStubBuilder.cppon currentmainmatches what you describe: an import with an emptyLibraryputs every needed library in its search order (import.Library.empty() || ...), butimported[index]is only set when!import.Library.empty(). The only other marking is my second commit's stem match against declared-but-unmatched modules.One consequence for the strict version: since an unnamed import searches every needed library, marking its whole search order marks all of them, so with even one unnamed import nothing is ever skipped. xXPBSXx found unnamed imports in all 19 titles they relinked (4 to 124 each), so the strict rule would most likely bring back the Lodoss, RE4 and Road of Death start-up failures from #2591, not just the
missing-unused-dependencytest cases.So I think the real choice is between allowing the 126 tolerance after all, or narrowing what an unnamed import searches at relink time (by the module it declares, or by the host libraries' export tables as you suggest), so that only libraries that can actually provide it get marked. The second keeps the rule from #3129 and would make the skip safe, but it's a bigger change and needs to know which host library exports what.
AI-assisted (Claude Code); I read the code on current
mainfor the above.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T17:36:38Z.
I checked the current
maincode against the startup regression described here. Merged PR #3365 (2faa5dd, “load needed providers for unscoped Windows imports”) adds anunscopedImportscheck when any ELF import has no library name. The Windows entry stub then keeps the needed host libraries in its load list and includes them in the unresolved-import search diagnostics, even when no named import marks that library as used. The PR also added a Windows import-module regression for this case.That appears to address the missing-provider path reported here; the issue and its attached fix discussion predate the merge. I have not run Hotline Miami myself. Does it still fail at
sceAppContentAddcontMountwhen relinked and launched from currentmain? If the stop is gone, this can be closed as fixed by #3365. If it persists, please add the current-main log showing which provider is missing so the remaining case can be distinguished from the original regression.The separate question of which absent optional providers may be skipped on error 126 is still being discussed in #3579; I am not treating that as resolved by this report.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T18:36:53Z.
@MarcZX100 I can't run Hotline Miami either, but two things point to it being fixed by #3365:
maina11c8f7fon Windows, has Hotline Miami get past start-up and reach level 1 (it stops later inLoading.PreloadManager, which is a different problem). That's the stop this issue was about.test_windows_import_modules.pyatd5c087d2) against currentmain's relinker on Windows (WinLibs GCC 15.2.0 r7, Release). Itsunnamed-import-from-host-librarycase, which failed againstmainwhen I ran it this morning before #3365 merged, now passes. The only assertion in that file that fails is the expected text of the branch's own log line for a skipped library (unused.prx -> not found; nothing is imported from it), whichmaindoesn't print;main's own version of that case expects no mention ofunused.prxand passes.@orishamir saw the same with Middle Ages Ping Pong on #3369. So I'd say this can be closed as fixed by #3365, unless @xXPBSXx sees something different. The 126 question stays with #3579, as you say.
AI-assisted (Claude Code); I ran the test above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T21:16:40Z.
Fixed by #3365: Hotline Miami (PPSA09682) gets past this stop on main (#3805).