Repository navigation
fix(relinker): defer bundled modules that a loader executable does not need - #15828
Conversation
|
Windows verification of this head (the fix content is identical to a copy I rebased onto current
AI-assisted: yes. |
|
Linux verification of head Focused
Full relinker-only suite
Conventions
Code reading
AI-assisted: yes |
BunnyFl
left a comment
There was a problem hiding this comment.
@juanpimg approved. The deferral only reaches a standard-directory module when the executable imports sceKernelLoadStartModule and nothing requires the module (details below). It also composes with the Windows deferral main got from #15370 after this branch was cut.
What I read
isRuntimenow also covers a standard-directory module whenexecutableLoadsModulesis set (core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:321at this head). Everything thatrequirereaches stays started: the executable's needed modules and providers, every non-runtime module and, on Windows, every standard-directory dependency of any module (core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:332on the merge withmain, from #15370). Only a module nothing depends on is deferred.- On Linux,
deferLinuxStart(core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:509at this head) keeps the old rule for runtime directories and adds the standard directories only for modules that are notrequired. - Moving the
wzvqT4UqKX8check above thedeclaresHostskip means the import is seen even when a host library declares it.
Two limits, neither blocking: a module that a bundled module (not the executable) loads through sceKernelLoadStartModule keeps the old start-at-launch behaviour, and no title has been run with this yet, on Linux or Windows.
What I ran
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2, Release, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), this head merged cleanly onto main b611e634f7:
- The 33
guest_*relinker tests,guest_load_start_module_deferincluded: 33 of 33 pass. - Negative control:
guest_load_start_module_deferwithGuestModuleBuilder.cppfrommainfails on thelinux/loadercase, which still lists$ORIGIN/app0/sce_module/bundled.prx.guest.prxinDT_NEEDED. - The full relinker-only suite (713 tests,
-j8): the merge and plainmainshare the same three failures on this machine (test_registration,select_tests_MissingCommandTestsand onecheck_compileWindows response-file test). The merge also timed outannotate_moduleand onetrace_digestCLI test; both pass when re-run alone (9.4 s and 7.3 s). They are presumably load timeouts at-j8rather than regressions; I haven't checked beyond the re-run. tools/pr_overlap.py --branchon this head: no line overlaps among the PRs it could compare. Of the 21 it could not, three changeGuestModuleBuilder.cpp: #10861 and #15032 (code-root analysis) and #15245 (needed-module resolution), none of them in the deferral code. #15245 changes which modules are needed, which feedsrequiredhere; worth a re-run if it lands first.
|
Retail data point. I relinked three unwrapped PS5 executables with the
The seven MGS4 deferrals are MGS4 on the PR libraries still boots through the launcher to its title tree and holds 59.9 fps there, no worse than AI-assisted: yes (Claude Code) |
|
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.
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.
|
|
Note for merge order, from the overlap bot: PR 15245 (open, CLEAN) also edits |
gabichuuuuu
left a comment
There was a problem hiding this comment.
Read befca70b9f against main.
Deferred dependencies never start on Linux. With the sceKernelLoadStartModule import, isRuntime (GuestModuleBuilder.cpp:321-324) covers every module in sce_module/, sce_modules/ and prx/, but on Linux nothing requires the bundled modules a deferred module depends on: the dependency loop at :332 runs only if (windows). Take sce_module/a.prx that needs sce_module/b.prx, and an executable that imports sceKernelLoadStartModule and needs neither. Both are deferred, so neither is in the executable's DT_NEEDED (:429), and both are written with deferInitialization (:509), so b loses DT_INIT and DT_INIT_ARRAY. When the title loads a, ld.so maps b through a's DT_NEEDED, but InitializeLinuxGuestModule (core/libs/prx/libkernel/Module/src/DynamicLoader.cpp on main) runs only the lifecycle table of the requested handle (if (owner != requested) return;), so b's module_start and static constructors never run. On main both start at launch. The debt file already lists this gap for --module-dir ("On Linux, loading a module does not start the deferred modules it needs"); this extends it to the standard folders.
The smallest fix keeps main's behaviour for those dependencies:
if (windows || executableLoadsModules) for (const auto dependency : dependencies[index]) if (standardDirectory(dependency)) require(dependency);plus a case in test_guest_load_start_module_defer.py where one bundled module needs another: on Linux the dependency should stay in the executable's DT_NEEDED, and the case should fail without the fix.
macOS changes too. deferred() also drives the macOS load list (:429 is !windows), so a bundled module nothing needs also leaves LC_LOAD_DYLIB there, but USAGE says "On Linux and Windows", the test covers only those, and docs/dev/debt/relinker.md still says "standard SDK folders keep their mapping initializer".
Stale base. The branch is about 4,400 commits behind main, and GuestModuleBuilder.cpp has since gained the Windows deferred sweep. It still merges cleanly, but the green checks come from the old merge; a rebase and a fresh run would help before landing.
Not run here; this is from reading the code.
AI-assisted: yes.
|
@juanpimg, a correction to my approval, prompted by @gabichuuuuu's review (thanks for catching it): their Linux point is right, and my sentence "Only a module nothing depends on is deferred" holds on Windows only. Reading
This is from reading the code; I have not run a Linux case. My approval's test runs were on Windows, where the dependency loop covers this. When the branch has the fix and the dependency case in |
…t need A bundled module started at launch even when the title later loads it with sceKernelLoadStartModule, so its module_start ran without the arguments the title passes. When the executable imports sceKernelLoadStartModule, a bundled module that neither the executable nor a required module needs is now deferred on Linux and Windows and starts when the title loads it. Without that import nothing changes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S9YbMMfRe28V3CXfs9gKPw (cherry picked from commit 85885d8)
befca70 to
72359c8
Compare
|
@BunnyFl @gabichuuuuu both points are addressed in
Checks on the new head are running. |
|
@juanpimg, the re-run I said I'd do, on Windows 11, WinLibs GCC 15.2, Release:
So the Linux dependency gap from my approval is closed at this head, and the new case is the one that catches it. I did not run a title, and nothing here ran on Linux or macOS: the Linux results are the relinker's Linux output checked on Windows. |
|
Hi @juanpimg, thanks for the dependency fix. One small docs point that does not block anything: |
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
gabichuuuuu
left a comment
There was a problem hiding this comment.
Follow-up on 72359c8c10, merged onto main c2ea254d0d (clean merge). Thanks for the Linux dependency fix; it closes the gap from my earlier comment.
Setup: Windows 11, WinLibs GCC 15.2, Release, relinker-only.
- 11 / 11 related tests pass:
guest_load_start_module_defer,guest_deferred_dependencies,guest_module_dir,guest_module_directories,guest_export_lookup,needed_libraries,guest_unused_import_dependencies,guest_module_args,guest_load_ranges,guest_needed_modules,macos_output.
macOS does change, as @oneandonlydean said. I ran the test's four fixtures through the relinker with --macos and read the executable's LC_LOAD_DYLIB entries under sce_module/:
| Case | main |
this PR |
|---|---|---|
plain |
bundled.prx.guest.prx |
bundled.prx.guest.prx |
loader |
bundled.prx.guest.prx |
none |
loader-needs-bundled |
bundled.prx.guest.prx |
bundled.prx.guest.prx |
loader-needs-dependency |
dependency…, bundled… |
dependency… only |
So on macOS a bundled module that nothing needs no longer loads at launch. Unlike Linux, WriteMacOs gets no deferInitialization, so the module keeps its initializers and runs them when the title loads it. I have no Mac, so I couldn't check whether that start gets the title's module_start arguments there. Either way, USAGE ("On Linux and Windows") and the debt entry should mention macOS, and a macos row in test_guest_load_start_module_defer.py would pin the load-list change.
|
Thanks. I checked this against the writer path before changing the sentence, and macOS does not defer the module today:
So "On Linux and Windows" is accurate: macOS still starts the module at launch. If you want the macOS behaviour stated explicitly rather than implied, I can add a short clause, but I would not change the platform list. @JJenkx thanks for the Windows 3/3 run on the new head. |
|
macOS check of head Setup: macOS 26.7, Apple M4, Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2, Python 3.15.0, Release,
macOS output, on the USAGE.md question above. The test checks Linux and Windows only, so I converted its four fixtures (same helpers) with
(paths are So the macOS executable drops the deferred module from its load commands, the same way the Linux |
|
Hi @juanpimg, thanks for walking through the writer path. Reviewed at 72359c8. @XIIYAZ's macOS run above settles the Could the sentence on line 17 say "On Linux, macOS and Windows"? If you haven't seen a later |
|
Thanks, and thanks @XIIYAZ for the macOS run. You are right: the executable's needed list is what decides the load, so the deferral reaches macOS too, and Updated |
|
@juanpimg @oneandonlydean this change stops PPSA22408 at startup on Linux. Converted with current Setup: Linux 7.3, GCC 15.3, Release, RTX 3080 Ti. The title's How it was found: I bisected
Good means it gets past module start and stops later on the title's known The crash, on
What changes in the output: the executable imports
The crash is under the host loader's call into AI-assisted. |
What
Fixes #14153. The relinker starts every module bundled in
sce_module/,sce_modules/orprx/at launch, even when the title later loads it withsceKernelLoadStartModule. A module that validates the arguments passed tomodule_start(PS5MC/Kodi'slibkodi-app.sprx) therefore starts with no arguments and refuses to initialize; the later load with the real arguments starts nothing.When the executable imports
sceKernelLoadStartModule(NIDwzvqT4UqKX8), a bundled module in a standard directory that neither the executable nor a required module needs is now deferred: on Linux it is left out ofDT_NEEDED, on Windows its initializer export is not emitted, so it starts when the title loads it. A module that is needed still starts at launch, and executables that do not importsceKernelLoadStartModulekeep the old behaviour. On Linux, a standard-directory module that another deferred module needs also stays started, because the Linux loader initializes only the requested handle; the newloader-needs-dependencycase pins that.This is the fix from commit
85885d8f51(authored by Claude, linked by @AbdoLwiyen in the issue), cherry-picked onto currentmainand verified here. The cherry-pick keeps the original author.Tested
CachyOS Linux, kernel 7.3.1-1-cachyos, GCC 16.2.1, CMake 3.31.6, Ninja 1.12.1, Release build.
cmake --build build --target relinker: builds and links cleanly.ctest --test-dir build -R "guest_load_start_module_defer|guest_module_dir|guest_module_directories|guest_export_lookup" --output-on-failure: 4/4 pass.plain(nosceKernelLoadStartModuleimport; the bundled module starts at launch),loader(the import is present and nothing needs the module; it is deferred),loader-needs-bundled(the executable depends on it; it starts) andloader-needs-dependency(a deferred bundled module DT_NEEDs another; the dependency stays started on Linux). Without the fix theloadercase starts the module at launch, and without the Linux dependency fix the new case leaves onlylibkernel.prxin the executable'sDT_NEEDED; both fail the test.guest_load_start_module_defer,guest_deferred_dependencies,guest_module_dir,guest_module_directories,guest_export_lookup,needed_libraries,guest_unused_import_dependencies,guest_module_args,guest_load_ranges): 13/13 pass after rebuilding the staleguest_module_args_hostfixture andguest_load_ranges_tests. The earlierEnterGuestMainStack_nid_no_patchfailures came from that stale October fixture, not this change.python3 tools/check_conventions.py --base origin/main: passes.git diff --check: clean.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)