fix(relinker): read the PS4 needed-module tag in guest modules #6381
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6381"
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 SandstromPL on 2026-10-15T13:43:06Z.
What
Until Dawn (CUSA02636) bundles
libc.prxandlibSceFios2.prx(01.00). Their conversion stops inGuestModuleBuilderwith:SuperCatElvis reported it on #3093 as stop 8 of the title's
--windowsconversion, onmaind92a8da. He had the open #5138 applied and scratch fixes for his other stops: "these modules list their dependencies in 0x6100000f, not 0x61000045; falling back to it fixes the order".GuestImageReadertakes a guest module's import modules only from0x61000045, the PS5 needed-module tag. PS4 modules use0x6100000f(DT_SCE_NEEDED_MODULE) instead. Both tags have the same layout: module ID in bits 48-63, a version in bits 32-47 (not read here), name offset in the low 32 bits. Sources:Elf.hL86-L87). It decodes them with one function (RuntimeLinker.cppL300-L315, called at L1367-L1368).linker.cppL688-L705).create-fselfwrites one0x6100000Fper imported module (PS4Constants.goL25,OELFGenDynlibData.goL992-L997), in that layout (L882-L888).The reader already accepts both forms of the export tag (
0x6100000dand0x61000043).So no import of a PS4 module had a library, and each bound to any guest export with its NID. A
libc.prximport declared from another module then bound to an export oflibSceFios2.prx, which itself needslibc.prx, and the initialization order became a cycle.The reader now also reads
0x6100000f, so a PS4 module's imports are tied to their declared modules, as a PS5 module's already are. A module that has both tags fails withGuest module mixes PS4 and PS5 needed-module tags. Kyty (RuntimeLinker.cppL1363) and RPCSX (linker.cppL803-L806) reject that too.This changes how PS4 modules are converted, including modules built with OpenOrbis
create-fself. Each change is what PS5 modules already get:DT_NEEDEDis no longer bound by NID across all modules.libc.prxif the program's library list has it, and forlibSceLibcInternal.prxalso in a bundledlibc.prx(WindowsEntryStubBuilder.cppL155-L165). Before, every loaded library was searched.Failed to load module, where before it was skipped.unresolved ELF import.libSceDiscMap.prxfunctions thatlibSceFios2.prximports. A separate PR will add that library.DT_NEEDEDstill binds by NID alone, as before. On Windows, a host library with that module's name (up to the first dot, ignoring case) becomes a required load.Unknown import module ID: the ID has no needed-module entry.Invalid qualified import,Invalid import module ID,Invalid import module nameorDuplicate import module ID.Ambiguous import module dependency: the declared module matches twoDT_NEEDEDnames.Not changed: executables.
RelinkerPipelinestill reads only0x61000045, so the imports of a PS4 executable keep binding by NID alone; no title needs that yet.Tested
Ubuntu 24.04, GCC 13.3, Release with
BUILD_TESTING=ON, onmain97aac6242. Locally the libusb submodule isn't checked out, so I removed its two lines fromCMakeLists.txt.libSceUsbdthen fails to compile, andninja -k 0built everything that does not depend on it.guest_symbol_names(relinker/tests/test_guest_symbol_names.py) gains these cases:libSceLibcInternal.prxthrough0x6100000f, next to a guest module exporting the same NID0x61000045sce_module/libc.prxexports X and imports Y fromlibkernel.prx;libSceFios2.prxexports Y and imports X fromlibc.prx(the shape of stop 8), with0x6100000f, Linux and Windowslibc.prx's import of Y stays a host import,libSceFios2.prx's import of X binds tolibc.prx, andlibc.prxcomes beforelibSceFios2.prxin the executable'sDT_NEEDED0x61000045(control)mainGuest module mixes PS4 and PS5 needed-module tags#A#C(module ID 2, not listed) through0x6100000fUnknown import module IDlibFoo) is not in itsDT_NEEDED(libFoo2.prx), through0x6100000fshared#guest), as onmaintest_windows_import_modules.py'sconsumer()gains aneeded_module_tagparameter (default0x61000045), so existing callers are unchanged.On
main:shared#guestinstead ofshared.Cyclic guest initialization dependency: .../sce_module/libSceFios2.prx, the line in the report.With the change all cases pass, and so do
windows_import_modules,guest_module_identityandguest_registry(which useconsumer()), 5 runs out of 5. The Windows required-load behaviour comes from the existing code path for PS5 modules (WindowsEntryStubBuilder.cpp); no new test checks the load order.Other checks:
cteston the RTX 3050 Ti: 1,253 of 1,257 pass, and all relinker tests pass.agc_driver_stencil_ref_exporton this GPU, and the VideoOut flip and frame-dump tests, which need a display.patched_librariesandguest_usbdare Not Run, because the libusb submodule isn't checked out.agc_pending_key_storesfails onmainsince #6247, as reported there.agc_driver_store_over_untrackedfails intermittently when run alone here.mainf633042dfwith #5990 to #5994, #5138 and #6376.using_librarystill starts and calls intolibExample.prx, acreate-fselfmodule withDT_NEEDED libkernel.prxand one0x6100000fentry. Its import stubs now namelibkernel.prx.__error, which AnyPS5 exports fromlibc.prx, still resolves through thelibc.prxstep.sce_module.mainb7cedd900, relinker-only builds for arm64 and for x86_64 under Rosetta.main.guest_symbol_namesfails onmainwith only the test changes, and passes with the fix.--macos, which the new test doesn't cover,mainstops the0x6100000fpair with the same cycle. With this PR both tags convert, the Mach-O load commands are identical for the two, and dyld initializeslibc.prxfirst.main4186f06a9. Six open PRs touch these files (#3965, #5138, #5981, #6112, #6325, #6357), and none of them gets a new conflict.main, incore/relinker/CMakeLists.txtanddocs/dev/debt/relinker.md, and has the same two conflicts with this PR merged. ItsGuestImageReader.cppline is in the lifecycle-array block, apart from this PR's hunks.main4186f06a9, this PR and #6112 passes all 182 relinker tests, including #6112'sguest_preinit.tools/check_conventions.pyfrommainpasses with this title and body.@Get-fix, thanks for running the OpenOrbis samples. @SuperCatElvis, could you check that this gets
libc.prxandlibSceFios2.prxpast stop 8, and say whichlibc.prximport resolved tolibSceFios2.prx?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)libc.prxandlibSceFios2.prx); CUSA03312 #7198 (Hasbro Family Fun Pack: stop 7 in savvaniss's conversion); CUSA02636 (no Game bring-up discussion): stop 8 of SuperCatElvis's--windowsconversion on #3093, in the bundledlibc.prxandlibSceFios2.prx.main. A full conversion scans the eboot first, and stop 1 (its jump tables) still stops it there.cteston NVIDIA GeForce RTX 3050 Ti Laptop GPU, driver 580.178.04, Ubuntu 24.04🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T14:00:05Z.
@SandstromPL Checked:
using_librarystill starts with this PR.libExample.prx(linked bycreate-fself) hasDT_NEEDED libkernel.prxand one0x6100000fentry,libkernel(module ID 1, version 0x101). I ran Windows 11 with WinLibs GCC 15.2, head6f8d9a09dmerged ontomainf633042dftogether with #5990 to #5994, #5138, #6376 and a local change that answers the LinuxTIOCGWINSZwithENOTTY:unresolved ELF import 9BcDykPmo1I from libkernel.prxinstead ofunresolved ELF import 9BcDykPmo1I.libc.prxrather thanlibkernel.prx, such as__error(9BcDykPmo1I), still resolve, through the lookup's hostlibc.prxstep.sce_module.pigletstops at its Piglet imports, as before.f633042df.AI-assisted: yes (Claude Code). I ran the builds, conversions and samples myself on Windows 11.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-15T14:07:03Z.
@Get-fix Thanks for running the samples! I've added your results to the description. That
__errorstill resolves through thelibc.prxstep is good to see: that step only searches alibc.prxalready in the program's library list, which your #5990 adds for a libkernel-only program likeusing_library.On the bot's note: it couldn't compare
GuestImageReader.cppwith #6112 because #6112 conflicts withmain, so I checked it by hand.mainalone (core/relinker/CMakeLists.txtanddocs/dev/debt/relinker.md).main4186f06a9+ this PR + #6112 passes all 182 relinker tests, including #6112'sguest_preinit(relinker-only build, Linux, GCC 13.3). Reverting this PR'sGuestImageReader.cppchange in that tree failsguest_symbol_namesas onmain, andguest_preinitstill passes.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T18:42:48Z.
Review: COMMENTED
Ran this on macOS. The new test converts with the Linux and
--windowstargets only, so I also checked the--macosoutput.Setup: Apple M2 Max, macOS 27.2, head
6f8d9a09dmerged without a commit ontomainb7cedd900(clean). Relinker-only Release builds for arm64 and for x86_64 under Rosetta (/usr/bin/python33.9.6).pr_overlap_tools,release_package,linux_fixed_base) fail the same way onmain(Python 3.9 issues unrelated to this PR).guest_symbol_nameswith only the test changes applied tomainfails on both arches (theguest-declared-ps4case still getsshared#guest); with the fix it passes.--macos, using the test'slibc.prx/libSceFios2.prxpair with each tag:main:0x61000045converts;0x6100000ffails withCyclic guest initialization dependency: .../libSceFios2.prx, the same stop as on Windows.output.elfloadslibc.prx.guest.prxbeforelibSceFios2.prx.guest.prx, andlibSceFios2.prx.guest.prxhas@loader_path/libc.prx.guest.prx, so dyld initializes libc first.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-15T18:48:22Z.
@jotitadev Thanks for the macOS run, and especially for checking
--macos, which the new test doesn't cover! Good to see the Mach-O load commands come out the same for both tags. I've added your results to the description.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T23:38:53Z.
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.
core/relinker/relinker/src/guest/GuestImageReader.cppcore/relinker/relinker/tests/test_guest_symbol_names.pycore/relinker/relinker/tests/test_windows_import_modules.pyImported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-18T20:59:46Z.
Second-title data point: Hasbro Family Fun Pack (CUSA03312, my own dump) needs this PR, on Linux and Windows.
Relinker-only Release build, Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7. Starting from
mainf3059421f, I merged, in this order: #7660, #6619 (a9fa0e8b0), #5138 (5f5641732), #6381 (6f8d9a09d),3b158c1e4from #6977, #6354 (81561867f), #6357 (32fe3aa8b), #6684 (ab9d21afc) and #6618 (bf06a8e5c). With that stack, the Linux and--windowsconversions of the eboot and its 9 bundled modules complete. I then rebuilt the relinker once per member with only that member left out. Without this PR, both targets stop in the eboot's module graph:The other members each stop at their own step, so every one of them is needed for this title; the whole table is on #6977.
AI-assisted: yes (Claude Code)