fix(relinker): resolve symbol-name imports through NIDs on Linux #9234
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9234"
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 mossyanwar on 2026-10-21T15:59:18Z.
What
Homebrew built with the ps5-payload-dev SDK needs
libkernel_web.sprx,libSceLibcInternal.sprxand so on, and imports by symbol name (memset,accept,__error). The libraries inlibs/are.prxfiles that export NIDs, so on Linux the converted executable stopped at the first.sprxdependency, and after that at the first symbol name (#9180). #6697 fixed the same thing on Windows.Linux output now:
.sprx,.suprxor.debug_prxdependency as the.prxlibrary of the same stem (Domain::NeededLibraryName, as on Windows);SysVDynamicSectionBuilderrecords these imports by relocation address inSysVDynamicSection::NamedImports, andLinuxElfPatcherrenames them after the guest module builder has run, so a name that a bundled module exports still binds to that module (shared#guest). Qualified imports and imports with a module are unchanged.Other executables keep their unqualified imports as written. Test fixtures import helpers such as
LoadExecFirst_nid_no_patchby name from host libraries that export them by name.Unlike Windows, there is no first lookup by the name as written:
ld.sosearches the global scope, which includes the host glibc and libstdc++ that every library inlibs/links, somallocorpthread_createwould bind to glibc. The SDK's own loader resolves these names by NID on the console (sprx_sym2addr). NoDT_NEEDEDis added forlibc.prxorlibkernel.prx, because every Linux library inlibs/already links both.The call registry and
needed.jsonare unchanged. The Windows debt entry now only mentions macOS, and a new Linux entry records what is still open: imports of bundled modules are still bound by name.guest_needed_modules,guest_module_identityandguest_needed_nested_modulesexpected a.suprxor.debug_prxhost dependency to be kept as written. It is now the.prxname.Tested
WSL2 Ubuntu 24.04, GCC 13.3, Ninja Release, on
main99844c7ee.New
linux_named_importstest. A host library built at test time exports9E8ipSX3c9g, the NID ofshared. An executable that importssharedwithout a module:DT_NEEDEDofavailable.sprx, which now loadsavailable.prxsharedand binds to a provider exportingsharedwhen it only needsavailable.prxundefined symbol: 9E8ipSX3c9gagainst a provider that only exportssharedas written, when it needsavailable.sprxsharedwhen the import isshared#A#Bshared#guestwhen a bundled module exportssharedOn
mainit fails at the first case: the output still importsshared, and running it givesundefined symbol: shared.Relinker-only build:
ctest239/239.Full build with
BUILD_TESTING=ON:loadexec_arguments,agc_driver_guest_memory_lifetime_converted,linux_named_imports,windows_named_imports,executable_tls_relocations,guest_needed_modules,guest_module_identityandguest_needed_nested_modulespass. With the relinker from the previous head28b31a306, the first two fail withundefined symbol: dt+StXeB4JQandundefined symbol: vIMLEVWjQbg, as @wail-arch reported. The rest of the full suite was not run.python3 tools/check_conventions.py --base origin/mainpasses.ftpsrv.elffrom the pacbrew-repo v0.41.1ps5-payload-daemons.zip(sha256ab59eb744eccd197d68af4d4a0b882940861e3c45010e766c83704188ff753a5), relinked with--skip-syscall-check --skip-sce-module --registry.--skip-syscall-checkis needed because its inline syscalls don't convert yet (#8624).main: needslibkernel_web.sprx,libSceLibcInternal.sprxandlibSceNet.sprx, and 84 of its 87 imports are plain names..prxnames, and all 87 imports are NIDs (__erroris9BcDykPmo1I,atoiisfPxypibz2MY). The call registry is identical tomain's.@rocklouis055 and @simonbbby ran the previous head against full
libsbuilds: SDKhello_worldand LÖVE load with every dependency a.prxname and every import a NID, then stop in the SDK's_start, which expects apayload_args_t*inrdi. That entry is outside this PR.Not tested: running on Windows or macOS. Those code paths are unchanged.
#9261, opened after this one, makes the same change and also covers imports of bundled modules.
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)Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-21T16:31:45Z.
Native Linux runtime check of exact head
28b31a306adb91e4e4a11c33b2736d44f3bad14e, following the request in #9180. The two import failures are fixed against real AnyPS5 libraries, but the unmodified SDK payload still stops in its bootstrap beforemain.Ubuntu 24.04.3, GCC 13.3, Release. I built the official ps5-payload-dev/sdk v0.44 hello_world source using the v0.44 SDK release and clang/lld 18. This is a newly built ELF, not the reporter's binary (SHA256
59ed5e733f97631d1bc94422ea07432fcd79046bc5076bf886bd72888401dfef). Its three undefined imports arememset,strncpy, andsceKernelSendNotificationRequest.I built the relinker separately at this head and at parent
cecb540a63f614d2b06cbb557c6d1f6f02475fa3, and rebuilt the fulllibstarget at the PR head, including NID patching. Both converted the same input with:Each output used the same freshly built
libsdirectory.libkernel_web.sprx. Providing isolated.sprxaliases then gives exit 127: undefinedsceKernelSendNotificationRequest..prxnames with no aliases.LD_DEBUG=bindingsconfirms guest6sJWiWSRuqkand8zTFvBIAIN8resolve tolibc.prx, andzl7hupSO0C0tolibkernel.prx. Startup then exits 139 at address1.The remaining crash is in the SDK's
__crt_syscall_init, atcall *(%rbx). The SDK treats its argument aspayload_args_t*, whose first member issys_dynlib_dlsym. AnyPS5's entry stub passes the initial process stack in RDI; GDB shows RBX pointing there, with first qword1(argc), which becomes the call target. This occurs before the sample'smainor notification call. Fresh libraries reproduce it, so the initial older-library result was not the cause.As a separate import-path diagnostic, I copied the input and changed only ELF
e_entryfrom_start(0x64) tomain(0). After conversion by this PR, it executes the sample body and prints[notification] Hello, world!; GDB shows EAX=0 on return, followed by SIGILL at the generated entry stub'sud2. This bypasses the SDK CRT and is not a successful unmodified-payload run. It does exercise the sample's three imports against the real runtime libraries.The PR's relinker-only CTest suite also passes 239/239. No repository source edits. This verifies the filename/NID fix and identifies a separate payload-entry ABI blocker; it does not establish that #9180's full SDK payload now runs.
Imported from boykopovar/AnyPS5. Originally posted by wail-arch on 2026-10-21T16:50:56Z.
Tried this branch with a full build (not relinker-only) on
cecb540a6, Ubuntu 24.04, GCC 13.3, as asked in #9180. Two tests that pass or skip onmainfail with this relinker:loadexec_arguments:undefined symbol: dt+StXeB4JQ(the NID ofLoadExecFirst_nid_no_patch)agc_driver_guest_memory_lifetime_converted:undefined symbol: vIMLEVWjQbgBoth fixtures import unqualified names that a host library exports by name, and both are registered only in the full build, so the relinker-only run stays green.
The executable side works on a real SDK binary: a probe built with the ps5-payload-dev SDK (own
_start,printf/getpid/strncpyby name) runs, with the calls bound inlibs/libc.prxandlibs/libkernel.prx.I have a branch that only rewrites images naming a
.sprx/.suprx/.debug_prxdependency, and also rewrites the named imports of bundled guest modules: https://github.com/wail-arch/AnyPS5/tree/fix/linux-sdk-homebrew-imports. Fullctestgives 1795/1802 (the 7 failures are IPv6/sandbox/root issues in my container). I'm opening it as an alternative so the maintainers can compare; happy to close it if you take these fixes into yours.Imported from boykopovar/AnyPS5. Originally posted by rocklouis055 on 2026-10-21T17:23:24Z.
Tried the branch (
28b31a306) against a fulllibsbuild ofmain7280a17ec: Linux x86-64, Ubuntu 26.04, GCC 15, Release, Intel Core Ultra 9 275HX, so--to-intel. The relinker was built from this branch (relinker-only build), the libraries frommain.Command, with no
.sprxaliases inlibs/:DT_NEEDEDsamples/hello_world(v0.44, sha2566fef8533…5d5e).prx8zTFvBIAIN8,6sJWiWSRuqk,zl7hupSO0C0)10ccd3ed…693f).prx__stderrpSo both failures from #9180 are gone on Linux.
The crash is outside this PR. Both jump to
0x1from the SDK's startup code (hello_world+0x463, in__crt_syscall_init). The SDK's_start(crt/crt.c, crt/payload.h) takes apayload_args_t*inrdifrom the ELF loader and callsargs->sys_dynlib_dlsym(...)first; run as a process,rdiis1. crt/syscall.c then takes the syscall address asgetpid+0xainside libkernel. Running these payloads needs an entry that suppliespayload_args_t, which belongs in a separate issue.Tested with AI assistance (Claude Code); the commands and outputs above were run locally.
Imported from boykopovar/AnyPS5. Originally posted by mossyanwar on 2026-10-21T17:50:31Z.
@wail-arch thanks, you're right. Rewriting every unqualified import broke fixtures that import
*_nid_no_patchhelpers by name. I've force-pushed a fix: unqualified imports are now only rewritten in an executable that names a.sprx,.suprxor.debug_prxdependency, the same condition your branch uses, and every other executable converts as onmain. With a full build,loadexec_argumentsandagc_driver_guest_memory_lifetime_convertedfail with the previous head (undefined symbol: dt+StXeB4JQ,vIMLEVWjQbg) and pass now. Your branch also rewrites imports of bundled modules. I've kept that out of this one and recorded it in the debt entry.@rocklouis055 @simonbbby thanks for running it against full
libsbuilds. Thepayload_args_tentry is separate from this PR, so a new issue for it makes sense.Imported from boykopovar/AnyPS5. Originally posted by wail-arch on 2026-10-21T19:12:27Z.
@mossyanwar Thanks. On
be51ab7,loadexec_argumentspasses andagc_driver_guest_memory_lifetime_convertedskips as onmain(full build, Ubuntu 24.04), and the relinker-only suite passes.I turned #9261 into the bundled-module follow-up, stacked on
be51ab7withDepends on: #9234: it applies the same rule to the modules an SDK homebrew ships next to its executable (their named imports and.sprxhost dependencies), so it only needs review once this one is merged.Imported from boykopovar/AnyPS5. Originally posted by rocklouis055 on 2026-10-21T19:47:57Z.
Re-ran on
be51ab7with the same setup as my earlier comment (fulllibsofmain7280a17ec, Linux,--to-intel):hello_worldand LÖVE: as on28b31a306. No.sprxdependency and no plain-name import is left (3 and 338 imports, all NIDs), both load, and both stop at the SDK startup'spayload_args_tcall, outside this PR..sprxdependency (thegpu_cubeexample of ps5link-sdk, NID imports):nm -D --undefined-onlyoutput identical tomain's, and it runs to its end, exit 0.I'll open a separate issue for the
payload_args_tentry.