feat(relinker): place macOS executables at a fixed base with --macos-fixed-base #6802
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6802"
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 DavidSamir on 2026-10-16T12:33:22Z.
What
Ruffle (PPSA68091), VLC (PPSA85300) and XPSemu (PPSA97358) read
app0/imports.txt, a list of import slot addresses relative to an executable whose lowest load page is at0x400000, and read each slot straight away.USAGE.mdalready names the three for--linux-fixed-base, and Windows has--windows-fixed-base. macOS output always places that page at0x140010000, and no option changes it, so all three crash on their first slot read. A Mach exception port in VLC shows the fault atcmpq $0x0, 0x400000(%rax)withrax = 0x362b2c8, the first address in itsimports.txt.--macos-fixed-base <address>maps the lowest ELF load page of the macOS executable at the address, as--windows-fixed-basedoes:address - 0x10000. The Mach-O header takes those 64 KiB and__PAGEZEROends there.MH_EXECUTEwithoutMH_PIE, so dyld doesn't slide it.0x20000through0x7fffffff0000. An image ending past the macOS user address space is refused.--executable, as--linux-fixed-basedoes. Bundled modules keep their placement.WriteMacOsImagewrote the WindowsImageBaseconstant into these places, while the relocations it rebases came from the load image's base:__PAGEZERO;The first commit reads the base from the load image everywhere. Without the option the output is byte-identical to
main's.Commits:
USAGE.md.Tested
macOS 26.7.1, Apple M2, AppleClang 21.0.0, Release. The relinker runs natively, and the titles run as x86-64 under Rosetta.
maindoesn't build the system libraries on macOS by itself, so the titles ran against the libraries of a local tree:maince991f1ecwith the macOS runtime work merged (#4627, #4630, #6124, the macOS relinker PRs, mugurc's port branches).Relinker tests: all 174 pass. The
macos,cli_args,linux_fixed_baseandwindowstests also pass at each commit.macos_fixed_baserelinks thelinux_fixed_basefixture with and without--macos-fixed-base 0x400000, and checks:__PAGEZEROends 64 KiB below the base, and the entry offset is unchanged;0x20000is accepted, and an unaligned, low, missing or repeated address and an image past user space are refused.Wrong versions: the test fails for each of 7 deliberately wrong versions:
__PAGEZEROor the section addresses keep the default base;--macos.cli_argscovers parsing, the range, repetition and the--macosrequirement.Default output: without the option, Ruffle (42,851,864 bytes) and OpenRCT2 Native Port (PPSA99728, 1.0.0, 23,259,368 bytes) relink byte-identical to
main's relinker.Titles, catalog sha256 checked, relinked with
--macos --to-rosetta:--macos-fixed-base 0x4000000 of 486 imports unresolved, then stops atgfx: no GPU, 2 runs of 2setrlimit: changing the limit of resource 8 is not supported(libkernel), 2 runs of 2OpenRCT2 Native Port still runs at 30 s without the option.
tools/check_conventions.py --base origin/mainandgit diff --checkpass.Not tested: Linux and Windows. Their output paths are unchanged. The Linux option's parser now shares its body with the macOS one, and
linux_fixed_baseandcli_argspass here.Not tested past the title's own renderer. VLC's own log reports
gfx: no GPUright after it resolves its imports. That comes from VLC's renderer, not from an AnyPS5 error, and I haven't found its cause, so VLC is not tested past that point. Wind Waker HD (PPSA99641), whose renderer printsRADV reports no PS5 GPU, suggests such renderers look for a PS5 GPU from inside the title, which AnyPS5 doesn't provide on any platform. That is unconfirmed for VLC. XPSemu's next stop, thesetrlimitrefusal, is in libkernel, is the same on every platform, and is not changed here.Overlap:
ParseLinuxFixedBaseinCliArgs.cpp, plus the option structs inCli.hpp,Conversion.hppandmain.cpp. It also adds--linux-fixed-baseto the options--verify-patchesrejects, and--macos-fixed-basebelongs in that list too.MacOsImage.cpp, but none of their hunks changes the lines this branch changes.core/relinker/CMakeLists.txt.tools/pr_overlap.pystopped on a pull request ref it couldn't fetch, so this list comes from the files of the 773 open pull requests. Whichever lands second rebases.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-16T12:41:50Z.
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/CMakeLists.txtcore/relinker/CMakeLists.txtdocs/user/USAGE.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/cli/src/CliArgs.cppcore/relinker/relinker/src/pipeline/Conversion.cppdocs/user/USAGE.mdcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtdocs/user/USAGE.mddocs/user/USAGE.mdImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T11:28:33Z.
Review: COMMENTED
Ran this on macOS, including the converted executable under Rosetta. The Mach-O loader and Rosetta are what the option targets, and the test checks the layout without running the output.
Machine: Apple M2 Max, macOS 27.2 (26B5091g), Xcode 27 clang, relinker-only Release builds. Head
e4ff92713merged ontomain9f25d0bf5(clean merge)./usr/bin/python33.9.6: 187/187, includingmacos_fixed_baseandcli_args.mainpasses 186/186 on both.linux_fixed_basefixture is byte-identical tomain's.Execution under Rosetta. I converted the
linux_fixed_basefixture with--macos --skip-sce-module. Its entry checks that its own address and the relocated slot both equalbase + 0x10, then hitsint3; on a mismatch it hitsud2. Next to it I put an x86_64libs/libkernel.prxwhoseAps5StartGuest_nid_no_patchjust calls the entry, plus an emptylibs/libc.prx.dladdr)0x1400000000x140010010ud2(SIGILL), as expected for a fixture built for0x400000--macos-fixed-base 0x4000000x3f00000x400010int3(SIGTRAP), slot rebased correctlyWith the fixture's code rebuilt for each base, the following load at the requested address and reach
int3:0x20000(the lowest accepted base, with a 64 KiB__PAGEZERO),0x30000,0x100000,0x10000000,0x100000000and0x7f0000000000.High bases that pass the new check but don't start. The new check refuses images that end past
0x7fffffe00000. Under Rosetta here, the kernel kills the process with SIGKILL before dyld runs, 20 out of 20 runs, for bases0x7ff700000000,0x7ff740000000,0x7ff780000000,0x7ff7b0000000,0x7ff7c0000000and0x7ff7e0000000.0x7ff6f0000000and lower start 20 out of 20. A bisection put the edge near0x7ff6ff800000, and it moved slightly between runs. The x86_64 shared cache maps from0x7ff8...and the Rosetta runtime sits just below it at0x7ff7ffxxx000. None of the titles in the description need such a base. Still, a lower bound in the check, or a note inUSAGE.md, would turn a silent SIGKILL into an error at conversion time.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T10:55:56Z.
Re-checked against current
main: the head is the earlier rebase plus the--verify-patchesrejection of--macos-fixed-base(with its test) and the USAGE.md entry; no logic changes since the last review. Layout, range, alignment and the--macosrequirement are covered bymacos_fixed_baseandcli_args, confirmed on macOS/Rosetta by @jotitadev; relinker CI is green. Merged.