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

Merged
nicolasabosch merged 3 commits from upstream-pr/684 into main 2026-10-07 02:16:04 +00:00
nicolasabosch commented 2026-10-05 15:18:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-05T15:18:19Z.


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

  • Windows 11, bundled MinGW, Release, rebased on main fe98276f: all 28 relinker CTest cases pass. The new foo_native / foo.native.prx and libSceFont / libSceFont-module.prx fixtures reproduce the reported failure before the fix and now convert and run correctly, including imports in guest initializers. Exact-match precedence and ambiguous alias rejection are covered. PPSA21564 itself was not available locally; no direct retest of that title is claimed.

  • The new test converts and executes synthetic Windows binaries with colliding providers returning different values, a SONAME alias, and a guest initializer. It checks wrong-provider and missing-symbol startup failures, an unavailable module, invalid qualifiers/IDs, and ambiguous unqualified imports.

  • Integration with #683 (runtime exports), #685 (raw AGC compute), and #553: the original integration based on af92452f built and passed 290/290 CTest tests; DOOM Shareware homebrew PPSA99666 01.001.000 reached E1M1 and responded to movement and shooting. #614 is already on main. No game files added or modified.

  • Updated integration on main fe98276f with the repaired #683/#684/#685 and #553: full build plus the runtime libs target succeeded; all nine focused integration tests passed. DOOM Shareware reached E1M1 again with movement and shooting through AGC compute presentation. Profiling recorded 3,798 dispatch-cache hits in 3,800 dispatches with zero evictions. This is cache-use evidence, not an FPS benchmark. Cold shader compilation can still exceed the homebrew frame deadline and trigger its CPU scaler; a warm restart used AGC. The startup UCRT diagnostic remains. Updated Linux and Windows CI pass.

Checklist

  • Based on main fe98276f; open PRs checked, related overlap with #672 noted above
  • One Windows import-resolution topic; new PR
  • No code comments, silent stubs, investigation artifacts, or third-party code added
  • Missing imports fail explicitly; generic behavior
  • Depends on: none for this change; the game integration requires the sibling fixes and #553
  • AI-assisted: yes

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4747093559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/684). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-05T15:18:19Z. --- ### 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 - Windows 11, bundled MinGW, Release, rebased on main `fe98276f`: all 28 relinker CTest cases pass. The new `foo_native` / `foo.native.prx` and `libSceFont` / `libSceFont-module.prx` fixtures reproduce the reported failure before the fix and now convert and run correctly, including imports in guest initializers. Exact-match precedence and ambiguous alias rejection are covered. PPSA21564 itself was not available locally; no direct retest of that title is claimed. - The new test converts and executes synthetic Windows binaries with colliding providers returning different values, a SONAME alias, and a guest initializer. It checks wrong-provider and missing-symbol startup failures, an unavailable module, invalid qualifiers/IDs, and ambiguous unqualified imports. - Integration with #683 (runtime exports), #685 (raw AGC compute), and #553: the original integration based on `af92452f` built and passed 290/290 CTest tests; DOOM Shareware homebrew PPSA99666 01.001.000 reached E1M1 and responded to movement and shooting. #614 is already on main. No game files added or modified. - Updated integration on main `fe98276f` with the repaired #683/#684/#685 and #553: full build plus the runtime `libs` target succeeded; all nine focused integration tests passed. DOOM Shareware reached E1M1 again with movement and shooting through AGC compute presentation. Profiling recorded 3,798 dispatch-cache hits in 3,800 dispatches with zero evictions. This is cache-use evidence, not an FPS benchmark. Cold shader compilation can still exceed the homebrew frame deadline and trigger its CPU scaler; a warm restart used AGC. The startup UCRT diagnostic remains. Updated Linux and Windows CI pass. ### Checklist - [x] Based on main `fe98276f`; open PRs checked, related overlap with #672 noted above - [x] One Windows import-resolution topic; new PR - [x] No code comments, silent stubs, investigation artifacts, or third-party code added - [x] Missing imports fail explicitly; generic behavior - [x] Depends on: none for this change; the game integration requires the sibling fixes and #553 - [x] AI-assisted: yes ### In-game screenshots [Two E1M1 gameplay captures from the integrated DOOM Shareware homebrew run](https://github.com/boykopovar/AnyPS5/pull/685#issuecomment-5997547697), showing the final integration build and movement/shooting. The integration dependencies and limits are described above.
oneandonlydean commented 2026-10-05 19:45:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T19:45:46Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6001773432 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/684#issuecomment-6001773432). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T19:45:46Z. --- 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`.
oneandonlydean commented 2026-10-06 03:27:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T03:27:10Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6008720894 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/684#issuecomment-6008720894). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T03:27:10Z. --- 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[bot] commented 2026-10-06 09:27:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T09:27:41Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6013351981 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/684#issuecomment-6013351981). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T09:27:41Z. --- <!-- pr-overlap --> 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](https://github.com/boykopovar/AnyPS5/blob/e4048a09891fa2cb8449b3bcddea3342ef8d0e89/core/relinker/domain/include/domain/GuestRuntime.hpp#L24)<br>`core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` [L204](https://github.com/boykopovar/AnyPS5/blob/e4048a09891fa2cb8449b3bcddea3342ef8d0e89/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L204) | | |
011010 commented 2026-10-06 22:28:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-06T22:28:41Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6026615018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/684#issuecomment-6026615018). Originally posted by [011010](https://github.com/011010) on 2026-10-06T22:28:41Z. --- 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.
Sign in to join this conversation.
No reviewers
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!684
No description provided.