Repository navigation
feat(relinker): place macOS executables at a fixed base with --macos-fixed-base - #6802
Conversation
|
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.
|
…a fixed base with --macos-fixed-base (@DavidSamir) Open upstream PR that adds macOS behaviour this branch did not have. The only conflict was a list both sides appended to (a debt index or the relinker test registrations), so both entries are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a fixed base with --macos-fixed-base (@DavidSamir) Open upstream PR that adds macOS behaviour this branch did not have. The only conflict was a list both sides appended to (a debt index or the relinker test registrations), so both entries are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jotitadev
left a comment
There was a problem hiding this comment.
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 e4ff92713 merged onto main 9f25d0bf5 (clean merge).
- arm64: 187/187.
- x86_64 under Rosetta with
/usr/bin/python33.9.6: 187/187, includingmacos_fixed_baseandcli_args.mainpasses 186/186 on both. - Without the option, the macOS output for the
linux_fixed_basefixture is byte-identical tomain's.
Execution under Rosetta. I converted the linux_fixed_base fixture with --macos --skip-sce-module. Its entry checks that its own address and the relocated slot both equal base + 0x10, then hits int3; on a mismatch it hits ud2. Next to it I put an x86_64 libs/libkernel.prx whose Aps5StartGuest_nid_no_patch just calls the entry, plus an empty libs/libc.prx.
| Output | Image header (dladdr) |
Entry | Result |
|---|---|---|---|
| default | 0x140000000 |
0x140010010 |
ud2 (SIGILL), as expected for a fixture built for 0x400000 |
--macos-fixed-base 0x400000 |
0x3f0000 |
0x400010 |
int3 (SIGTRAP), slot rebased correctly |
With 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, 0x100000000 and 0x7f0000000000.
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 bases 0x7ff700000000, 0x7ff740000000, 0x7ff780000000, 0x7ff7b0000000, 0x7ff7c0000000 and 0x7ff7e0000000. 0x7ff6f0000000 and lower start 20 out of 20. A bisection put the edge near 0x7ff6ff800000, and it moved slightly between runs. The x86_64 shared cache maps from 0x7ff8... and the Rosetta runtime sits just below it at 0x7ff7ffxxx000. None of the titles in the description need such a base. Still, a lower bound in the check, or a note in USAGE.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.
WriteMacOsImage wrote the Windows ImageBase constant into the Mach-O segment and section addresses, __PAGEZERO, the metadata load bias, the TLS descriptors and the init pointer, while the relocations it rebases were computed from the WindowsLoadImage base. Read the base from the load image everywhere instead. Every caller still builds its image at ImageBase, so the output is unchanged.
…fixed-base Ruffle (PPSA68091), VLC (PPSA85300) and XPSemu (PPSA97358) read app0/imports.txt, whose import slot addresses assume the executable's lowest ELF load page at 0x400000, and dereference them at once. macOS output always placed that page at 0x140010000, so all three fault on their first slot read. Linux and Windows have --linux-fixed-base and --windows-fixed-base for this; macOS had no equivalent. --macos-fixed-base <address> builds the load image so that the lowest ELF load page is at the address, as --windows-fixed-base does. The Mach-O header takes the 64 KiB below it and __PAGEZERO ends there. The executable is MH_EXECUTE without MH_PIE, so dyld does not slide it. The address must be 64 KiB aligned, from 0x20000 through 0x7fffffff0000, and an image ending past the macOS user address space is refused.
macos_fixed_base relinks the fixed-base fixture with and without --macos-fixed-base 0x400000 and checks that every segment and section moves by the same amount, __PAGEZERO ends 64 KiB below the base, the lowest load page is at the base, the entry offset is unchanged, and the metadata load bias and the relocated slot hold base-relative addresses. It also checks the lowest base and the refused options and images. cli_args covers the parsing, range, repetition and --macos requirement.
e4ff927 to
a29f7d0
Compare
|
Re-checked against current |
Brings in main's 49 newer commits. Seven of the PRs this branch carried are now in main (boykopovar#6647, boykopovar#6667, boykopovar#6668, boykopovar#6685, boykopovar#6686, boykopovar#6767, boykopovar#6802), so the branch shrinks by them. Conflicts: - GuestGetrlimit: main adds a check that 1024 stdio streams open on Windows; it runs after this branch's descriptor exhaustion helper, which Windows and macOS share. - the relinker keeps this branch's macOS fixture test beside main's macOS fixed-base test from boykopovar#6802. - the libkernel and shader debt files take main's text and keep this branch's short macOS entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a fixed base with --macos-fixed-base (@DavidSamir) Open upstream PR that adds macOS behaviour this branch did not have. The only conflict was a list both sides appended to (a debt index or the relinker test registrations), so both entries are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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:maince991f1 with 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)