fix(relinker): bind Windows imports to their declared modules #684
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/684"
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 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.prxshim can then intercept imports explicitly belonging to a system module with its placeholder exports.Preserve
DT_SCE_IMPORT_MODULEIDs 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-modulefilename differences map to declaredDT_NEEDEDdependencies, 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 hostlibc.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 newfoo_native/foo.native.prxandlibSceFont/libSceFont-module.prxfixtures 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
af92452fbuilt 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
fe98276fwith the repaired #683/#684/#685 and #553: full build plus the runtimelibstarget 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
fe98276f; open PRs checked, related overlap with #672 noted aboveIn-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.
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:The module names in
DT_SCE_IMPORT_MODULE(0x61000045) aren't always theDT_NEEDEDfile name without.prx. PPSA21564's eboot names the modulelibSceSaveData_native, while itsDT_NEEDEDentry islibSceSaveData.native.prx. The same eboot needslibSceFont-module.prxandlibSceFontFt-module.prx, and its string table haslibSceFontandlibSceFontFtbut nolibSceFont-module, so the first mismatch is probably not the only one.ImportModuleappends.prxto the module name, andWindowsEntryStubBuilderthen looks for that name among the dependencies, so the lookup fails for these.Could the module ID be mapped to its
DT_NEEDEDentry some other way, or could a qualified import whose module has no matching dependency fall back to the current unqualified lookup? A case intest_windows_import_modules.pywith a module name that differs from the file name (for examplefoo_nativeagainstfoo.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.prxinsce_module.windows_import_modulesfails with main's relinker and passes with this one, and the full ctest passes with it merged on Linux. The Linux CI failure is theagc_driver_flat_cache_bitstimeout that #677 has since fixed on main.It conflicts with #698 in
GuestModuleBuilder.cppandcore/relinker/CMakeLists.txt, and with #672 incore/relinker/CMakeLists.txt.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T03:27:10Z.
Thanks for the alias mapping.
foo_nativeagainstfoo.native.prxandlibSceFontagainstlibSceFont-module.prxnow 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(59DT_NEEDEDentries, 59DT_SCE_IMPORT_MODULEentries). Three now match that didn't before (libSceSaveData_native,libSceFont,libSceFontFt), but six still have no dependency with the same normalized name:DT_NEEDEDlibSceSaveDataDialoglibSceSaveDataDialog.native.prxlibSceJsonlibSceJson2.prxlibSceAvPlayerlibSceAvPlayer.native.prxlibSceAudiodeclibSceAudiodec.native.prxlibSceMsgDialoglibSceMsgDialog.native.prxlibSceAppContentUtillibSceAppContent.prxImportModulereturns the unmatched name unchanged, so as far as I can tellWindowsEntryStubBuilderwould still stop atImport module is not a dependency: libSceSaveDataDialog.prxfor 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 likelibSceJson/libSceJson2andlibSceAppContentUtil/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 modulelibFooagainstlibFoo2.prx) would pin that.One smaller point, Linux only: in
GuestModuleBuilder,mainrejects 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 thepush_backwould preserve it.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.
main)core/relinker/domain/include/domain/GuestRuntime.hppL24core/relinker/relinker/src/guest/GuestModuleBuilder.cppL204Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-06T22:28:41Z.
Independent verification (relinker-only, builds anywhere).
Built the relinker from
pr684standalone on macOS 26.6.2 (arm64), Apple Clang 21, C++20:test_windows_import_modules.pypasses, 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 withwhich 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.