fix(relinker): start Windows runtime modules the executable needs when the title loads them #8162

Merged
savvaniss merged 4 commits from upstream-pr/8162 into main 2026-10-21 13:10:11 +00:00
savvaniss commented 2026-10-20 00:58:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T00:58:32Z.


What

On Windows, a --module-dir module that the executable needs was initialized by the entry stub, with no start arguments, before the title's main. When the title later loaded the module with sceKernelLoadStartModule(path, args, argp), DynamicLoader found it initialized and started nothing, so its module_start never saw those arguments.

A Unity PS4 player hits this. boggle.self from CUSA03312 (Hasbro Family Fun Pack) lists mono-ps4.sprx as needed and loads it with its 88-byte plugin argument block. mono's module_start keeps that block and passes it on when it loads the plugins in Media/Plugins. Started at startup with no arguments, mono passed none, and UnityNpToolkit.prx's module_start read through a null argp and crashed.

GuestModuleBuilder no longer marks a runtime module as required on Windows just because the executable lists it in DT_NEEDED. Such a module is now deferred like any other --module-dir module:

  • the entry stub still loads it, so the executable's imports from it bind as before;
  • it gets the __aps5_guest_initialize table;
  • DynamicLoader runs its entry, with the title's start arguments, and then its initializers, when the title loads it.

What stays the same:

  • A runtime module that another guest module needs is still started at startup, with no arguments. DynamicLoader does not start a deferred module's dependencies, and the existing debt line for this remains.
  • A module in sce_module, sce_modules or prx that the executable needs is still started at startup. The CLI never treats these folders as runtime directories, but the browser converter (core/relinker/wasm/Bindings.cpp) adds sce_module, and Windows is its default target. Titles do not load libc.prx or libSceFios2.prx themselves, so deferring them would mean their module_start and initializers never run. SandstromPL found this in review; the second commit keeps them required, as #6586 does for its Linux deferral.
  • Modules outside --module-dir directories.
  • Linux and macOS output. #6586 defers the Linux start of linked runtime modules for the same reason (a Unity plugin in Double Dragon Gaiden); this is the Windows counterpart.

A title that calls such a module before loading it would now find its initializers not run; the new debt line says so. Whether the console starts these modules earlier is not measured. The players I ran load mono before calling it.

One side effect: with --executable, a module that one executable needs and another loads at run time is now deferred for both. It converts the same way for both, so test_executables.py's Windows case that expected "Guest modules convert differently" now converts. #7450 handled that case in a more general way and touches the same test lines; SandstromPL has moved #7450 to draft in favour of this PR.

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON) of the branch with main 56b299c3a merged.

  • Full ctest: 223/223 pass.
  • relinker_conversion (new case): converts for Windows through Relinker::Conversion, adding the module's folder to the runtime directories the way Bindings.cpp adds sce_module, an executable whose DT_NEEDED lists needed.prx. In sce_module, sce_modules and prx, needed.prx.guest.prx exports no __aps5_guest_initialize; in Media/Modules it does. Without the second commit's GuestModuleBuilder.cpp change the case fails with "Wrong start of a runtime module the executable needs"; with it, it passes.
  • test_guest_module_dir.py: on Windows, a module the executable needs, in Media/Modules and in the root directory, now has __aps5_guest_initialize. The converted executable still runs and exits with 42.
  • test_executables.py: the Windows --executable case whose second executable needs a runtime module converts, and the shared module is deferred.
  • Negative control for the first commit, on main 34b1b77ab: with main's GuestModuleBuilder.cpp, guest_module_dir and relinker_executables fail; with the change, they pass.
  • Boggle (CUSA03312): converted with --module-dir boggleMedia/Modules --module-dir boggleMedia/Plugins and run through the PS4 path of #6977. Before the change, UnityNpToolkit.prx crashed in its module_start. After it, mono's module_start receives the player's 88-byte block, every plugin starts with it, and the title renders its first scene. Trivial Pursuit Live!, converted the same way, reaches its title screen.
  • Peace Walker (PPSA18216), run by @mrfelek (comment): Windows 11 Pro 26200, i7-11850H, RTX A2000 Laptop GPU (NVIDIA 610.60), WinLibs GCC 15.2.0, Release, with 45cc02c49 on their PPSA18216 test branch and without #7450. relinker --windows --registry --executable mgspw/mgspw.elf --module-dir Media/Modules --module-dir Media/Plugins exits 0 with 12 guest modules, and Il2cppUserAssemblies.prx.guest.prx exports __aps5_guest_initialize. The launcher runs at 60 FPS, hands over to mgspw, and New Game reaches the beach tutorial at the same rate as with #7450 on that laptop, with no terminate, FATAL or unhandled exception. Il2cppUserAssemblies.prx and the Unity plugins start when the launcher loads them. That run predates the second commit, which changes nothing for CLI conversions.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py lists #6586 (the debt and USAGE.md lines) and #7450 (test_executables.py and USAGE.md); neither changes which Windows modules are deferred.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: CUSA03312 #7198 (Boggle and Trivial Pursuit Live!, on the PS4 path of #6977)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4929468258 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-20T00:58:32Z. --- ### What On Windows, a `--module-dir` module that the executable needs was initialized by the entry stub, with no start arguments, before the title's `main`. When the title later loaded the module with `sceKernelLoadStartModule(path, args, argp)`, `DynamicLoader` found it initialized and started nothing, so its `module_start` never saw those arguments. A Unity PS4 player hits this. `boggle.self` from CUSA03312 (Hasbro Family Fun Pack) lists `mono-ps4.sprx` as needed and loads it with its 88-byte plugin argument block. mono's `module_start` keeps that block and passes it on when it loads the plugins in `Media/Plugins`. Started at startup with no arguments, mono passed none, and `UnityNpToolkit.prx`'s `module_start` read through a null `argp` and crashed. `GuestModuleBuilder` no longer marks a runtime module as required on Windows just because the executable lists it in `DT_NEEDED`. Such a module is now deferred like any other `--module-dir` module: - the entry stub still loads it, so the executable's imports from it bind as before; - it gets the `__aps5_guest_initialize` table; - `DynamicLoader` runs its entry, with the title's start arguments, and then its initializers, when the title loads it. What stays the same: - A runtime module that another guest module needs is still started at startup, with no arguments. `DynamicLoader` does not start a deferred module's dependencies, and the existing debt line for this remains. - A module in `sce_module`, `sce_modules` or `prx` that the executable needs is still started at startup. The CLI never treats these folders as runtime directories, but the browser converter (`core/relinker/wasm/Bindings.cpp`) adds `sce_module`, and Windows is its default target. Titles do not load `libc.prx` or `libSceFios2.prx` themselves, so deferring them would mean their `module_start` and initializers never run. SandstromPL found this in review; the second commit keeps them required, as #6586 does for its Linux deferral. - Modules outside `--module-dir` directories. - Linux and macOS output. #6586 defers the Linux start of linked runtime modules for the same reason (a Unity plugin in Double Dragon Gaiden); this is the Windows counterpart. A title that calls such a module before loading it would now find its initializers not run; the new debt line says so. Whether the console starts these modules earlier is not measured. The players I ran load mono before calling it. One side effect: with `--executable`, a module that one executable needs and another loads at run time is now deferred for both. It converts the same way for both, so `test_executables.py`'s Windows case that expected "Guest modules convert differently" now converts. #7450 handled that case in a more general way and touches the same test lines; SandstromPL has moved #7450 to draft in favour of this PR. ### Tested Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`) of the branch with `main` `56b299c3a` merged. - Full `ctest`: 223/223 pass. - `relinker_conversion` (new case): converts for Windows through `Relinker::Conversion`, adding the module's folder to the runtime directories the way `Bindings.cpp` adds `sce_module`, an executable whose `DT_NEEDED` lists `needed.prx`. In `sce_module`, `sce_modules` and `prx`, `needed.prx.guest.prx` exports no `__aps5_guest_initialize`; in `Media/Modules` it does. Without the second commit's `GuestModuleBuilder.cpp` change the case fails with "Wrong start of a runtime module the executable needs"; with it, it passes. - `test_guest_module_dir.py`: on Windows, a module the executable needs, in `Media/Modules` and in the root directory, now has `__aps5_guest_initialize`. The converted executable still runs and exits with 42. - `test_executables.py`: the Windows `--executable` case whose second executable needs a runtime module converts, and the shared module is deferred. - Negative control for the first commit, on `main` `34b1b77ab`: with `main`'s `GuestModuleBuilder.cpp`, `guest_module_dir` and `relinker_executables` fail; with the change, they pass. - **Boggle (CUSA03312):** converted with `--module-dir boggleMedia/Modules --module-dir boggleMedia/Plugins` and run through the PS4 path of #6977. Before the change, `UnityNpToolkit.prx` crashed in its `module_start`. After it, mono's `module_start` receives the player's 88-byte block, every plugin starts with it, and the title renders its first scene. Trivial Pursuit Live!, converted the same way, reaches its title screen. - **Peace Walker (PPSA18216), run by @mrfelek** ([comment](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6288011511)): Windows 11 Pro 26200, i7-11850H, RTX A2000 Laptop GPU (NVIDIA 610.60), WinLibs GCC 15.2.0, Release, with `45cc02c49` on their PPSA18216 test branch and without #7450. `relinker --windows --registry --executable mgspw/mgspw.elf --module-dir Media/Modules --module-dir Media/Plugins` exits 0 with 12 guest modules, and `Il2cppUserAssemblies.prx.guest.prx` exports `__aps5_guest_initialize`. The launcher runs at 60 FPS, hands over to `mgspw`, and New Game reaches the beach tutorial at the same rate as with #7450 on that laptop, with no `terminate`, `FATAL` or unhandled exception. `Il2cppUserAssemblies.prx` and the Unity plugins start when the launcher loads them. That run predates the second commit, which changes nothing for CLI conversions. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py` lists #6586 (the debt and `USAGE.md` lines) and #7450 (`test_executables.py` and `USAGE.md`); neither changes which Windows modules are deferred. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: CUSA03312 #7198 (Boggle and Trivial Pursuit Live!, on the PS4 path of #6977) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 01:19:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T01:19:44Z.


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
PR 6586 docs/dev/debt/relinker.md L7
docs/user/USAGE.md L78
PR 7450 core/relinker/relinker/tests/test_executables.py L9, L99-100
docs/user/USAGE.md L78-79

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6171 docs/user/USAGE.md
PR 6788 docs/user/USAGE.md
PR 6924 docs/user/USAGE.md
PR 6946 docs/user/USAGE.md
PR 6947 docs/user/USAGE.md
PR 6977 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
PR 7642 docs/user/USAGE.md
PR 7800 docs/user/USAGE.md
PR 7918 docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 8076 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281070020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6281070020). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T01:19:44Z. --- <!-- 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 | |---|---|---|---| | [PR 6586](https://www.github.com/boykopovar/AnyPS5/pull/6586) | `docs/dev/debt/relinker.md` [L7](https://github.com/boykopovar/AnyPS5/blob/b5d763770a8e932b35db9bea1c415e7e0ac50a22/docs/dev/debt/relinker.md#L7)<br>`docs/user/USAGE.md` [L78](https://github.com/boykopovar/AnyPS5/blob/b5d763770a8e932b35db9bea1c415e7e0ac50a22/docs/user/USAGE.md#L78) | | | | [PR 7450](https://www.github.com/boykopovar/AnyPS5/pull/7450) | `core/relinker/relinker/tests/test_executables.py` [L9](https://github.com/boykopovar/AnyPS5/blob/b5d763770a8e932b35db9bea1c415e7e0ac50a22/core/relinker/relinker/tests/test_executables.py#L9), [L99-100](https://github.com/boykopovar/AnyPS5/blob/b5d763770a8e932b35db9bea1c415e7e0ac50a22/core/relinker/relinker/tests/test_executables.py#L99-L100)<br>`docs/user/USAGE.md` [L78-79](https://github.com/boykopovar/AnyPS5/blob/b5d763770a8e932b35db9bea1c415e7e0ac50a22/docs/user/USAGE.md#L78-L79) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/relinker.md`<br>`docs/user/USAGE.md` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `docs/user/USAGE.md` | | [PR 6171](https://www.github.com/boykopovar/AnyPS5/pull/6171) | `docs/user/USAGE.md` | | [PR 6788](https://www.github.com/boykopovar/AnyPS5/pull/6788) | `docs/user/USAGE.md` | | [PR 6924](https://www.github.com/boykopovar/AnyPS5/pull/6924) | `docs/user/USAGE.md` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `docs/user/USAGE.md` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `docs/user/USAGE.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp`<br>`docs/dev/debt/relinker.md` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `docs/user/USAGE.md` | | [PR 7800](https://www.github.com/boykopovar/AnyPS5/pull/7800) | `docs/user/USAGE.md` | | [PR 7918](https://www.github.com/boykopovar/AnyPS5/pull/7918) | `docs/dev/debt/relinker.md`<br>`docs/user/USAGE.md` | | [PR 8076](https://www.github.com/boykopovar/AnyPS5/pull/8076) | `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp`<br>`docs/dev/debt/relinker.md` |
SandstromPL commented 2026-10-20 07:25:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-20T07:25:11Z.


@savvaniss @oneandonlydean I found two things while checking this PR against the browser converter and against my #7450.

1. Browser converter, Windows output. Bindings.cpp L68 adds /input/sce_module to RuntimeDirectories, and Windows is the web converter's default target (demo/web/index.html L18).

With && !windows at L264, a Windows browser conversion now defers every sce_module module that the executable lists in DT_NEEDED, unless another bundled module depends on it (L269). For example libSceFios2.prx, or libc.prx when no other bundled module imports from it.

Titles don't load these modules themselves:

  • The console preloads libc and libSceFios2 from /app0/sce_module (shadPS4's sysmodule table, L370-L371).
  • Our sceSysmoduleLoadModule only opens libs/<name>.prx.

So their module_start and initializers would never run. The CLI isn't affected, because it never treats sce_module, sce_modules or prx as runtime directories.

How I checked it: I patched a relinker-only CLI build of 45cc02c49 to add sce_module to the runtime directories, the same way Bindings.cpp does. With executable_with_needed() and sce_module/needed.prx:

  • with this PR, needed.prx.guest.prx exports __aps5_guest_initialize, so it is deferred;
  • with main's GuestModuleBuilder.cpp, it doesn't.

Suggested fix: keep the requirement for the standard folders, as #6586 does for its Linux deferral (L390-L391 at 85b281b22). That brings back main's output for the browser and changes nothing in the CLI:

+    const auto standardDirectory = [&](const std::size_t index) {
+        const auto directory = images[index].SourcePath.parent_path().lexically_normal();
+        return directory == (root / "sce_module").lexically_normal() || directory == (root / "sce_modules").lexically_normal() || directory == (root / "prx").lexically_normal();
+    };
     for (const auto& name : neededNames) {
         const auto found = findGuest(name);
-        if (found != guestNames.end() && !windows) require(found->second);
+        if (found != guestNames.end() && (!windows || standardDirectory(found->second))) require(found->second);
     }

With that change, the patched build writes no table in the sce_module case, and the relinker-only suite passes 218/218 on Linux (linux_gnu_segments timed out under -j and passed when rerun on its own).

2. #7450. After this PR, which Windows guest modules are required no longer depends on the executable being converted:

  • executableProviders is only filled for non-Windows targets (L209-L211);
  • L269 depends only on the module set, which is the same for every executable.

So the case #7450 handles, where one executable starts a module at startup and the other defers it, can no longer happen.

The two PRs also don't combine as they stand. I merged both into main 98db77922 and resolved only the textual conflicts (test_executables.py L9 and L88-89, and the USAGE.md rows). #7450's new Windows case then fails at test_executables.py:76 with AssertionError: (4176, [], []), so the suite passes 222/223. The cause is that the executable that lists the modules no longer starts them.

So I'd rather this one goes in and #7450 doesn't. I've moved #7450 back to draft so it can't merge first, and I'll close it once this one merges.

Peace Walker: PPSA18216 is the PS5 IL2CPP title that was run on Windows with #7450's --executable relink. With this PR, its launcher starts Il2cppUserAssemblies.prx when the launcher loads it, no longer at startup. I've asked mrfelek on #5268 to run it with this PR alone.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285695545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6285695545). Originally posted by [SandstromPL](https://github.com/SandstromPL) on 2026-10-20T07:25:11Z. --- @savvaniss @oneandonlydean I found two things while checking this PR against the browser converter and against my #7450. **1. Browser converter, Windows output.** [`Bindings.cpp` L68](https://github.com/boykopovar/AnyPS5/blob/e9cc4a8efb346205f909759dfff18e5501fe3f13/core/relinker/wasm/Bindings.cpp#L68) adds `/input/sce_module` to `RuntimeDirectories`, and Windows is the web converter's default target (`demo/web/index.html` L18). With `&& !windows` at [L264](https://github.com/boykopovar/AnyPS5/blob/45cc02c49ca674ed177bd2f7100fe4f1f601de85/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L264), a Windows browser conversion now defers every `sce_module` module that the executable lists in `DT_NEEDED`, unless another bundled module depends on it (L269). For example `libSceFios2.prx`, or `libc.prx` when no other bundled module imports from it. Titles don't load these modules themselves: - The console preloads `libc` and `libSceFios2` from `/app0/sce_module` (shadPS4's [sysmodule table, L370-L371](https://github.com/shadps4-emu/shadPS4/blob/a808e7626e3c7de8d0f0fda6a91f620b42f6c762/src/core/libraries/sysmodule/sysmodule_table.h#L370-L371)). - Our `sceSysmoduleLoadModule` only opens `libs/<name>.prx`. So their `module_start` and initializers would never run. The CLI isn't affected, because it never treats `sce_module`, `sce_modules` or `prx` as runtime directories. **How I checked it:** I patched a relinker-only CLI build of 45cc02c49 to add `sce_module` to the runtime directories, the same way `Bindings.cpp` does. With `executable_with_needed()` and `sce_module/needed.prx`: - with this PR, `needed.prx.guest.prx` exports `__aps5_guest_initialize`, so it is deferred; - with `main`'s `GuestModuleBuilder.cpp`, it doesn't. **Suggested fix:** keep the requirement for the standard folders, as #6586 does for its Linux deferral ([L390-L391 at 85b281b22](https://github.com/boykopovar/AnyPS5/blob/85b281b22cd0fc43757ec59c6039099632ee7fbd/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L390-L391)). That brings back `main`'s output for the browser and changes nothing in the CLI: ```diff + const auto standardDirectory = [&](const std::size_t index) { + const auto directory = images[index].SourcePath.parent_path().lexically_normal(); + return directory == (root / "sce_module").lexically_normal() || directory == (root / "sce_modules").lexically_normal() || directory == (root / "prx").lexically_normal(); + }; for (const auto& name : neededNames) { const auto found = findGuest(name); - if (found != guestNames.end() && !windows) require(found->second); + if (found != guestNames.end() && (!windows || standardDirectory(found->second))) require(found->second); } ``` With that change, the patched build writes no table in the `sce_module` case, and the relinker-only suite passes 218/218 on Linux (`linux_gnu_segments` timed out under `-j` and passed when rerun on its own). **2. #7450.** After this PR, which Windows guest modules are required no longer depends on the executable being converted: - `executableProviders` is only filled for non-Windows targets (L209-L211); - L269 depends only on the module set, which is the same for every executable. So the case #7450 handles, where one executable starts a module at startup and the other defers it, can no longer happen. The two PRs also don't combine as they stand. I merged both into `main` 98db77922 and resolved only the textual conflicts (`test_executables.py` L9 and L88-89, and the `USAGE.md` rows). #7450's new Windows case then fails at `test_executables.py:76` with `AssertionError: (4176, [], [])`, so the suite passes 222/223. The cause is that the executable that lists the modules no longer starts them. So I'd rather this one goes in and #7450 doesn't. I've moved #7450 back to draft so it can't merge first, and I'll close it once this one merges. **Peace Walker:** PPSA18216 is the PS5 IL2CPP title that was run on Windows with #7450's `--executable` relink. With this PR, its launcher starts `Il2cppUserAssemblies.prx` when the launcher loads it, no longer at startup. I've asked mrfelek on #5268 to run it with this PR alone. AI-assisted: yes (Claude Code)
mrfelek commented 2026-10-20 09:37:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-20T09:37:40Z.


Peace Walker (PPSA18216), Windows, with this PR instead of #7450. @SandstromPL asked on #5268 for this run.

Setup: Windows 11 Pro 26200, i7-11850H, RTX A2000 Laptop GPU (NVIDIA 610.60), WinLibs GCC 15.2.0, Release, on AC power. My PPSA18216 test branch (8e5e16820: main c9e6c45de plus the open Peace Walker PRs) with 45cc02c49 cherry-picked, and without #7450. The cherry-pick stopped only on docs/dev/debt/relinker.md; I took this PR's side.

  • Combined relink: relinker --windows --registry --executable mgspw/mgspw.elf --module-dir Media/Modules --module-dir Media/Plugins src/eboot.elf app.exe exits 0 (12 guest modules), and Il2cppUserAssemblies.prx.guest.prx exports __aps5_guest_initialize.
  • In the title: the launcher runs at 60 FPS (600 presents per 10 s), hands over to mgspw, and New Game reaches the beach tutorial at about 13 presents per 10 s, the same as with #7450 on this laptop. No terminate, FATAL or unhandled exception in the log.
  • Where it starts now (a temporary print in InitializeDeferredModule after const auto count = table[1];, not part of the build otherwise): app.exe prints Il2cppUserAssemblies.prx.guest.prx entry=0x10010 count=0 once, when it loads the module itself. The Unity plugins (PSN, SaveData, CommonDialog, GameIntent, Share, SaveTransferring) print the same way on load, with later loads at entry=0x0. mgspw printed none.

So with this PR, Peace Walker on Windows works without #7450.

AI-assisted; the runs are from my machine(s).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288011511 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6288011511). Originally posted by [mrfelek](https://github.com/mrfelek) on 2026-10-20T09:37:40Z. --- **Peace Walker (PPSA18216), Windows, with this PR instead of #7450.** @SandstromPL asked on #5268 for this run. **Setup:** Windows 11 Pro 26200, i7-11850H, RTX A2000 Laptop GPU (NVIDIA 610.60), WinLibs GCC 15.2.0, Release, on AC power. My PPSA18216 test branch (`8e5e16820`: `main` c9e6c45de plus the open Peace Walker PRs) with `45cc02c49` cherry-picked, and without #7450. The cherry-pick stopped only on `docs/dev/debt/relinker.md`; I took this PR's side. - **Combined relink:** `relinker --windows --registry --executable mgspw/mgspw.elf --module-dir Media/Modules --module-dir Media/Plugins src/eboot.elf app.exe` exits 0 (12 guest modules), and `Il2cppUserAssemblies.prx.guest.prx` exports `__aps5_guest_initialize`. - **In the title:** the launcher runs at 60 FPS (600 presents per 10 s), hands over to `mgspw`, and New Game reaches the beach tutorial at about 13 presents per 10 s, the same as with #7450 on this laptop. No `terminate`, `FATAL` or unhandled exception in the log. - **Where it starts now** (a temporary print in `InitializeDeferredModule` after `const auto count = table[1];`, not part of the build otherwise): `app.exe` prints `Il2cppUserAssemblies.prx.guest.prx entry=0x10010 count=0` once, when it loads the module itself. The Unity plugins (`PSN`, `SaveData`, `CommonDialog`, `GameIntent`, `Share`, `SaveTransferring`) print the same way on load, with later loads at `entry=0x0`. `mgspw` printed none. So with this PR, Peace Walker on Windows works without #7450. AI-assisted; the runs are from my machine(s).
savvaniss commented 2026-10-20 12:30:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T12:30:00Z.


@SandstromPL thank you for checking this against the browser converter. You were right: with Bindings.cpp adding sce_module to the runtime directories, a Windows browser conversion would have deferred libc.prx and libSceFios2.prx, and their module_start would never have run.

Change (2e1864cdf4): your standardDirectory rule, as suggested. On Windows, a module in sce_module, sce_modules or prx that the executable needs is required again. A --module-dir module the executable needs is still deferred. CLI output doesn't change.

Test: the CLI refuses --module-dir sce_module as a duplicate guest module directory, so the new case is in relinker_conversion. It goes through Relinker::Conversion with the folder in RuntimeDirectories, as Bindings.cpp does. The executable's DT_NEEDED lists needed.prx, and the case converts it for Windows:

  • in sce_module, sce_modules and prx, needed.prx.guest.prx exports no __aps5_guest_initialize;
  • in Media/Modules, it does.

Without the GuestModuleBuilder.cpp change the case fails ("Wrong start of a runtime module the executable needs"). With it, the case passes. I put it at the end of ConversionTests.cpp so it doesn't conflict with #6586's runtimeLifecyclePolicy case.

Results: Windows 11, WinLibs GCC 15.2.0, Release, relinker-only, with main 56b299c3a merged into the branch:

  • full ctest: 223/223 pass;
  • check_conventions.py passes;
  • pr_overlap.py now lists only #6586 (the debt and USAGE.md lines) and #7450.

#7450: thanks for working out how the two combine, and for moving it to draft in favour of this one. The description now says so.

@mrfelek thank you for the Peace Walker run. It's in Tested now, credited to you. Your run used 45cc02c49. The new commit only changes modules in folders the CLI never treats as runtime directories, so that conversion stays the same.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290869214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6290869214). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-20T12:30:00Z. --- @SandstromPL thank you for checking this against the browser converter. You were right: with `Bindings.cpp` adding `sce_module` to the runtime directories, a Windows browser conversion would have deferred `libc.prx` and `libSceFios2.prx`, and their `module_start` would never have run. **Change** (2e1864cdf4): your `standardDirectory` rule, as suggested. On Windows, a module in `sce_module`, `sce_modules` or `prx` that the executable needs is required again. A `--module-dir` module the executable needs is still deferred. CLI output doesn't change. **Test:** the CLI refuses `--module-dir sce_module` as a duplicate guest module directory, so the new case is in `relinker_conversion`. It goes through `Relinker::Conversion` with the folder in `RuntimeDirectories`, as `Bindings.cpp` does. The executable's `DT_NEEDED` lists `needed.prx`, and the case converts it for Windows: - in `sce_module`, `sce_modules` and `prx`, `needed.prx.guest.prx` exports no `__aps5_guest_initialize`; - in `Media/Modules`, it does. Without the `GuestModuleBuilder.cpp` change the case fails ("Wrong start of a runtime module the executable needs"). With it, the case passes. I put it at the end of `ConversionTests.cpp` so it doesn't conflict with #6586's `runtimeLifecyclePolicy` case. **Results:** Windows 11, WinLibs GCC 15.2.0, Release, relinker-only, with `main` 56b299c3a merged into the branch: - full `ctest`: 223/223 pass; - `check_conventions.py` passes; - `pr_overlap.py` now lists only #6586 (the debt and `USAGE.md` lines) and #7450. **#7450:** thanks for working out how the two combine, and for moving it to draft in favour of this one. The description now says so. @mrfelek thank you for the Peace Walker run. It's in Tested now, credited to you. Your run used 45cc02c49. The new commit only changes modules in folders the CLI never treats as runtime directories, so that conversion stays the same.
oneandonlydean commented 2026-10-20 16:09:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T16:09:16Z.


Thanks. Starting mono with the title's own arguments is the right outcome for CUSA03312. One case worries me before this goes in.

On Windows, executableProviders is never filled: the block that fills it is if (!windows && …). So on main, the DT_NEEDED rule you change is the only thing that starts a --module-dir module the executable needs at startup. With this PR, such a module is deferred on Windows even when the executable imports functions from it and never calls sceKernelLoadStartModule on it. The entry stub still loads it, so the imports bind. But its module_start and initializers (static constructors included) never run, and nothing reports that. Linux keeps starting it (#6586, the Linux counterpart you cite, is still open), so the two targets would behave differently for the same title.

Could you keep a needed module required on Windows when the executable actually references one of its exports, i.e. the same reference check executableProviders uses on Linux, and defer only the needed modules the executable never imports from? A test with an executable that imports from a --module-dir module and never loads it would pin that.

If the title's executable itself imports from mono-ps4.sprx (so that rule wouldn't help your case), please say so, and we'll put the trade-off to the maintainer instead.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6295415707 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6295415707). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T16:09:16Z. --- Thanks. Starting mono with the title's own arguments is the right outcome for CUSA03312. One case worries me before this goes in. On Windows, `executableProviders` is never filled: the block that fills it is `if (!windows && …)`. So on `main`, the `DT_NEEDED` rule you change is the only thing that starts a `--module-dir` module the executable needs at startup. With this PR, such a module is deferred on Windows even when the executable imports functions from it and never calls `sceKernelLoadStartModule` on it. The entry stub still loads it, so the imports bind. But its `module_start` and initializers (static constructors included) never run, and nothing reports that. Linux keeps starting it (#6586, the Linux counterpart you cite, is still open), so the two targets would behave differently for the same title. Could you keep a needed module required on Windows when the executable actually references one of its exports, i.e. the same reference check `executableProviders` uses on Linux, and defer only the needed modules the executable never imports from? A test with an executable that imports from a `--module-dir` module and never loads it would pin that. If the title's executable itself imports from `mono-ps4.sprx` (so that rule wouldn't help your case), please say so, and we'll put the trade-off to the maintainer instead.
SandstromPL commented 2026-10-20 18:38:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-20T18:38:14Z.


@oneandonlydean @savvaniss one interaction to weigh with the reference rule: it would bring back the --executable case #7450 was opened for.

On Windows the deferral is written into the module itself (the .ginit table and the __aps5_guest_initialize export). If one executable imports from a --module-dir module and another doesn't, the rule requires the module in the first and defers it in the second. The two conversions then write different bytes for it, and main.cpp throws Guest modules convert differently, as it did before this PR.

That is Peace Walker's shape (PPSA18216, #5268). The launcher lists Il2cppUserAssemblies.prx and loads it itself (mrfelek's print above: entry=0x10010, once, when it loads it), and mgspw.elf doesn't need it. If the launcher also imports from it, which is likely for a Unity player that loads its own module, the rule would start it at startup with no arguments again, and the combined relink would fail as it does on main. So for this title the reference rule and "start with the title's arguments" pull in opposite directions, the same as for mono-ps4.sprx.

If the rule goes in, I'll keep #7450 (draft) for that case instead of closing it. It lets the executable that requires a module start it at startup and clear the table, while the other one loads the same file later.

@mrfelek, when you have a moment: does eboot.elf import anything from Il2cppUserAssemblies.prx? tools/import_audit.py on the --registry JSON with --modules app0/Media/Modules lists such imports with the class module.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298375901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6298375901). Originally posted by [SandstromPL](https://github.com/SandstromPL) on 2026-10-20T18:38:14Z. --- @oneandonlydean @savvaniss one interaction to weigh with the reference rule: it would bring back the `--executable` case #7450 was opened for. On Windows the deferral is written into the module itself (the `.ginit` table and the `__aps5_guest_initialize` export). If one executable imports from a `--module-dir` module and another doesn't, the rule requires the module in the first and defers it in the second. The two conversions then write different bytes for it, and `main.cpp` throws `Guest modules convert differently`, as it did before this PR. That is Peace Walker's shape (PPSA18216, #5268). The launcher lists `Il2cppUserAssemblies.prx` and loads it itself (mrfelek's print above: `entry=0x10010`, once, when it loads it), and `mgspw.elf` doesn't need it. If the launcher also imports from it, which is likely for a Unity player that loads its own module, the rule would start it at startup with no arguments again, and the combined relink would fail as it does on `main`. So for this title the reference rule and "start with the title's arguments" pull in opposite directions, the same as for `mono-ps4.sprx`. If the rule goes in, I'll keep #7450 (draft) for that case instead of closing it. It lets the executable that requires a module start it at startup and clear the table, while the other one loads the same file later. @mrfelek, when you have a moment: does `eboot.elf` import anything from `Il2cppUserAssemblies.prx`? `tools/import_audit.py` on the `--registry` JSON with `--modules app0/Media/Modules` lists such imports with the class `module`. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-20 19:25:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T19:25:26Z.


@SandstromPL you're right, and thanks for spelling it out. Requiring the module when the executable references it would make the module's bytes depend on which executable is converted, and that brings back the --executable mismatch #7450 was opened for. We withdraw that form of our earlier request.

The gap we raised is still real, though: on Windows, a --module-dir module that the executable imports from but never loads explicitly would bind its imports but never run module_start or its initializers, with nothing reporting it. We think both concerns fit if the rule moves to the executable side. Keep this PR's uniform deferral (the module is the same for every executable), and have each converted executable start, at startup, the deferred --module-dir modules it imports from through their __aps5_guest_initialize. The module bytes stay identical, and the no-init case is closed.

Two import questions decide whether that matters in practice for the cases in this thread: does the CUSA03312 executable import from mono-ps4.sprx directly, and does the PPSA18216 launcher import from Il2cppUserAssemblies.prx? If neither does, this PR is fine as it stands for those titles, and the executable-side start can be a follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6299390716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6299390716). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T19:25:26Z. --- @SandstromPL you're right, and thanks for spelling it out. Requiring the module when the executable references it would make the module's bytes depend on which executable is converted, and that brings back the `--executable` mismatch #7450 was opened for. We withdraw that form of our earlier request. The gap we raised is still real, though: on Windows, a `--module-dir` module that the executable imports from but never loads explicitly would bind its imports but never run `module_start` or its initializers, with nothing reporting it. We think both concerns fit if the rule moves to the executable side. Keep this PR's uniform deferral (the module is the same for every executable), and have each converted executable start, at startup, the deferred `--module-dir` modules it imports from through their `__aps5_guest_initialize`. The module bytes stay identical, and the no-init case is closed. Two import questions decide whether that matters in practice for the cases in this thread: does the CUSA03312 executable import from `mono-ps4.sprx` directly, and does the PPSA18216 launcher import from `Il2cppUserAssemblies.prx`? If neither does, this PR is fine as it stands for those titles, and the executable-side start can be a follow-up.
savvaniss commented 2026-10-21 07:05:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-21T07:05:30Z.


@oneandonlydean @SandstromPL to the import question: yes, the CUSA03312 executable imports from mono-ps4.sprx directly.

How I checked:

  • I relinked Trivial Pursuit Live! with relinker --windows --registry --executable TPMedia/tp.self eboot.bin app.exe, then ran tools/import_audit.py on TPMedia.tp.self.registry.json.
  • mono-ps4.sprx is in its needed list.
  • Of its 529 unique imports, 244 come from no system library ("library not named").
  • import_audit.py --modules cannot read the original mono-ps4.sprx ("incomplete dynamic string or symbol table"). So instead I hashed 30 common Mono API names with nid_names.compute_nid, and all 30 are among those 244. Examples: mono_jit_init_version, mono_domain_get, mono_runtime_invoke, mono_thread_attach, mono_add_internal_call, mono_set_assemblies_path and mono_gchandle_new.
  • Boggle (boggleMedia/boggle.self) gives the same result, with the same 30 of 30.

So for this title, the executable-side start would run mono's module_start at startup again, without the arguments the title passes when it loads mono itself. That is the case this PR fixes. As SandstromPL found for Peace Walker, the import rule and "start with the title's arguments" pull in opposite directions here. Imports alone can't separate a module the title loads itself from one it only binds to.

I'd keep the uniform deferral as it is, and leave the trade-off for the no-init case to the maintainer, as you offered.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310170200 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6310170200). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-21T07:05:30Z. --- @oneandonlydean @SandstromPL to the import question: yes, the CUSA03312 executable imports from `mono-ps4.sprx` directly. How I checked: - I relinked Trivial Pursuit Live! with `relinker --windows --registry --executable TPMedia/tp.self eboot.bin app.exe`, then ran `tools/import_audit.py` on `TPMedia.tp.self.registry.json`. - `mono-ps4.sprx` is in its needed list. - Of its 529 unique imports, 244 come from no system library ("library not named"). - `import_audit.py --modules` cannot read the original `mono-ps4.sprx` ("incomplete dynamic string or symbol table"). So instead I hashed 30 common Mono API names with `nid_names.compute_nid`, and all 30 are among those 244. Examples: `mono_jit_init_version`, `mono_domain_get`, `mono_runtime_invoke`, `mono_thread_attach`, `mono_add_internal_call`, `mono_set_assemblies_path` and `mono_gchandle_new`. - Boggle (`boggleMedia/boggle.self`) gives the same result, with the same 30 of 30. So for this title, the executable-side start would run mono's `module_start` at startup again, without the arguments the title passes when it loads mono itself. That is the case this PR fixes. As SandstromPL found for Peace Walker, the import rule and "start with the title's arguments" pull in opposite directions here. Imports alone can't separate a module the title loads itself from one it only binds to. I'd keep the uniform deferral as it is, and leave the trade-off for the no-init case to the maintainer, as you offered. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-21 07:08:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T07:08:21Z.


@savvaniss thanks, that settles the import question: the executable binds to the runtime module directly, so imports alone cannot tell a module the title loads itself from one it only binds to. Keeping the uniform deferral as it is makes sense; we will take the no-init trade-off to a decision and come back here with it. Thanks @SandstromPL for the earlier data point.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310215338 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6310215338). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T07:08:21Z. --- @savvaniss thanks, that settles the import question: the executable binds to the runtime module directly, so imports alone cannot tell a module the title loads itself from one it only binds to. Keeping the uniform deferral as it is makes sense; we will take the no-init trade-off to a decision and come back here with it. Thanks @SandstromPL for the earlier data point.
oneandonlydean commented 2026-10-21 08:34:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T08:34:28Z.


@savvaniss we've settled the trade-off: keep the uniform deferral as it is. Two small things, please: add a line to docs/dev/debt/ saying that a module the executable only imports from --module-dir (and the title never loads itself) gets no module_start under the deferral, and, if you have time, a follow-up PR that logs at startup each deferred --module-dir module the executable imports, so a silent no-init is visible. With the debt line in, we'll run full CI and merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311678668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6311678668). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T08:34:28Z. --- @savvaniss we've settled the trade-off: keep the uniform deferral as it is. Two small things, please: add a line to `docs/dev/debt/` saying that a module the executable only imports from `--module-dir` (and the title never loads itself) gets no `module_start` under the deferral, and, if you have time, a follow-up PR that logs at startup each deferred `--module-dir` module the executable imports, so a silent no-init is visible. With the debt line in, we'll run full CI and merge.
savvaniss commented 2026-10-21 11:12:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-21T11:12:26Z.


@oneandonlydean added in 1d0451f65. The "Runtime-loaded modules the executable needs" entry in docs/dev/debt/relinker.md now also says: "A module the executable only imports from and the title never loads itself gets no module_start and no initializers at all under this deferral, and nothing reports it." tools/check_conventions.py --base origin/main passes.

I'll open the startup log of deferred --module-dir modules that the executable imports from as a separate follow-up PR.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314516999 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6314516999). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-21T11:12:26Z. --- @oneandonlydean added in `1d0451f65`. The "Runtime-loaded modules the executable needs" entry in `docs/dev/debt/relinker.md` now also says: "A module the executable only imports from and the title never loads itself gets no `module_start` and no initializers at all under this deferral, and nothing reports it." `tools/check_conventions.py --base origin/main` passes. I'll open the startup log of deferred `--module-dir` modules that the executable imports from as a separate follow-up PR. AI-assisted: yes (Claude Code)
savvaniss commented 2026-10-21 15:40:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-21T15:40:58Z.


@oneandonlydean the startup log is in #9228: on Windows the entry stub prints one Deferred module <path> line for each deferred --module-dir module that an import of the executable names. Guest module bytes are unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6320008072 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8162#issuecomment-6320008072). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-21T15:40:58Z. --- @oneandonlydean the startup log is in #9228: on Windows the entry stub prints one `Deferred module <path>` line for each deferred `--module-dir` module that an import of the executable names. Guest module bytes are unchanged.
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!8162
No description provided.