Skip to content

fix(relinker): defer bundled modules that a loader executable does not need - #15828

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
juanpimg:fix/relinker-defer-bundled-modules
Nov 10, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
juanpimg:fix/relinker-defer-bundled-modules

Conversation

@juanpimg

@juanpimg juanpimg commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #14153. The relinker starts every module bundled in sce_module/, sce_modules/ or prx/ at launch, even when the title later loads it with sceKernelLoadStartModule. A module that validates the arguments passed to module_start (PS5MC/Kodi's libkodi-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 (NID wzvqT4UqKX8), 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 of DT_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 import sceKernelLoadStartModule keep 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 new loader-needs-dependency case pins that.

This is the fix from commit 85885d8f51 (authored by Claude, linked by @AbdoLwiyen in the issue), cherry-picked onto current main and 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.
  • The new test covers four cases on Linux and Windows: plain (no sceKernelLoadStartModule import; 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) and loader-needs-dependency (a deferred bundled module DT_NEEDs another; the dependency stays started on Linux). Without the fix the loader case starts the module at launch, and without the Linux dependency fix the new case leaves only libkernel.prx in the executable's DT_NEEDED; both fail the test.
  • Focused relinker set (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 stale guest_module_args_host fixture and guest_load_ranges_tests. The earlier EnterGuestMainStack_nid_no_patch failures came from that stale October fixture, not this change.
  • python3 tools/check_conventions.py --base origin/main: passes.
  • git diff --check: clean.
  • No title was run: the contributor has no PS5 and no game dumps.

Checklist

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Nov 4, 2026
@Nciibi

Nciibi commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Windows verification of this head (the fix content is identical to a copy I rebased onto current main 9ab6a281ea and built here):

  • Windows 11, WinLibs GCC 16.2.0 (UCRT, POSIX), Release, relinker-only build with -DBUILD_TESTING=ON.
  • On unpatched main the new test fails on both systems' assertions: Linux, the loader case still has $ORIGIN/app0/sce_module/bundled.prx.guest.prx in DT_NEEDED; Windows, the loader case's converted module still exports __aps5_guest_initialize. With this change both pass.
  • Focused: guest_load_start_module_defer, guest_module_dir, guest_module_directories, needed_libraries, guest_deferred_dependencies, guest_unused_import_dependencies — 6/6 pass.
  • Full relinker-only ctest -j 8: 688/691. annotate_module timed out once under parallel load and passed on rerun. test_registration and select_tests_MissingCommandTests fail on this host because it does not hold the Windows symlink privilege (WinError 1314); they fail the same way on unmodified main.
  • python tools/check_conventions.py --base origin/main: passes.

AI-assisted: yes.

@blawesom

blawesom commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Linux verification of head befca70b9f (CachyOS, kernel 7.3.1, GCC 16.2.1, Ninja 1.13.2, Release, -DANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON). This closes the platform gap left by the Windows check.

Focused

  • guest_load_start_module_defer (including the new loader case) plus guest_module_dir, guest_module_directories, guest_export_lookup, needed_libraries, guest_deferred_dependencies, guest_unused_import_dependencies: 7/7 pass.
  • Deferral neighbours guest_module_identity, guest_symbolic_modules, sce_module_path, guest_host_libc, linux_named_imports, windows_named_imports, guest_zero_finalizer: 7/7 pass.

Full relinker-only suite

  • ctest -j16: 687/687 pass, zero failures or skips — so on Linux the suite Nciibi ran on Windows is fully clean (the three failures there were host-specific: the symlink privilege and a parallel-load timeout).

Conventions

  • python3 tools/check_conventions.py --base origin/main: passes.

Code reading

  • The gate is generic: executableLoadsModules is keyed on the sceKernelLoadStartModule NID base, not a title value, and the check now runs before the declaresHost continue so the Linux host-libkernel case is covered. A module stays required through the executable's DT_NEEDED closure, relocation-referenced providers, or (Windows) image dependencies, so the residual deferral risk is a loader-style title that expects a bundled module to auto-start with none of those — which contradicts PS5 loader semantics and is the case the old behaviour broke. The new test's three cases × two platforms pin exactly this boundary.

AI-assisted: yes

@github-actions github-actions Bot added build relinker docs fix error Closes an issue (Fixes #N) review queue Next in the maintainer review queue: checks pass, no open change request, no conflict labels Nov 4, 2026

@BunnyFl BunnyFl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

  • isRuntime now also covers a standard-directory module when executableLoadsModules is set (core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:321 at this head). Everything that require reaches 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:332 on the merge with main, from #15370). Only a module nothing depends on is deferred.
  • On Linux, deferLinuxStart (core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:509 at this head) keeps the old rule for runtime directories and adds the standard directories only for modules that are not required.
  • Moving the wzvqT4UqKX8 check above the declaresHost skip 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_defer included: 33 of 33 pass.
  • Negative control: guest_load_start_module_defer with GuestModuleBuilder.cpp from main fails on the linux/loader case, which still lists $ORIGIN/app0/sce_module/bundled.prx.guest.prx in DT_NEEDED.
  • The full relinker-only suite (713 tests, -j8): the merge and plain main share the same three failures on this machine (test_registration, select_tests_MissingCommandTests and one check_compile Windows response-file test). The merge also timed out annotate_module and one trace_digest CLI test; both pass when re-run alone (9.4 s and 7.3 s). They are presumably load timeouts at -j8 rather than regressions; I haven't checked beyond the re-run.
  • tools/pr_overlap.py --branch on this head: no line overlaps among the PRs it could compare. Of the 21 it could not, three change GuestModuleBuilder.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 feeds required here; worth a re-run if it lands first.

@github-actions github-actions Bot added review queue Next in the maintainer review queue: checks pass, no open change request, no conflict and removed review queue Next in the maintainer review queue: checks pass, no open change request, no conflict labels Nov 6, 2026
@milescoviello

milescoviello commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Retail data point. I relinked three unwrapped PS5 executables with the main 9a4bcc3018 relinker and with this head merged onto it (28e0692971), then compared the DT_NEEDED lists. Linux, GCC 15.2, Release.

Title DT_NEEDED, main / PR deferred by the PR
Steins;Gate RE:BOOT (PPSA36591) 37 / 37 none
Call of Duty: Black Ops II (PPSA34502) 48 / 48 none
Metal Gear Solid 4 (PPSA18194) 45 / 38 7

The seven MGS4 deferrals are libSceFontGsm, libSceJobManager, libSceNpCppWebApi and libScePfs from app0/sce_module, plus libSceFont-module.prx, libSceJson2.prx and ulobjmgr.prx.

MGS4 on the PR libraries still boots through the launcher to its title tree and holds 59.9 fps there, no worse than main, with no fault in a 154 s run. The run log doesn't show the later sceKernelLoadStartModule calls at the default log level, so this checks only that deferring the seven doesn't break start-up up to the title tree. It says nothing about what happens when the game loads them.

AI-assisted: yes (Claude Code)

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

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 15245 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L241-242

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 4847 docs/user/USAGE.md
PR 5021 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6149 core/relinker/CMakeLists.txt
PR 6924 docs/user/USAGE.md
PR 7642 docs/user/USAGE.md
PR 9345 docs/user/USAGE.md
PR 9508 docs/user/USAGE.md
PR 10193 docs/user/USAGE.md
PR 10792 core/relinker/CMakeLists.txt
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 10861 core/relinker/CMakeLists.txt
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 11525 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
PR 11628 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 11661 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 11689 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 11698 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 12678 core/relinker/CMakeLists.txt
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 12910 docs/dev/debt/relinker.md
PR 13486 core/relinker/CMakeLists.txt
PR 13716 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 13928 docs/user/USAGE.md
PR 13929 docs/user/USAGE.md
PR 14212 docs/dev/debt/relinker.md
PR 14214 docs/dev/debt/relinker.md
PR 14241 docs/dev/debt/relinker.md
PR 15642 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 15896 core/relinker/CMakeLists.txt
PR 17451 core/relinker/CMakeLists.txt
PR 17473 core/relinker/CMakeLists.txt

@github-actions github-actions Bot added review queue Next in the maintainer review queue: checks pass, no open change request, no conflict and removed review queue Next in the maintainer review queue: checks pass, no open change request, no conflict labels Nov 7, 2026
@oneandonlydean oneandonlydean self-assigned this Nov 7, 2026
@juanpimg

juanpimg commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Note for merge order, from the overlap bot: PR 15245 (open, CLEAN) also edits GuestModuleBuilder::Build around lines 217–247, and this PR has hunks at 220, 238–239, 312 and 503. The features differ — 15245 resolves a needed module on the executable that exports its imports, while this PR defers bundled modules a loader executes — so whichever lands first, the other should be rebased. No shared exports or tests.

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@BunnyFl

BunnyFl commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@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 befca70b9f again:

  • The loop that keeps a module's dependencies started is Windows-only: if (windows) for (const auto dependency : dependencies[index]) require(dependency); (core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:332).
  • So on Linux, with the sceKernelLoadStartModule import, a standard-directory module that only another deferred module needs is not required, and deferLinuxStart (core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:509) writes it deferred as well.
  • InitializeLinuxGuestModule (core/libs/prx/libkernel/Module/src/DynamicLoader.cpp:211 on main 9e47f0c3ac) returns for any handle but the requested one (if (owner != requested) return; at :220), so that dependency's lifecycle table would not run when the title loads the module that needs it.

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 test_guest_load_start_module_defer.py that gabichuuuuu describes, I'll re-run the relinker tests on the new head and say so here.

claude and others added 2 commits November 8, 2026 01:36
…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)
@juanpimg
juanpimg force-pushed the fix/relinker-defer-bundled-modules branch from befca70 to 72359c8 Compare November 8, 2026 00:45
@juanpimg

juanpimg commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@BunnyFl @gabichuuuuu both points are addressed in 72359c8c10, on top of a rebase onto current main:

  • Linux dependencies: when the executable imports sceKernelLoadStartModule, the standard-SDK-folder dependencies of every module are now required, so a bundled module that another deferred module needs stays started and keeps its initializer. The Windows path is unchanged (the condition is still true there).
  • Regression case: test_guest_load_start_module_defer.py adds loader-needs-dependency — bundled.prx DT_NEEDs dependency.prx and the executable needs neither. On Linux the dependency stays in the executable's DT_NEEDED; on Windows it does not carry the deferred sweep export. Without the one-line fix the new Linux case fails with only libkernel.prx in DT_NEEDED; with it the test passes.
  • Debt: the bullet no longer says standard SDK folders keep their mapping initializer. It records the new Linux behaviour and keeps the remaining --module-dir limitation.
  • macOS: behaviour is unchanged (the module still appears in the load list), so USAGE's "Linux and Windows" still matches.
  • Base: rebased from 4,463 commits behind. Focused relinker set is 13/13 after rebuilding the stale guest_module_args_host fixture — the EnterGuestMainStack_nid_no_patch failures were that fixture, not this change.

Checks on the new head are running.

@BunnyFl

BunnyFl commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

@juanpimg, the re-run I said I'd do, on 72359c8c10 (merged onto main locally, clean merge); thanks for the fix and the new case, and thanks again @gabichuuuuu.

Windows 11, WinLibs GCC 15.2, Release:

  • The relinker's guest_* tests at this head, including the generated guest_none_relocations_* cases: 39 of 39 passed.
  • With main's GuestModuleBuilder.cpp, guest_load_start_module_defer fails on the linux/loader case (main has no deferral), the other 30 of the 31 non-generated tests pass.
  • With only your one-line change reverted (if (windows || executableLoadsModules) back to if (windows) at core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:332), guest_load_start_module_defer fails on the new case: AssertionError: ('linux', 'loader-needs-dependency', ['libkernel.prx']).

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.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @juanpimg, thanks for the dependency fix. One small docs point that does not block anything: docs/user/USAGE.md:17 says the deferral applies "On Linux and Windows", but the code defers on macOS too (GuestModuleBuilder.cpp:332 has no platform check, :435 drops deferred modules from the needed list for every non-Windows build, and :496 sets DeferInitialization on all platforms). Could that sentence say "On Linux, macOS and Windows"?

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 72359c8c10, merged onto main 4ab649f4d8 (3854c6eff1, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_load_start_module_defer passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions github-actions Bot added the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 8, 2026

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@juanpimg

juanpimg commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I checked this against the writer path before changing the sentence, and macOS does not defer the module today:

  • WriteMacOs receives the needed vector built from all dependencies (GuestModuleBuilder.cpp:512) and writes every entry into input.Dylibs (MacOsGuestModuleWriter.cpp:96), so a bundled module stays in the load list.
  • DeferInitialization and the !windows && !deferred filter at :435 feed the Windows and Linux writers: dynamic.DynamicSegmentData is the ELF DT_NEEDED data, and runtime.DeferInitialization is consumed by the Windows writer only.

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.

@XIIYAZ

XIIYAZ commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

macOS check of head 72359c8c10, merged onto main 52c33518f8 (f0faa3cdb3, clean merge).

Setup: macOS 26.7, Apple M4, Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2, Python 3.15.0, Release, -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, built twice: native arm64 and -DCMAKE_OSX_ARCHITECTURES=x86_64 (tests run under Rosetta). The automatic macOS PR job covers arm64 only.

  • Full relinker suite: 770/770 on arm64 and 770/770 on x86_64; main alone is 769/769 on both.
  • guest_load_start_module_defer against main's relinker fails at ('linux', 'loader', ['$ORIGIN/app0/sce_module/bundled.prx.guest.prx', 'libkernel.prx']).

macOS output, on the USAGE.md question above. The test checks Linux and Windows only, so I converted its four fixtures (same helpers) with --macos and read the executable's LC_LOAD_DYLIB entries with otool -L:

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.prx.guest.prx, bundled.prx.guest.prx dependency.prx.guest.prx

(paths are @executable_path/app0/sce_module/...)

So the macOS executable drops the deferred module from its load commands, the same way the Linux DT_NEEDED list does, and keeps the dependency in the last case. Whatever WriteMacOs writes into the module's own input.Dylibs, the executable no longer loads it at launch. I did not run a converted title or check that a later sceKernelLoadStartModule loads it on macOS. On this evidence "On Linux and Windows" in docs/user/USAGE.md leaves macOS out.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @juanpimg, thanks for walking through the writer path. Reviewed at 72359c8.

@XIIYAZ's macOS run above settles the docs/user/USAGE.md question. With this head, the converted loader executable has no LC_LOAD_DYLIB for bundled.prx.guest.prx (on main it does), and loader-needs-dependency keeps only the dependency. That matches GuestModuleBuilder.cpp:435. The executable's needed list skips deferred modules for every non-Windows build (!windows && !deferred(index)), so macOS too, whatever WriteMacOs puts in the module's own input.Dylibs.

Could the sentence on line 17 say "On Linux, macOS and Windows"? If you haven't seen a later sceKernelLoadStartModule load the deferred module on macOS, a short note saying that path is untested there would also help. Nobody has run a converted title on macOS yet. This is a doc change only; the code is fine.

@juanpimg

Copy link
Copy Markdown
Contributor Author

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 WriteMacOs's own Dylibs list does not change that.

Updated docs/user/USAGE.md: "On Linux, macOS and Windows", plus a sentence that loading a deferred module later with sceKernelLoadStartModule has not been run on macOS. The debt entry stays as it is; it only claims the needed-module startup behaviour.

@github-actions github-actions Bot added review queue Next in the maintainer review queue: checks pass, no open change request, no conflict and removed review queue Next in the maintainer review queue: checks pass, no open change request, no conflict labels Nov 10, 2026
@oneandonlydean
oneandonlydean merged commit 4183518 into boykopovar:main Nov 10, 2026
14 checks passed
@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 10, 2026
@mrfelek

mrfelek commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@juanpimg @oneandonlydean this change stops PPSA22408 at startup on Linux. Converted with current main, the title crashes about 10 s in, while its bundled kitt_data_eos module starts. With only this merge reverted, it starts again.

Setup: Linux 7.3, GCC 15.3, Release, RTX 3080 Ti. The title's eboot.elf, sce_module/ and prx/ were converted with relinker --registry src/eboot.elf app.elf, and the runs started it with no input.

How it was found: I bisected main's first-parent history between 21eac6dd8b (good) and 0cf873937f (bad). Each step:

  • built the relinker;
  • converted the title;
  • ran it for 30 s with the same, older libraries (3e089775b9), so only the converted executable and modules changed.

Good means it gets past module start and stops later on the title's known sceHttp2SendRequestAsync not implemented. Bad means it crashes as kitt_data_eos starts. The first bad commit is 41835185e8, this PR's merge. 0cf873937f with that merge reverted (git revert -m 1 41835185e8) is good again.

The crash, on 0cf873937f:

Started module kitt_data_eos -++EOSSDK+KITT-Release-2.4-CL-49426010 12000038 2.4.4 freska- (final LTO)
[libc] fatal SIGSEGV (code 128) at address 0x0000000000000000 in thread ...
  rip 0x00007d0ec8570360 libkernel.prx+0x114360
  rax 0x73702d736f655f61 ...
    #1 ... kitt_data_eos-ps5-shipping.prx.guest.prx+0x5c20
    #2 ... kitt_data_eos-ps5-shipping.prx.guest.prx+0xefd650
    #3 ... ld-linux-x86-64.so.2+0x2cfd

rax holds ASCII (a_eos-ps), not a pointer.

What changes in the output: the executable imports sceKernelLoadStartModule, so with this change five modules in standard folders lose their DT_INIT. Nothing else in their dynamic sections changes:

  • prx/kitt_data_eos-ps5-shipping.prx.guest.prx
  • prx/kitt-ps5-shipping.prx.guest.prx
  • sce_module/libScePfs.prx.guest.prx
  • sce_module/libSceFontGsm.prx.guest.prx
  • sce_module/libSceJobManager.prx.guest.prx

The crash is under the host loader's call into kitt_data_eos (frame #3). My guess is that a module starts while one it relies on hasn't run its initializers, but I haven't traced which call starts it, or which of the five it relies on.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs fix error Closes an issue (Fixes #N) relinker unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

relinker: bundled sce_module modules start at launch, so sceKernelLoadStartModule's arguments never reach them (PS5MC)