Windows relinker: needed host libraries are no longer loaded when only unnamed imports use them (unresolved ELF import at start-up) #3367

Closed
opened 2026-10-11 09:09:13 +00:00 by xXPBSXx · 6 comments
xXPBSXx commented 2026-10-11 09:09:13 +00:00 (Migrated from github.com)
Contributor

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:

FAIL: unresolved ELF import VANhIWcqYak
Searched libraries:
  ... (the list has no libSceAppContent.prx)
GetLastError: 127

VANhIWcqYak is sceAppContentAddcontMount, which libSceAppContent.prx (built by this repository) exports. The title imports it without a library name, and libSceAppContent.prx is one of its needed libraries.

Bisect: git bisect over the 23 relinker commits between 06da1176 (good) and ccf9ff904 (bad), relinking the same ELF each step and starting it, gives 7755e1d0 ("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;). But imported is 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 main ccf9ff904). 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 existing test_windows_import_modules.py expectation about that message is restored, and a new case (unnamed-import-from-host-library) fails on current main with unresolved ELF import shared and passes with the fix. All windows_* ctest targets and the conventions check pass.

With the fix Hotline Miami (relinked with --module-dir Media/Plugins from #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).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5799678582 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3367). Originally posted by [xXPBSXx](https://github.com/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: ``` FAIL: unresolved ELF import VANhIWcqYak Searched libraries: ... (the list has no libSceAppContent.prx) GetLastError: 127 ``` `VANhIWcqYak` is `sceAppContentAddcontMount`, which `libSceAppContent.prx` (built by this repository) exports. The title imports it without a library name, and `libSceAppContent.prx` is one of its needed libraries. **Bisect:** `git bisect` over the 23 relinker commits between 06da1176 (good) and `ccf9ff904` (bad), relinking the same ELF each step and starting it, gives `7755e1d0` ("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;`). But `imported` is 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 `main` ccf9ff904). 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 existing `test_windows_import_modules.py` expectation about that message is restored, and a new case (`unnamed-import-from-host-library`) fails on current `main` with `unresolved ELF import shared` and passes with the fix. All `windows_*` ctest targets and the conventions check pass. **With the fix** Hotline Miami (relinked with `--module-dir Media/Plugins` from #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).
Silverash-i8 commented 2026-10-11 09:14:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T09:14:56Z.


Windows check of the fix (d5c087d21, merged onto current main), WinLibs GCC 15.2.0 r7, Release: all 12 windows_* tests pass, including windows_import_modules with the new unnamed-import-from-host-library case. Running the updated test_windows_import_modules.py against main'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. 7755e1d0 then stopped loading needed libraries that no named import uses, and imported only 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107486099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3367#issuecomment-6107486099). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T09:14:56Z. --- Windows check of the fix (`d5c087d21`, merged onto current `main`), WinLibs GCC 15.2.0 r7, Release: all 12 `windows_*` tests pass, including `windows_import_modules` with the new `unnamed-import-from-host-library` case. Running the updated `test_windows_import_modules.py` against `main`'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. `7755e1d0` then stopped loading needed libraries that no named import uses, and `imported` only 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.
reyani-dev commented 2026-10-11 09:26:07 +00:00 (Migrated from github.com)
Author
Contributor

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.

Carrying on after a failed load is a fallback, which isn't allowed here, and the relinker already knows which libraries those are.

A library that an import is still searched in has to stay in the load list. At 7755e1d0 it doesn't when the import has no matching library: WindowsEntryStubBuilder.cpp:127 marks a library only when import.Library is set [...]

That review describes this regression. It was left on main when #3129 merged: imported[index] is still only set when !import.Library.empty(), and skippedModule is 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 the if (!import.Library.empty()) condition in front of imported[index] = true, with no change to the 126 handling. Your new unnamed-import-from-host-library case covers it.

The catch is #3129's own missing-unused-dependency cases. With an unnamed import (('shared', None)), the search order includes unused.prx, so under that rule it stays in the load list and the start fails. That is the RE4 Party.prx situation from #2591/#2776 again, if RE4's Party.prx is 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107571230 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3367#issuecomment-6107571230). Originally posted by [reyani-dev](https://github.com/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. > Carrying on after a failed load is a fallback, which isn't allowed here, and the relinker already knows which libraries those are. > > A library that an import is still searched in has to stay in the load list. At 7755e1d0 it doesn't when the import has no matching library: `WindowsEntryStubBuilder.cpp:127` marks a library only when `import.Library` is set [...] That review describes this regression. It was left on `main` when #3129 merged: `imported[index]` is still only set when `!import.Library.empty()`, and `skippedModule` is 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 the `if (!import.Library.empty())` condition in front of `imported[index] = true`, with no change to the 126 handling. Your new `unnamed-import-from-host-library` case covers it. The catch is #3129's own `missing-unused-dependency` cases. With an unnamed import (`('shared', None)`), the search order includes `unused.prx`, so under that rule it stays in the load list and the start fails. That is the RE4 `Party.prx` situation from #2591/#2776 again, if RE4's `Party.prx` is 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.
Silverash-i8 commented 2026-10-11 09:30:25 +00:00 (Migrated from github.com)
Author
Contributor

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.cpp on current main matches what you describe: an import with an empty Library puts every needed library in its search order (import.Library.empty() || ...), but imported[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-dependency test 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 main for the above.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107602733 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3367#issuecomment-6107602733). Originally posted by [Silverash-i8](https://github.com/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.cpp` on current `main` matches what you describe: an import with an empty `Library` puts every needed library in its search order (`import.Library.empty() || ...`), but `imported[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-dependency` test 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 `main` for the above.
MarcZX10 commented 2026-10-11 17:36:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T17:36:38Z.


I checked the current main code against the startup regression described here. Merged PR #3365 (2faa5dd, “load needed providers for unscoped Windows imports”) adds an unscopedImports check 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 sceAppContentAddcontMount when relinked and launched from current main? 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111782184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3367#issuecomment-6111782184). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T17:36:38Z. --- I checked the current `main` code against the startup regression described here. Merged PR [#3365](https://github.com/boykopovar/AnyPS5/pull/3365) (`2faa5dd`, “load needed providers for unscoped Windows imports”) adds an `unscopedImports` check 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 `sceAppContentAddcontMount` when relinked and launched from current `main`? 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](https://github.com/boykopovar/AnyPS5/pull/3579); I am not treating that as resolved by this report.
Silverash-i8 commented 2026-10-11 18:36:53 +00:00 (Migrated from github.com)
Author
Contributor

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:

  • @xXPBSXx's own #3805, on main a11c8f7f on Windows, has Hotline Miami get past start-up and reach level 1 (it stops later in Loading.PreloadManager, which is a different problem). That's the stop this issue was about.
  • I reran the regression test from xXPBSXx's fix branch (test_windows_import_modules.py at d5c087d2) against current main's relinker on Windows (WinLibs GCC 15.2.0 r7, Release). Its unnamed-import-from-host-library case, which failed against main when 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), which main doesn't print; main's own version of that case expects no mention of unused.prx and 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112334002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3367#issuecomment-6112334002). Originally posted by [Silverash-i8](https://github.com/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: - @xXPBSXx's own #3805, on `main` `a11c8f7f` on Windows, has Hotline Miami get past start-up and reach level 1 (it stops later in `Loading.PreloadManager`, which is a different problem). That's the stop this issue was about. - I reran the regression test from xXPBSXx's fix branch (`test_windows_import_modules.py` at `d5c087d2`) against current `main`'s relinker on Windows (WinLibs GCC 15.2.0 r7, Release). Its `unnamed-import-from-host-library` case, which failed against `main` when 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`), which `main` doesn't print; `main`'s own version of that case expects no mention of `unused.prx` and 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.
oneandonlydean commented 2026-10-11 21:16:40 +00:00 (Migrated from github.com)
Author
Contributor

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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113851142 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3367#issuecomment-6113851142). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T21:16:40Z. --- Fixed by #3365: Hotline Miami (PPSA09682) gets past this stop on main (#3805).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3367
No description provided.