fix(relinker): start Windows runtime modules the executable needs when the title loads them #8162
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8162"
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 savvaniss on 2026-10-20T00:58:32Z.
What
On Windows, a
--module-dirmodule that the executable needs was initialized by the entry stub, with no start arguments, before the title'smain. When the title later loaded the module withsceKernelLoadStartModule(path, args, argp),DynamicLoaderfound it initialized and started nothing, so itsmodule_startnever saw those arguments.A Unity PS4 player hits this.
boggle.selffrom CUSA03312 (Hasbro Family Fun Pack) listsmono-ps4.sprxas needed and loads it with its 88-byte plugin argument block. mono'smodule_startkeeps that block and passes it on when it loads the plugins inMedia/Plugins. Started at startup with no arguments, mono passed none, andUnityNpToolkit.prx'smodule_startread through a nullargpand crashed.GuestModuleBuilderno longer marks a runtime module as required on Windows just because the executable lists it inDT_NEEDED. Such a module is now deferred like any other--module-dirmodule:__aps5_guest_initializetable;DynamicLoaderruns its entry, with the title's start arguments, and then its initializers, when the title loads it.What stays the same:
DynamicLoaderdoes not start a deferred module's dependencies, and the existing debt line for this remains.sce_module,sce_modulesorprxthat 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) addssce_module, and Windows is its default target. Titles do not loadlibc.prxorlibSceFios2.prxthemselves, so deferring them would mean theirmodule_startand initializers never run. SandstromPL found this in review; the second commit keeps them required, as #6586 does for its Linux deferral.--module-dirdirectories.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, sotest_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 withmain56b299c3amerged.ctest: 223/223 pass.relinker_conversion(new case): converts for Windows throughRelinker::Conversion, adding the module's folder to the runtime directories the wayBindings.cppaddssce_module, an executable whoseDT_NEEDEDlistsneeded.prx. Insce_module,sce_modulesandprx,needed.prx.guest.prxexports no__aps5_guest_initialize; inMedia/Modulesit does. Without the second commit'sGuestModuleBuilder.cppchange 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, inMedia/Modulesand in the root directory, now has__aps5_guest_initialize. The converted executable still runs and exits with 42.test_executables.py: the Windows--executablecase whose second executable needs a runtime module converts, and the shared module is deferred.main34b1b77ab: withmain'sGuestModuleBuilder.cpp,guest_module_dirandrelinker_executablesfail; with the change, they pass.--module-dir boggleMedia/Modules --module-dir boggleMedia/Pluginsand run through the PS4 path of #6977. Before the change,UnityNpToolkit.prxcrashed in itsmodule_start. After it, mono'smodule_startreceives 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.45cc02c49on their PPSA18216 test branch and without #7450.relinker --windows --registry --executable mgspw/mgspw.elf --module-dir Media/Modules --module-dir Media/Pluginsexits 0 with 12 guest modules, andIl2cppUserAssemblies.prx.guest.prxexports__aps5_guest_initialize. The launcher runs at 60 FPS, hands over tomgspw, and New Game reaches the beach tutorial at the same rate as with #7450 on that laptop, with noterminate,FATALor unhandled exception.Il2cppUserAssemblies.prxand 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/mainpasses.tools/pr_overlap.pylists #6586 (the debt andUSAGE.mdlines) and #7450 (test_executables.pyandUSAGE.md); neither changes which Windows modules are deferred.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
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.
main)docs/dev/debt/relinker.mdL7docs/user/USAGE.mdL78core/relinker/relinker/tests/test_executables.pyL9, L99-100docs/user/USAGE.mdL78-79Some 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.
docs/dev/debt/relinker.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mdcore/relinker/relinker/src/guest/GuestModuleBuilder.cppdocs/dev/debt/relinker.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/relinker/src/guest/GuestModuleBuilder.cppdocs/dev/debt/relinker.mdImported 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.cppL68 adds/input/sce_moduletoRuntimeDirectories, and Windows is the web converter's default target (demo/web/index.htmlL18).With
&& !windowsat L264, a Windows browser conversion now defers everysce_modulemodule that the executable lists inDT_NEEDED, unless another bundled module depends on it (L269). For examplelibSceFios2.prx, orlibc.prxwhen no other bundled module imports from it.Titles don't load these modules themselves:
libcandlibSceFios2from/app0/sce_module(shadPS4's sysmodule table, L370-L371).sceSysmoduleLoadModuleonly openslibs/<name>.prx.So their
module_startand initializers would never run. The CLI isn't affected, because it never treatssce_module,sce_modulesorprxas runtime directories.How I checked it: I patched a relinker-only CLI build of
45cc02c49to addsce_moduleto the runtime directories, the same wayBindings.cppdoes. Withexecutable_with_needed()andsce_module/needed.prx:needed.prx.guest.prxexports__aps5_guest_initialize, so it is deferred;main'sGuestModuleBuilder.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:With that change, the patched build writes no table in the
sce_modulecase, and the relinker-only suite passes 218/218 on Linux (linux_gnu_segmentstimed out under-jand 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:
executableProvidersis only filled for non-Windows targets (L209-L211);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
main98db77922and resolved only the textual conflicts (test_executables.pyL9 and L88-89, and theUSAGE.mdrows). #7450's new Windows case then fails attest_executables.py:76withAssertionError: (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
--executablerelink. With this PR, its launcher startsIl2cppUserAssemblies.prxwhen 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)
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:mainc9e6c45deplus the open Peace Walker PRs) with45cc02c49cherry-picked, and without #7450. The cherry-pick stopped only ondocs/dev/debt/relinker.md; I took this PR's side.relinker --windows --registry --executable mgspw/mgspw.elf --module-dir Media/Modules --module-dir Media/Plugins src/eboot.elf app.exeexits 0 (12 guest modules), andIl2cppUserAssemblies.prx.guest.prxexports__aps5_guest_initialize.mgspw, and New Game reaches the beach tutorial at about 13 presents per 10 s, the same as with #7450 on this laptop. Noterminate,FATALor unhandled exception in the log.InitializeDeferredModuleafterconst auto count = table[1];, not part of the build otherwise):app.exeprintsIl2cppUserAssemblies.prx.guest.prx entry=0x10010 count=0once, when it loads the module itself. The Unity plugins (PSN,SaveData,CommonDialog,GameIntent,Share,SaveTransferring) print the same way on load, with later loads atentry=0x0.mgspwprinted none.So with this PR, Peace Walker on Windows works without #7450.
AI-assisted; the runs are from my machine(s).
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.cppaddingsce_moduleto the runtime directories, a Windows browser conversion would have deferredlibc.prxandlibSceFios2.prx, and theirmodule_startwould never have run.Change (
2e1864cdf4): yourstandardDirectoryrule, as suggested. On Windows, a module insce_module,sce_modulesorprxthat the executable needs is required again. A--module-dirmodule the executable needs is still deferred. CLI output doesn't change.Test: the CLI refuses
--module-dir sce_moduleas a duplicate guest module directory, so the new case is inrelinker_conversion. It goes throughRelinker::Conversionwith the folder inRuntimeDirectories, asBindings.cppdoes. The executable'sDT_NEEDEDlistsneeded.prx, and the case converts it for Windows:sce_module,sce_modulesandprx,needed.prx.guest.prxexports no__aps5_guest_initialize;Media/Modules, it does.Without the
GuestModuleBuilder.cppchange the case fails ("Wrong start of a runtime module the executable needs"). With it, the case passes. I put it at the end ofConversionTests.cppso it doesn't conflict with #6586'sruntimeLifecyclePolicycase.Results: Windows 11, WinLibs GCC 15.2.0, Release, relinker-only, with
main56b299c3amerged into the branch:ctest: 223/223 pass;check_conventions.pypasses;pr_overlap.pynow lists only #6586 (the debt andUSAGE.mdlines) 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.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,
executableProvidersis never filled: the block that fills it isif (!windows && …). So onmain, theDT_NEEDEDrule you change is the only thing that starts a--module-dirmodule 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 callssceKernelLoadStartModuleon it. The entry stub still loads it, so the imports bind. But itsmodule_startand 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
executableProvidersuses on Linux, and defer only the needed modules the executable never imports from? A test with an executable that imports from a--module-dirmodule 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.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
--executablecase #7450 was opened for.On Windows the deferral is written into the module itself (the
.ginittable and the__aps5_guest_initializeexport). If one executable imports from a--module-dirmodule 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, andmain.cppthrowsGuest modules convert differently, as it did before this PR.That is Peace Walker's shape (PPSA18216, #5268). The launcher lists
Il2cppUserAssemblies.prxand loads it itself (mrfelek's print above:entry=0x10010, once, when it loads it), andmgspw.elfdoesn'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 onmain. So for this title the reference rule and "start with the title's arguments" pull in opposite directions, the same as formono-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.elfimport anything fromIl2cppUserAssemblies.prx?tools/import_audit.pyon the--registryJSON with--modules app0/Media/Moduleslists such imports with the classmodule.AI-assisted: yes (Claude Code)
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
--executablemismatch #7450 was opened for. We withdraw that form of our earlier request.The gap we raised is still real, though: on Windows, a
--module-dirmodule that the executable imports from but never loads explicitly would bind its imports but never runmodule_startor 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-dirmodules 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.sprxdirectly, and does the PPSA18216 launcher import fromIl2cppUserAssemblies.prx? If neither does, this PR is fine as it stands for those titles, and the executable-side start can be a follow-up.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.sprxdirectly.How I checked:
relinker --windows --registry --executable TPMedia/tp.self eboot.bin app.exe, then rantools/import_audit.pyonTPMedia.tp.self.registry.json.mono-ps4.sprxis in its needed list.import_audit.py --modulescannot read the originalmono-ps4.sprx("incomplete dynamic string or symbol table"). So instead I hashed 30 common Mono API names withnid_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_pathandmono_gchandle_new.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_startat 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)
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.
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 nomodule_startunder the deferral, and, if you have time, a follow-up PR that logs at startup each deferred--module-dirmodule the executable imports, so a silent no-init is visible. With the debt line in, we'll run full CI and merge.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 indocs/dev/debt/relinker.mdnow also says: "A module the executable only imports from and the title never loads itself gets nomodule_startand no initializers at all under this deferral, and nothing reports it."tools/check_conventions.py --base origin/mainpasses.I'll open the startup log of deferred
--module-dirmodules that the executable imports from as a separate follow-up PR.AI-assisted: yes (Claude Code)
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-dirmodule that an import of the executable names. Guest module bytes are unchanged.