feat(relinker): add --module-dir for modules loaded at run time #846
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/846"
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 merwie on 2026-10-06T09:00:30Z.
What
Adds
--module-dir <dir>to the relinker, for modules a title keeps outsidesce_module/sce_modules/prx. Since #2708 the relinker looks for guest modules only in those directories.Unity titles keep two kinds of modules elsewhere:
Media/Modules: modules the executable needs at startup (Il2cppUserAssemblies.prx,PS5Util.prx).Media/Plugins: native plugins, loaded at run time withsceKernelLoadStartModule. In PPSA12544, an unrelinked plugin shows up asDllNotFoundException: Unable to load DLL 'PSN'for/app0/Media/Plugins/PSN.prx.How the option works:
--module-dir <dir>(repeatable) relinks the ELF modules of a directory under the module parent directory (--sce-module-path, by default the input's directory). Outputs keep the relative path, and #717 then finds them as<path>.guest.prx. The directory must exist inside the parent directory and differ from the other module directories. The option conflicts with--skip-sce-module.DT_INITentry and init array as__aps5_guest_initialize, anddlopencalls it once, with the start argumentssceKernelLoadStartModulerecords for the LinuxDT_INITstub (36c979b3), so*resgets the entry's result. On Linux these modules are left out ofDT_NEEDED, and that stub passes the arguments. The plugins check them: PPSA12544's PSN plugin is loaded withsceKernelLoadStartModule(path, 16, {16, 0x200, ...})and refuses to start without them (PSN is an old version that cannot be used by the current player runtime).USAGE.mddocuments the option. TechnicalDebt covers modules that another module needs being initialized at startup, and macOS not passing start arguments.Design question open for the maintainers: an explicit option vs. auto-discovery (see the comments).
Tested
Windows 11, PPSA12544, relinked with
--windows --module-dir Media/Modules --module-dir Media/Pluginsonmain4a747c48plus #425. All 12 guest modules are converted. TheMedia/Modulesmodules start at launch and the plugins on load. The title boots without theDllNotFoundException, the SaveData plugin mounts its save data, and the title menu renders at about 60 fps (bring-up: #726).test_guest_module_dir.pycovers:DT_NEEDEDon Linux;It fails on
main(unknown option), and the needed-module case fails without the startup rule.Non-GPU
ctestpasses (460), and the conventions check passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-06T09:30:14Z.
On the overlap report with #684: the two changes are independent. Both add a field after
UsePlatformTlsResolverinGuestRuntime(#684Names, this PRDeferInitialization) and a line in the same per-image runtime setup inGuestModuleBuilder::Build. This PR does not use theexportsmap that #684 changes. Whichever lands second keeps both lines; I will mergemainhere if #684 lands first.Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-06T16:32:19Z.
Independent verification (relinker-only, builds anywhere).
Built the relinker from
pr846standalone on macOS 26.6.2 (arm64), Apple Clang 21, C++20.test_guest_module_dir.pypasses; the other 21 relinker Python tests in the tree pass too.main(5895ea7) the same test fails at the first case withFAIL: unknown option: --module-dir, so it exercises the new flag rather than passing vacuously.One thing to make explicit before merge: this branch carries
test_guest_needed_modules.py, which is added by #716 (still open), so it is stacked on #716. The PR lists noDepends on, but merging it before #716 would pull #716's changes in with it. Worth stating the order or rebasing once #716 lands.No real Unity title was tested here (no dump).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T03:45:47Z.
Thanks. #684 has landed, so as you expected this branch now conflicts with main in
core/relinker/domain/include/domain/GuestRuntime.hppandcore/relinker/relinker/src/guest/GuestModuleBuilder.cpp(theNames/DeferInitializationfields and the per-image setup line). Could you rebase onto main, keeping both sides? A force push is fine.While you're there, please add
Depends on: #716to the description if the branch still carriestest_guest_needed_modules.pyfrom #716, so the merge order is clear.Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-07T05:49:47Z.
Merged
mainand kept both sides:GuestRuntimehas #684'sNamesfollowed byDeferInitialization, andGuestModuleBuilder::Buildsets both per image. Non-GPU tests pass (233). I merged rather than force-pushed so the review history stays, and Auto-fix on my side is set up for merges. Happy to squash at merge time if you prefer. The description now starts with Depends on: #716: the branch still carries #716's commit, includingtest_guest_needed_modules.py.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T16:21:24Z.
@boykopovar a design question before this goes further (cc @oneandonlydean). The code itself checks out on Linux: we rebased it onto current
main, and build + full ctest pass (399/399).guest_module_dirfails with the non-test changes reverted.sce_module/sce_modules/prxon its own, and the other module flags are deprecated. With--module-dir, whoever relinks a title has to know where it keeps its runtime-loaded modules (Media/Pluginsfor Unity). An alternative with no new option: treat every.prx/.sprxwith an ELF header under the input directory, outside the standard module directories, as a module loaded at run time (relinked, deferred initialization, kept out ofDT_NEEDED). Only files with those extensions get opened, so the title's data isn't scanned. Which one do you want?dlopenwith the host process arguments, and*resis 0. So the case that motivates the PR (PSN started with{16, 0x200, ...}) is still broken there, and nothing reports it. Until deferred initialization exists on Linux,sceKernelLoadStartModuleon such a module should throw instead.Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-07T19:02:20Z.
Thanks for running it on Linux.
Linux: agreed. On Linux,
sceKernelLoadStartModulewith start arguments now throws (NotImplemented_nid_no_patch, before thedlopen), so the PSN case is reported instead of starting the module without its arguments. TechnicalDebt has a line for it. I can't build the Linux path here; it is one guarded call.Flag or automatic discovery: that's for @boykopovar to decide. A correction to what I first wrote here: Silksong's
app0has more.prx/.sprxfiles outsidesce_modulethan the runtime-loaded plugins inMedia/Plugins:Media/Modules/Il2cppUserAssemblies.prxandPS5Util.prx, which the executable needs at startup (found throughDT_NEEDEDby #716);fakelib/*.sprx(5 files);sce_sys/about/right.sprx.So automatic discovery would have to exclude anything reachable through
DT_NEEDED, and skip or reject thefakelibandsce_sysfiles, which may not be ELF modules at all. That's doable. If it's the preferred direction, I'll switch the PR to it and drop the option.Also merged
mainagain (conflicts incore/relinker/CMakeLists.txtandGuestModuleBuilder.cpp, keeping this PR's lines). Non-GPU tests pass (235).Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-07T23:10:55Z.
Rebased onto current
main(df16c4c2) as @oneandonlydean asked; the merge commits are gone. The #716 commit dropped out because it is already upstream, so the branch is now the--module-dircommit and the Linux start-arguments commit. One correction: one of my earlier merges had accidentally removed theto_intel_linux_stubstest registration fromcore/relinker/CMakeLists.txt; the rebased branch keeps it. Otherwise the changes are the same. Non-GPU tests pass (239).Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-08T15:48:18Z.
Rebased onto current
main(4b005b22) again, after the conflict with the newReadNeededNameshelper inGuestModuleBuilder.cpp. Two commits, no merge commits, same changes. Non-GPU tests pass (275) and the conventions check passes.Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-09T17:45:48Z.
Another Unity title that needs this: Seeker: My Shadow (PPSA12500). Without it the game keeps retrying
sceKernelLoadStartModule("/app0/Media/Plugins/PSNCore.prx"). With--module-dir Media/Pluginsthe PSN and SaveData plugins load and start.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T22:31:07Z.
On adriadam10's question: auto-discovery seems better here. The title loads these modules by its own paths, so finding them the way the console would needs no flag. Could you switch to that and drop --module-dir?
Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-10T16:37:35Z.
A data point for the auto-discovery question, now that #2708 looks for guest modules only in
sce_module,sce_modulesandprx.Hollow Knight: Silksong (PPSA12544) keeps two of the modules its eboot lists as DT_NEEDED in
Media/Modules:Il2cppUserAssemblies.prxandPS5Util.prx. They load at start-up, not throughsceKernelLoadStartModule.--module-dir Media/Pluginsalone: onmainde5e541dplus this PR, the relinker converts 10 guest modules instead of 12. It treats the missing two as host libraries, and the game stops at start-up (exit 0xC0000135):--module-dir Media/Modulesadded: all 12 are converted, and the game runs through the opening into Moss Grotto (Windows 11, RTX 3060 Laptop). These two modules get the deferred initialization--module-dirgives, and on Windows that did not stop them from working.So for Unity titles, the flag or auto-discovery has to cover start-up modules outside
sce_moduleas well as the plugins loaded at run time.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by rm-NoobInCoding on 2026-10-10T19:26:56Z.
Data point for the auto-discovery question: Unity (PPSA07117) on Windows 11.
Il2CppUserAssemblies.prxandPS5Util.prxfromMedia/Modules, as orbz22 found for PPSA12544.Il2CppUserAssemblies.prxin turn needsAkSoundEngine.prx, which lives inMedia/Plugins. So one module in the plugin directory is a start-up dependency, while the other 10 are loaded bysceKernelLoadStartModule.(0, NULL)fails as described here:PSNCore is an old version that cannot be used by the current player runtime.sceKernelLoadStartModulearguments), PSNCore, PSNCommon, SaveData, CommonDialog and the Wwise plugins load and start, and the title is playable.Investigated with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-10T19:38:56Z.
@oneandonlydean @boykopovar, before I switch this to auto-discovery, one conflict to settle. #2708 landed after the request above and removed recursive module search on purpose ("I want the behavior to be consistent every time"). Auto-discovery would bring back a walk of the whole input tree for
.prx/.sprxfiles. That walk is what stopped on the malformedsce_sys/about/right.sprxin #2663, and in a real dump it also meets the dump tools'fakelib/*.sprx, which are SELF containers. An explicit directory option fits #2708's model, like--sce-module-path. So for now I've kept--module-dirand ported it onto currentmain.Which do you want? If it's auto-discovery, I'll switch: walk the module parent directory, skip
sce_sysand non-ELF files, and treat what's left as below.What changed in this push (merge of
main4a747c48, plus 558c53e3):Media/Modulesare no longer found. A module in a--module-dirdirectory that the executable or another module needs is now initialized at startup, and on Linux it stays inDT_NEEDED. Only modules that nothing needs are deferred tosceKernelLoadStartModule. So--module-dir Media/Modules --module-dir Media/Pluginscovers Unity titles.test_guest_module_dir.pyhas a new case for this, which fails without the change (the needed module is missing fromDT_NEEDED).mainnow passes them to Linux modules through theDT_INITstub (36c979b3). So I dropped my commit that madesceKernelLoadStartModulethrow on Linux. The Windows deferred initializer now reads the same handoff (__aps5_get_pending_module_args), andsceKernelLoadStartModuleis the same as onmain.sceKernelLoadStartModuledoesn't pass start arguments yet.Tested: Windows 11. Non-GPU
ctestpasses (460), and the conventions check passes. PPSA12544 was relinked with--windows --module-dir Media/Modules --module-dir Media/Pluginsonmainplus this branch and #425. All 12 guest modules are converted. The twoMedia/Modulesmodules have no deferred initializer, the five plugins do. The title boots past the point where it used to fail withDllNotFoundException: Unable to load DLL 'PSN', and the SaveData plugin mounts its save data.Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-10T19:53:19Z.
On the overlap report with #2119: the two changes are independent. #2119 adds
--to-rosettaand this PR adds--module-dir, so both add a branch toParseArgs, an entry to the usage string, and a parameter toGuestModuleBuilder::Build(and its call inmain.cpp). Neither uses the other's option. Whichever lands second keeps both; I'll mergemainhere if #2119 lands first.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T00:51:55Z.
Data point for run-time loaded modules: Hotline Miami (PPSA09682, Unity), relinked from the decrypted dump with
Media/Plugins/PSNCore.prxamong the extra modules. On Windows the title faults at start-up insidePSNCore.prx(read of 0x4, rip at +0x118f7 of the relinked module).What I could read from the relinked module: the function at +0x1891 is reached from the module entry at +0x10010 (it runs the init array). It checks its second argument as a parameter block,
*(u32*)p == 0x10and*(u32*)(p+4) == 0x200, and if that fails it prints a "please update the PSNCore module" message and then readsp+4anyway, which faults becausepis null. The call into the module entry comes from the title code (return addressapp.exe+0x2358d26) as one of a run of calls that all passedi = esi = edx = 0.Not established: whether the title is meant to pass a block here and something earlier in our emulation leaves it out, or whether that call sequence is something the relinker or loader should not trigger for a module loaded at run time. A gdb breakpoint on
sceKernelLoadStartModulewas never reported as hit before the fault, but I did not confirm that the breakpoint had resolved, so I can not say whether #918's fix is involved. I'm leaving this as a report.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:15Z.
Keep
--module-dir. #2708 settled on explicit module directories, and a tree walk would bring back theright.sprxandfakelibproblems. Please rebase onto main without the merge commit (a24d5235); it conflicts inCliArgs.cpp,main.cpp,GuestImage.hppandGuestModuleBuilder.cpp.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T01:13:45Z.
A second Unity title stops the same way: PPSA02801 faults at
PSNCore.prx.guest.prx+0x11624(read of 0x4,rbx = 0), which is the same function as the one I described for Hotline Miami above (the failed parameter-block check, thenp+4is read withpnull). Both titles shipMedia/Plugins/PSNCore.prxandPSNCommon.prx. I did not check whethersceKernelLoadStartModuleis involved for this title (for Hotline Miami my gdb breakpoint on it was never reported as hit, but I did not confirm that the breakpoint had resolved).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-11T02:48:07Z.
A third Unity title with run-time plugins: God of War Sons of Sparta (PPSA28997). Its
Media/PluginscontainsSaveData,PSN,CommonDialog,libfmod,libfmodstudio,lib_burst_generated,VoiceInputPluginandlibresonanceaudio. Two problems showed up, which may matter for how--module-dirlays out its output:prx/makes themDT_NEEDEDof the executable, so they are started at load without start arguments.SaveData.prx's start routine then reads the null argument pointer: SIGSEGV atmov (%rsi),%eaxwithrsi = 0.--exclude-sce-module, with each.guest.prxplaced beside its original). The plugins gotNEEDED $ORIGIN/../sce_module/libc.prx.guest.prxandRUNPATH $ORIGIN/../../libs. Those paths assume a module one directory belowapp0, but$ORIGINisapp0/Media/Plugins. EverysceKernelLoadStartModulefailed, and the failure was only visible throughdlerror(LD_DEBUG=filesshowed it). The title then retriedPSN.prxthousands of times and stayed on a black screen after its logos. Adding the symlinksapp0/Media/sce_module -> ../sce_moduleandapp0/libs -> ../libsmakes all of them load, and the title then reaches its menu and gameplay.So the relative dependency paths would need to be computed from the directory the module is loaded from (
Media/Pluginshere), not assumed to be one level belowapp0.Imported from boykopovar/AnyPS5. Originally posted by LightStorm72 on 2026-10-11T06:26:08Z.
Windows result for
--module-dir: tested on Windows 11 with Road of Death (PPSA07286), merged on top of01e65cfb(the only conflict was inGuestRuntime.hpp, where I kept both fields).Command:
relinker --windows --module-dir games <input>\eboot.elf app.exeBefore: the title's runtime-loaded plugin in
app0\gameswas an unconverted PS5 module, and Windows rejected it withthe "Bad Image" error 0xc000012f.
After: the runner loads the converted
rgpluginsgm_ps5.prx.guest.prx(it shows up in a backtrace) and printsStarting Ratalaika Games plugin system for PS5. The title then reaches its main loop and runs.No game files shared. AI-assisted (Claude).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:19:27Z.
Rebased onto current
mainas a single commit (the history had a merge commit; conflicts inCliArgs.cpp,GuestRuntime.hpp,main.cpp,GuestImage.hpp,GuestModuleBuilder.cppresolved keeping both sides, including--to-rosetta).Checked: relinker + libkernel build and 183 scoped tests pass (
guest_module_dir,guest_needed_modules,guest_module_directories,sce_module_path);guest_module_dirfails with the non-test changes reverted. Windows runs by @LightStorm72 and the Unity reports above cover the runtime side. Keeping--module-diras @oneandonlydean asked; merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-11T08:19:59Z.
Thanks @adriadam10. Your rebase has the same tree as the one I had prepared on
mainf60923bf(no file differs), so there's nothing more to push from my side. On Windows the non-GPU suite passes on it (516) and the conventions check passes.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T14:29:58Z.
Windows re-test of the Unity titles on current
maina11c8f7f7, relinked with--windows --module-dir Media/Modules --module-dir Media/Plugins(all modules converted; the import audit shows no named absent imports):mainas2faa5dd6e). With only--module-dir Media/Pluginsthe run gets further but the title logsunable to load /app0/Media/Modules/PS5Util.prx, error:0x80020002and the same forIl2CppUserAssemblies.prx: it opens those two by path at run time, soMedia/Moduleshas to be a module directory too (as already noted above). With both directories the load errors disappear and the title reaches level 1, then faults deterministically (3 of 3 runs) onLoading.PreloadManager:rip app.exe+0x7a6730, write of 0x24. The instruction is in a Unity deserialization routine (app.exe+0x7a6690, caller chain+0x8f382e, called while/app0/Media/sharedassets1.assetsis open) that stores 40-byte elements through an array whose data pointer is null while its capacity field says it is big enough, so no allocation happens. Which object that is I could not establish. Not established either: whether this is the title's data, a wrong value returned by one of our imports, or a memory-contents difference.multisampling or coverage conversion is unsupported (register 0x2f8 = 0x00108001)(State.cpp, the check on context register 0x2f8). That is multisampling, so it belongs with #419.So the PSNCore fault that #846 comments reported for these titles is not reproduced on current
mainwhen both module directories are given. Evidence kept locally (logs); no game data shared.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T16:22:43Z.
Follow-up on the Hotline Miami stop (PPSA09682,
maina11c8f7f7,--module-dir Media/Modules --module-dir Media/Plugins, Windows). It is deterministic (6 of 6 runs) and I can narrow it, not explain it:app.exe+0x7a6690, threadLoading.PreloadManager,sharedassets1.assetsopen) reads an element count from the stream and stores 40-byte elements into an array object. With a healthy empty array the object holds{data=0, label|0x2b, size=0, capacity=1}(logged at 7 earlier calls of the same routine). The array it faults on has data=0 but a large capacity field, so the routine skips its allocation and writes through null. The object's other fields hold values such as 1.0f and 0x7f000000, i.e. the object around that array was not constructed as expected. Which Unity class it is, I did not find out.sceKernelMprotect,sceKernelMapNamedFlexibleMemoryandsceKernelMapDirectMemory(every call in 0x1000000000-0x10ffffffff plus every non-zero result) printed nothing. The last memory call before the fault issceKernelReserveVirtualRange(len=0x9ec040000, flags=0)which we answer with 0 at 0x1000000000 (a 39.7 GiB reservation; the title also readssceKernelGetDirectMemorySize= 0x360000000 several times). I do not know whether that reservation matters.Cult of the Lamb, DREDGE and Harmony's Odyssey each ran 180 s with the same two module directories: no fault, no abort, no error line, shader cache hits and texture creation continuing; I did not look at the window.
AI-assisted (Claude Code).