fix(relinker): load Linux executables at 0x400000 by default #8973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8973"
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 rooklz on 2026-10-21T07:59:58Z.
What
Linux output is a PIE that the loader puts at
0x5555..., above 2^40. Titles that ship their ownlibc.prxcreate an mspace over a static buffer inside the executable, and thatsceLibcMspaceCreaterejects a buffer at or above 2^40 (#3043). Start-up then fails beforemain. #4237 fixed this for Windows by loading the executable low by default; on Linux it still needs--linux-fixed-base, which the web converter doesn't expose at all.This makes
0x400000the default Linux base, using the existing fixed-base path from #4593 (ET_EXEC, every address rebased). Why0x400000rather than the Windows0x140000000:0x400000+ offset (#4013) and run on a PS5;0x200000000);0x140000000and0x400000000both are.Details:
--linux-fixed-basestill picks another address.--lazy-bindingkeeps the PIE layout, since its PLT slots can't be rebased (same reason the two options already conflict), and the converter warns when it does that for Linux output. Bundled modules are unchanged.Entry stub call exceeds rel32 range), so at the default base the executable ends below the guest arena at0x200000000.test_linux_fixed_basepins both, and the debt entry says it.Relinker::Conversion, so the web converter gets it too.--verify-outputrefusedET_EXEC, which would have made it useless on default output. The conversion now writeslinux_baseto<output>.patches.tomlwhen the executable isET_EXEC, and--verify-outputchecks entries atva + linux_base. AnET_EXECoutput withoutlinux_base, or anET_DYNoutput with it, is an error. Reported addresses stay the manifest'sva.test_linux_fixed_basepins the default (byte-identical to--linux-fixed-base 0x400000), compares two bases instead of PIE vs fixed, and checks that--lazy-bindingstaysET_DYN.MappedImageinElfFixture.hppplaced segments at their vaddr counted from 0, so it now counts from the image's first page (no change for PIE images).Not in this PR: JIT memory within 2 GiB of the code (#5217) is still out of reach, since the arena starts at 8 GiB. PPSA99808 asks for a fixed mapping at
0x400000(libkernel debt); that is refused today because it's outside the arena, and it still is.APS5_TRACE_CALLSprints a caller in anET_EXECexecutable asapp.elf+<absolute address>, because it takes the offset fromdlpi_addr. That already happens with--linux-fixed-base; #8974 counts it from the image's first page instead.Tested
No title run on my side; I don't have these titles. The title evidence is from the bring-up threads: in #7972 and #7852, Monster Hunter Wilds (PPSA24191) stops at the mspace check on the default base and gets past start-up with
--linux-fixed-base 0x400000or0x400000000. VLC (#5732) and XPSemu (#5600) need exactly0x400000.123ba7083rebased onmain950388bfd: the relinker CI matrix on this PR passes (Ubuntu, which runs the converted executables, Windows, macOS arm64 and x86_64, ASan).test_linux_fixed_basenow also checks the--lazy-bindingwarning and the largest accepted image.c4a116f62:ANYPS5_ENABLE_SPIRV_TOOLS=ON), tests on lavapipe withANYPS5_REQUIRE_VULKAN=1, run on my fork for this branch and for its base7ab4b2e56: 1775/1779 on both, and the same four fail on both (agc_driver_sgpr_pattern_fill_keys,net_dontwait_blocking_send,net_dontwait_blocking_sendmsg,net_dontwait_blocking_sendto). The tests that relink an executable and run it against the real libraries pass at the new default:loadexec_arguments,agc_driver_guest_memory_lifetime_converted,linux_executable_exports,linux_entry_argv,linux_fixed_base,game_patches.to_intel_linux_stubscrashed before theMappedImagefix.check_conventions.pypasses.pr_overlap.pyreports no conflicting lines; the shared files it couldn't compare belong to PRs that conflict withmain.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 github-actions[bot] on 2026-10-21T08:21:53Z.
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)docs/user/USAGE.mdL66-67Some 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.
docs/dev/debt/relinker.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mdcore/relinker/relinker/tests/test_linux_entry_argv.pydocs/user/USAGE.mddocs/user/USAGE.mddocs/dev/debt/relinker.mddocs/user/USAGE.mddocs/dev/debt/relinker.mdImported from boykopovar/AnyPS5. Originally posted by mpratsaki on 2026-10-21T13:04:26Z.
Independent conversion check on public homebrew. Conversion only, nothing was run.
Windows 11, WinLibs GCC 15.2.0 r7, relinker-only Release. Base:
main2abfb1beb. Candidate: the samemainwith this PR's headc4a116f62merged on top (no conflicts), so the only difference is this PR. Inputs: 18 distinct ELFs from public ps5-payload-dev releases (gdbsrv, klogsrv, elfldr, shsrv from the daemons bundle; websrv v0.34 bundles EDuke32, LakeSnes, Omnispeak, OpenJazz, PKGInstall, Wolf4SDL ×2, DevilutionX, FFplay, LinkDev, OffAct, Mednafen, VVVVVV; JTPlay, TVHP). All conversions use--trap-sdk-syscall-stubs --skip-sce-module.For all 18:
--windowsand--macosoutputs are byte-identical between base and candidate.ET_DYNwith segments from 0, candidateET_EXECwith the lowestPT_LOADat0x400000. The highest segment end is0x5fc4040(Mednafen), well below 2^40 and the guest arena at0x200000000.--linux-fixed-base 0x400000from both the candidate and base.--lazy-bindingoutput is byte-identical between base and candidate and staysET_DYN.--to-inteldefault output (6 inputs get INSERTQ or EXTRQ stubs) isET_EXECand byte-identical to base--to-intel --linux-fixed-base 0x400000.Six other ps5-payload-dev images (four
*-install.elf, ftpsrv and websrv) are refused identically on both sides at the mount wrapper from #8624.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-21T13:06:01Z.
Thanks for running that, it covers a lot more real inputs than my fixtures did. Good to see
--windows,--macosand--lazy-bindingstay byte-identical and that the largest image ends far below the arena.Imported from boykopovar/AnyPS5. Originally posted by mpratsaki on 2026-10-21T13:33:19Z.
Correction to my count above: the check covered 21 distinct ELFs, not 18. gdbsrv and klogsrv were each converted in two versions (the v0.9 release assets and the pacbrew-repo v0.41.1 daemons bundle), which I had counted once. Every result listed above holds for all 21.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:56:26Z.
Review: COMMENTED
The failure it targets is real and has a precedent (#4237 did this for Windows: titles that ship their own
libc.prxcreate an mspace over a static buffer, andsceLibcMspaceCreaterejects a buffer at or above 2^40), and the verify-output handling (linux_basewritten to the patches file,ET_EXECwithout it an error) is carefully done. Turning it on by default for every Linux conversion is a bigger step than the evidence supports yet.0x400000or0x400000000, and VLC and XPSemu need exactly0x400000. So0x400000is shown to be necessary for two homebrew titles and sufficient for none of the retail ones named. Please get one title that hits the mspace check on the default base (Monster Hunter Wilds, PPSA24191) to boot on the default output of this branch, with the log line, and cite it. Without that the PR changes the default for all Linux output on the strength of CI tests that relink synthetic executables.0x400000collides with anything the host places low (a title with a large static image, a preload, a differentvm.mmap_min_addr, a compatibility layer).--linux-fixed-basemade that the user's explicit choice; making it the default makes it every user's failure mode. State what happens when the image doesn't fit before the arena at0x200000000(a title with a very large executable), and add a test with an image that spans the range.--lazy-bindingkeeps the PIE layout, so a title that needs lazy binding does not get the fix. Say that in the usage text and have the converter warn when both conditions apply, since a user will hit the original mspace failure again with no hint.vawhile the process runs atva + linux_base;APS5_TRACE_CALLSprintsapp.elf+<absolute address>for it. The PR notes this as a separate libc change. Because the default now produces this for every Linux title, tools and logs that parse those lines will see different numbers from the same executable. A one-line note in USAGE and a follow-up issue number would help.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-21T18:33:37Z.
Thanks for going through it this carefully. I pushed
123ba7083for the second and third points. Point by point:A title on the default output. I don't have Monster Hunter Wilds, so I can't run it myself. The default output of this branch is byte-identical to
--linux-fixed-base 0x400000; that's the first thingtest_linux_fixed_basechecks. #7852 reports the title on that flag: "Relinked with--linux-fixed-base 0x400000or0x400000000, the title compiles its shaders, presents frames and checks its save data within 5 minutes." So0x400000gets the retail case past the mspace check too, not only the homebrew. I agree a run of this exact head beats an inference, though. @Lindamea1, if you have a few minutes: converting PPSA24191 with this branch and no base option should give the same result as your fixed-base runs. The log past the point where it used to stop would be enough.An image that doesn't fit before the arena. On
mainthe relinker already refuses any image that spans 2 GiB or more, PIE or not: its entry stub reaches the image with rel32 calls, and conversion fails withEntry stub call exceeds rel32 range. So the largest image it accepts ends around0x80400000at the default base, well below0x200000000.test_linux_fixed_basenow pins this. An image whose last segment is just under 2 GiB up converts, ends below the arena and runs at the base. Images reaching0x80000000or the arena start are refused the same way with and without--lazy-binding, so the default doesn't change which images convert. The debt entry says so too. If that limit is ever lifted, the arena still copes:SeedHostUsedRangesinGuestArena.cppreads/proc/self/mapsand keeps every host mapping inside the arena range out of guest allocations. That's the same path any host mapping there takes today.On the other collisions:
0x400000is also GNU ld's default text address for x86-64 non-PIE executables. A host that can't map an executable there can't run ordinary non-PIE binaries either. The kernel maps the executable beforeld.soand any preloaded libraries, and the usualvm.mmap_min_addrvalues (4096 to 65536) are far below it.--lazy-binding. The usage row already says the executable stays position independent. The converter now also warns when it does that for Linux output:Warning: with --lazy-binding the Linux executable stays position independent and is not placed at 0x400000; a title whose own sceLibcMspaceCreate checks the 40-bit address window stops at start-up. The test checks that the warning appears with the option and not without it.Trace offsets. #8974 is that follow-up. It counts the offset from the image's first loaded page, so an
ET_EXECexecutable printsapp.elf+0x...the same way a PIE does. The two PRs are independent. I left the USAGE note out because it would go stale once #8974 lands. If you'd rather this PR not depend on the merge order, I'll add it.Relinker CI on the new head passes on Ubuntu (which runs the converted executables), Windows, both macOS jobs and ASan.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T22:49:16Z.
Review: COMMENTED
Apple-side run of the test suite for this PR. No Apple result was on the thread yet: the independent check above was a Windows conversion smoke-test (byte-identical
--macos/--windows/--lazy-binding), and the author reports Linux only.Machine: Apple M2 Max, macOS 27.2.
Head:
123ba7083, merged ontomaina6dcea9279(clean merge). Relinker-only Release.-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3, Python 3.9.6): ctest 229/229. The relinker binary itself runs under Rosetta and produces the same output the suite expects.Red/green on the relinker binary (ran this PR's updated test drivers against a
maina6dcea9279relinker built without the change):test_linux_fixed_base→a relink without the option is not placed at 0x400000test_game_patches→ expectedlinux_base = 0x400000not in the dumped patch inputstest_executable_tls_relocations,test_none_relocations,test_overlapping_relocations,test_optional_rela,test_sce_relro,test_linux_eh_frame_header→ rebasing assertions fail (the base no longer defaults to0x400000, so the rebased addresses the tests check diverge).All of them pass against the PR binary on both arches. The default-
0x400000change and its rebasing are covered by the suite on Apple Silicon and under Rosetta.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T01:24:15Z.
Not a review. This is evidence from a branch I had prepared for #7972 and dropped, because this PR was there first. It made the same change, but at a different base:
0x140010000(the Windows and macOS layout), not0x400000.GamePatchTests.cpp:388asserted that--verify-outputrefuses anET_EXECoutput. OnceET_EXECoutput is verifiable the expectation has to change, as it does here. I only saw it becauserelinker_game_patchfailed on Windows once I built that test's own target: an earlier run that built only the relinker passed.--linux-position-independent(main's output) against the new default at0x140010000. The first pass differed for 13 titles that ran before and stopped after, and 9 the other way. None of it reproduced: two repeats, and three interleaved rounds on the 10 doubtful titles, gave the same result under both settings. The first-run differences came from games rewriting config files that my runs kept between them. So no title that ran at the position-independent base stopped at a fixed low base.That was
0x140010000; I did not run the catalog at0x400000.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T01:29:09Z.
Thanks, this is the catalog-wide check the review asked for, even if at the other base. 111 titles with no repeatable regression from a fixed low base is the strongest answer yet to the "every Linux title" concern. The
GamePatchTests.cpppoint matches what this PR changes there. I'll run the same catalog A/B at0x400000once I have a Linux machine with a GPU set up, and post it here.