feat(relinker): load Linux executables at a fixed base #4593
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4593"
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 Recapi on 2026-10-12T16:26:54Z.
What
Linux side of #4013, the counterpart of #4140's
--windows-fixed-base. Ruffle (PPSA68091), VLC (PPSA85300) and XPSemu (PPSA97358) read GOT slots atoffset + 0x400000, where each offset comes fromapp0/imports.txt, so they assume the console's load address. The relinked Linux executable is a PIE loaded at0x555555554000, and the first read faults.The relinker option.
relinker --linux-fixed-base <address>writes the executable asET_EXECand adds the address to every virtual address it holds, so virtual address 0 lands at the address, as on the console:PT_NULLandPT_GNU_STACK;DT_STRTAB,DT_SYMTAB,DT_HASH,DT_RELA,DT_JMPREL,DT_PLTGOT);R_X86_64_RELATIVEandR_X86_64_IRELATIVE, whichld.sono longer adds a load bias to;SHN_ABSandSTT_TLSsymbols stay unchanged.It throws instead of writing an image that would not load:
RELATIVEtarget below the image;DT_NEEDEDin the executable's dependency table;PT_LOADalignment;The CLI takes a 64 KiB-aligned address from
0x10000through0x7fffffff0000, in decimal or hexadecimal, and rejects the option with--windows,--macosor--lazy-binding. Lazy binding would need the PLT slots' initial contents rebased, and it is deprecated. Bundled guest modules keep their normal placement. Without the option the output is unchanged: the DOOM catalog executable relinks byte for byte the same as withmain's relinker.The libkernel fix.
dlsymin the default scope recognized the main program by comparingdladdr'sdli_fbasewithdl_iterate_phdr'sdlpi_addr. For anET_EXECimage these differ:dlpi_addris 0 anddli_fbaseis the image's first page, so symbols of a non-PIE executable were not found. It now compares link maps, taken fromdladdr1(RTLD_DL_LINKMAP)anddlinfo(dlopen(NULL), RTLD_DI_LINKMAP).Tested
Linux (Ubuntu, GCC, Release, NVIDIA RTX 2080 SUPER) on
maind592d54:sce_module/libc.prxunwrapped:main:SIGSEGVatcmpq $0x0,0x400000(%rax),rax= 0x24d5370, as in #4013.--registry --linux-fixed-base 0x400000: the output isET_EXECwith entry 0x2d8ecd0 (0x298ecd0 + 0x400000). The import check passes, and the title opens VideoOut, builds its shaders and renders, then stops at an unrelated AGC limit:only normal color rendering with copy ROP is supported (CB_COLOR_CONTROL 0x00cc0050, mode FMASK decompress).linux_fixed_basetest:0x400000 + entryand that itsRELATIVEslot holds that address (SIGTRAPon success);RELATIVEtarget.linux_executable_exportsnow also runs at a fixed base, wheredlsym(RTLD_DEFAULT)from a needed library resolves an executable export. Without the symbol rebasing it fails withSIGSEGV.guest_dynamic_loader_fixed_base:GuestDynamicLoader.cppbuilt with-no-pie. Before the libkernel fix it aborts (sceKernelDlsym(0, GuestDefaultScopeOnly)misses the executable symbol); after the fix it passes.cli_argscovers parsing, the range, alignment, malformed values, repetition and the conflicts.check_conventions.pyandcheck_test_registration.pypass.linux_fixed_base,guest_dynamic_loader_fixed_base,linux_executable_exportsandcli_argspass on Linux. The branch merges cleanly onto currentmain2a5eca1.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)Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-12T16:40:18Z.
The overlap check on #4140 lists this PR. The two only touch the same lines: both add an option to
Cli.hpp,CliArgs.cpp(the usage string and the parser),CliArgsTests.cppand theUSAGE.mdtable. The code paths are separate: #4140 changes the Windows PE writer, and this PR changes the Linux ELF patcher and libkernel'sdlsym. Neither depends on the other, and whichever lands second needs only a mechanical rebase. I'll do it here if #4140 goes first. @veosett, I'm happy to rebase on yours or follow your parsing style if you prefer one address parser for both options.Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-12T18:53:12Z.
Rebased onto
main1acfa7f. The only conflict was an#includeinDynamicLoader.cpp, wheremainhad dropped<set>. After the rebase on Linux: ctest 973/973, andcheck_conventions.pyandcheck_test_registration.pypass.More from Ruffle (PPSA68091) with
--linux-fixed-base 0x400000, with this PR onmain1acfa7f:/data/ruffle/ruffle.log(dup2, #2478), so the run shows up there.SIGSEGVright aftercan't write /data/ruffle/ruffle.log.[Library] 0 gamesand presents 2,400 frames in 60 s. It ran until the timeout.only normal color rendering with copy ROP is supported (CB_COLOR_CONTROL 0x00cc0050, mode FMASK decompress). That is AGC and outside this PR; I'm looking at it separately.Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-12T19:25:25Z.
Tested on Linux with PPSA15304 (engine: Unreal Engine 5), a second case besides #4013 that needs the console's load address. Its bundled
libc.prxcreates a "Low Address Malloc" mspace over a static buffer inside the executable and rejects a base outside the application area0x200000000..0xFC00000000. With the PIE at0x555555554000the creation returns NULL, and the title faults in its global constructors beforemain. #3043 describes the same check on Windows.--registry --linux-fixed-base 0x400000000on head03dd25f99: the output isET_EXEC, and its relocations (1,300,490RELATIVE, 2,430R_X86_64_64, 19GLOB_DAT) match, in offset and addend, those of an image rebased by hand to the same address.Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-12T20:16:52Z.
Thanks @ee6aba54, that's a good second case. It also exercises a base above 4 GiB (
0x400000000), where the image has to fit the console's application area rather than0x400000. It's good to know the 1.3MRELATIVErelocations match a hand-rebased image.Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-13T10:40:20Z.
Rebased onto
mainc7632f036; new head4fd9e6ea7.The conflicts were in the CLI usage string and
main.cpp. Current main moved image conversion intoRelinker::Conversion, so the fixed-base option now passes throughConversionOptions::LinuxFixedBaseto the Linux patcher there. The new--executablesupport and conversion progress are retained; bundled PRX modules keep their normal placement.Verification on Linux, GCC 15, Release, NVIDIA RTX 2080 SUPER:
linux_fixed_base,linux_executable_exports,relinker_conversion,relinker_executables,cli_args,guest_dynamic_loaderandguest_dynamic_loader_fixed_baseall pass.0x400000000): ET_EXEC and rebased entry, bundled module bytes unchanged; non-Linux targets reject the option.--linux-fixed-base 0x400000 --executable other.binproduces both executables as ET_EXEC at0x400000, with the bundled module still ET_DYN.--registry --linux-fixed-base 0x400000and the rebuilt libraries, ran for 40 s until timeout (exit 124). Its log records 3,000 presented frames,[Ruffle] Player started, the game loop, and a return to the library. Quality remains Low (quality=0), the workaround for #4685; this is not a claim of MSAA support or gameplay with an external SWF.Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-13T11:40:03Z.
Updated the base again to
maine99a1b0aa(41 more main commits); new head5e7471794. This rebase applied without conflicts and adds no new feature changes. Full Linux Release build succeeds; CTest has 1,031 passed, 8 skipped, no failures (1,039 registered). Conventions and test-registration checks pass. Ruffle (PPSA68091, catalog 1.2.0), freshly relinked with--registry --linux-fixed-base 0x400000and the rebuilt libraries, runs its library UI for 30 s until timeout (exit 124), logging 2,400 presented frames. The Flash player was not entered in this run.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:42:57Z.
Rebased onto current
main(conflicts with #4140's--windows-fixed-baseinCli.hpp,CliArgs.cpp,CliArgsTests.cppandUSAGE.md; both options are kept, and the usage string lists both). Also adjusted theUSAGE.mdsentence that said the Windows option "does not change Linux output".Checked: relinker + libkernel build and 248/248 ctest (
linux_fixed_base,guest_dynamic_loader_fixed_base,linux_executable_exports,cli_args,relinker_conversion,windows_fixed_base); the new tests don't build without the change. Merging once the full build is green.Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-13T15:40:57Z.
Thanks @adriadam10 for the rebase. Verified
66b3c810con Linux (GCC 15, Release, RTX 2080 SUPER): full build, full CTest 1,059/1,059. Ruffle (PPSA68091) relinked with--registry --linux-fixed-base 0x400000runs its library UI for 30 s until timeout, 2,400 presented frames.Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-13T16:13:55Z.
Rebased onto
mainafter #4547 (--trace-imports); new headc25a5783e. The conflicts were additive inCli.hpp,CliArgs.cpp(usage string and option checks) and theUSAGE.mdtable; all options are kept. Linux (GCC 15, Release): full build, full CTest 1,071/1,071, conventions and test-registration checks pass.--windows --trace-imports --windows-fixed-base 0x400000still converts. Ruffle (PPSA68091), relinked with--registry --linux-fixed-base 0x400000, runs its library UI for 30 s until timeout, 2,400 presented frames.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T18:37:38Z.
XPSemu (PPSA97358), the third title in #4013, on Linux (headless): on
main18c438b1with #5061 merged, every import resolves and it segfaults on its GOT read. Relinked with--linux-fixed-base 0x400000from this PR (c25a5783, clean merge), it runs past that togetrlimit(RLIMIT_NOFILE)(#5187), and with that too, into xemu's start-up and its GPU probe (details in #5061).Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-13T18:50:44Z.
Thanks @babyhuey. That makes XPSemu the second #4013 title past the GOT read on Linux, after Ruffle, and it shows the option works together with #5187.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T10:50:07Z.
Rebased onto current
main(one conflict indocs/user/USAGE.md: both options kept, the Windows paragraph now says it does not change macOS output) and added one commit: droppedR_X86_64_DTPMOD64,R_X86_64_DTPOFF64,R_X86_64_TPOFF64andSTT_TLSfromElfConstants.hpp, whichmainalready defines and broke the build.Checked: relinker + libkernel build and 263/263 ctest (
linux_fixed_base,guest_dynamic_loader_fixed_base,linux_executable_exports,cli_args,conversion); the new tests don't build or pass without the change. Confirmed on XPSemu (PPSA97358) by @babyhuey and PPSA15304 by @ee6aba54; merging once the full build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T10:53:59Z.
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.
main)core/libs/prx/libkernel/CMakeLists.txtL208core/relinker/cli/src/CliArgs.cppL13