Skip to content

fix(relinker): bind Windows imports to their declared modules - #684

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
nicolasabosch:fix/windows-import-module-binding
Oct 7, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
nicolasabosch:fix/windows-import-module-binding

Conversation

@nicolasabosch

@nicolasabosch nicolasabosch commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What

Windows startup currently strips the module qualifier from ELF imports and searches every loaded library. A title's bundled libc.prx shim can then intercept imports explicitly belonging to a system module with its placeholder exports.

Preserve DT_SCE_IMPORT_MODULE IDs through executable and guest-module imports and bind each qualified import to its declared module. Guest filenames and SONAME aliases identify providers; module names with underscore/dot or -module filename differences map to declared DT_NEEDED dependencies, with exact matches preferred and ambiguous aliases rejected; duplicate exports in different Windows guest modules are allowed when imports select a provider explicitly. Unqualified ambiguous guest imports and malformed/unknown module IDs are rejected. Missing symbols still fail at startup. Host system modules may resolve their shared runtime implementations from host libc.prx; that path never searches unrelated guest modules. TLS resolver selection follows the same module scope. Inputs without module metadata retain the legacy lookup behavior; Linux keeps its existing duplicate-export policy.

Rebased over #672 and #698 on main, retaining Linux host/guest symbol isolation, ambiguity checks and absolute-symbol handling.

Tested

Checklist

In-game screenshots

Two E1M1 gameplay captures from the integrated DOOM Shareware homebrew run, showing the final integration build and movement/shooting. The integration dependencies and limits are described above.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, the idea of binding each qualified import to its declared module makes sense to me, and the new test covers the cases you list. I found one problem with a real title, though.

I relinked PPSA21564 for Windows with this branch (--windows --to-intel, the same input that relinks fine on main), and it stops with:

FAIL: Import module is not a dependency: libSceSaveData_native.prx

The module names in DT_SCE_IMPORT_MODULE (0x61000045) aren't always the DT_NEEDED file name without .prx. PPSA21564's eboot names the module libSceSaveData_native, while its DT_NEEDED entry is libSceSaveData.native.prx. The same eboot needs libSceFont-module.prx and libSceFontFt-module.prx, and its string table has libSceFont and libSceFontFt but no libSceFont-module, so the first mismatch is probably not the only one. ImportModule appends .prx to the module name, and WindowsEntryStubBuilder then looks for that name among the dependencies, so the lookup fails for these.

Could the module ID be mapped to its DT_NEEDED entry some other way, or could a qualified import whose module has no matching dependency fall back to the current unqualified lookup? A case in test_windows_import_modules.py with a module name that differs from the file name (for example foo_native against foo.native.prx) would cover it.

On Linux nothing changes: PPSA21564's relinked eboot and guest modules come out byte for byte the same as on main, both with and without its bundled libc.prx in sce_module. windows_import_modules fails with main's relinker and passes with this one, and the full ctest passes with it merged on Linux. The Linux CI failure is the agc_driver_flat_cache_bits timeout that #677 has since fixed on main.

It conflicts with #698 in GuestModuleBuilder.cpp and core/relinker/CMakeLists.txt, and with #672 in core/relinker/CMakeLists.txt.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
@nicolasabosch
nicolasabosch force-pushed the fix/windows-import-module-binding branch from 0be543d to e96e9c1 Compare October 6, 2026 01:47
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 6, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for the alias mapping. foo_native against foo.native.prx and libSceFont against libSceFont-module.prx now resolve, the exact name still wins, and two dependencies with the same normalized name fail as ambiguous, which is what I'd expect.

I read PPSA21564's eboot dynamic table against ImportModuleName (59 DT_NEEDED entries, 59 DT_SCE_IMPORT_MODULE entries). Three now match that didn't before (libSceSaveData_native, libSceFont, libSceFontFt), but six still have no dependency with the same normalized name:

module name DT_NEEDED
libSceSaveDataDialog libSceSaveDataDialog.native.prx
libSceJson libSceJson2.prx
libSceAvPlayer libSceAvPlayer.native.prx
libSceAudiodec libSceAudiodec.native.prx
libSceMsgDialog libSceMsgDialog.native.prx
libSceAppContentUtil libSceAppContent.prx

ImportModule returns the unmatched name unchanged, so as far as I can tell WindowsEntryStubBuilder would still stop at Import module is not a dependency: libSceSaveDataDialog.prx for this title (I haven't rerun the Windows relink on this head; this is from the tables and the code). The module name is the provider's own module name rather than a file name, so suffix rules will keep missing cases like libSceJson/libSceJson2 and libSceAppContentUtil/libSceAppContent. Could a qualified import whose module matches no dependency fall back to the current unqualified search order, so the qualified binding only applies where it can be resolved? A test row with an unrelated name (for example module libFoo against libFoo2.prx) would pin that.

One smaller point, Linux only: in GuestModuleBuilder, main rejects two exports in the same module that strip to the same name (existing->second == images.size()). With the provider vector, a second export from the same module is now deduplicated silently instead. Was that intended? If not, keeping the same-module check on Linux before the push_back would preserve it.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#846 core/relinker/domain/include/domain/GuestRuntime.hpp L24
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L204

…odules

A qualified import whose module name matches no DT_NEEDED entry now uses
the unqualified search order instead of failing with "Import module is
not a dependency". Restore the Linux rejection of duplicate exports
within one guest module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@011010

011010 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Independent verification (relinker-only, builds anywhere).

Built the relinker from pr684 standalone on macOS 26.6.2 (arm64), Apple Clang 21, C++20:

  • test_windows_import_modules.py passes, and the other 20 relinker Python tests in the tree pass (21/21).

The warm-up test that this needs is confirmed by running the same test against main (c1241ad): it fails at the first fixture with

FAIL: Duplicate guest export after stripping #: shared in .../a.prx/prx/a.prx and .../a.prx/prx/b.prx

which is what this PR changes (bind each qualified import to its declared module and allow a duplicate export across Windows guest modules when the import selects a provider). With the change the fixture relinks.

Limits: no Windows host here, so I did not execute a relinked binary; the parse and relink behaviour is what I checked. No title involved.

@oneandonlydean
oneandonlydean merged commit 293d121 into boykopovar:main Oct 7, 2026
3 checks passed
adriadam10 added a commit to nicolasabosch/AnyPS5 that referenced this pull request Oct 11, 2026
… third-party results

Drops the stale pending-dependency note (boykopovar#553 boykopovar#683 boykopovar#684 boykopovar#685 are merged), adds the
package source and the Linux, extended-gameplay, save/load and audio results
reported in the thread, and replaces the cold-start note with the measured cause.
The UCRT diagnostic note is removed: no report on current main.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants