fix(relinker): load macOS executables at 0x400000 by default #24967
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24967"
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 Jazeupoi on 2026-11-21T13:46:38Z.
What
macOS output placed the executable at a fixed address only with
--macos-fixed-base; without it the first load page landed at0x140010000. Linux (#8973) and Windows (#9332) already default to0x400000, where Ruffle, VLC and XPSemu expect their image when they read theirapp0/imports.txt(#4013). macOS now defaults to0x400000too;--macos-fixed-basestill selects another address.With the image that low, dyld, malloc and Rosetta placed their memory below 4 GB, and DOOM Native Port (PPSA99666) crashed in 8 of 15 launches. The executable now reserves the range from the end of the image up to
__LINKEDIT, which ends at 4 GiB (0x100000000), with no access (__APS5LOW), so that memory lands above it, as it did when the image itself started at0x140010000. dyld keeps the export trie's offset from__TEXTin auint32_t, so the export trie is written first in__LINKEDIT, which starts at the end of the reserve, and the relinker refuses an output whose trie would end more than 4 GiB past__TEXT. The tests that assumed the old base and USAGE.md are updated, andmacos_outputchecks that offset.Tested
macOS 27, Apple M4, ending
__LINKEDITat 4 GiB (zedekvdb's suggestion), headeb2759b627:macos_fixed_baseis refused at--macos-fixed-base 0x20000and fails the layout check on the previous head7d71880e04.macOS 27, Apple M4, with the reserve ending at 4 GiB, merged onto main
28f493e6d1:macos_outputfails on the previous head ("the export trie ends 0x13fc10058 past __TEXT"), the offset macOS 26's dyld truncated (reported below).macOS 27, Apple M4, with the earlier reserve up to
0x140000000, on maine60b2f74ad:main(25 s each, relinked with this change): all 94 still run and none crashes. The 4 that drew fewer frames than in an earlier sweep (Playden, Mediathek, EVO Player, Arcade Gallery) draw the same number with and without this change.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)Summary by CodeRabbit
0x400000; the fixed-base option can select a different address.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T14:06:40Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected macOS base selection and low-address reservation match the stated goal; I found no verified blocking defect in the code read.
What I ran
Head:
aad00f7deef4814b13eca33c6afca8af23e2a964. I inspected the prepared diff and the changed image-writing function throughrepo_read.py; I ran no tests or build commands.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
The remaining changed files were not read in full, including CLI help, conversion wiring, tests, and usage documentation. No tests, builds, or macOS runtime behavior were independently verified. The manifest lists 12 changed files, all included in the prepared bundle; I read only the diff and the relevant range of
MacOsImage.cpp.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T08:31:55Z.
Review: APPROVED
Reviewed — looks good
The change at head
7d71880e04119e23061e49d580c969b45d2391f5was reviewed; no verified defect blocks merging, and the relinker tests and console behavior were not independently run.What I ran
No build or tests were run. I read the prepared description, commits, manifest, diff, and all 12 changed files at the pinned head using
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build, relinker tests, and macOS console behavior were not run. The claims in the PR description about test totals, dyld behavior, and DOOM launch results remain author-reported. No files were excluded from review; all 12 changed files listed in the manifest were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T04:23:28Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review covered all changed files at the stated head, but tests were not run here.
What I ran
Reviewed head
eb2759b6276813260b2d990f92bcf8581bcdf81d. Read the prepared description, commits, manifest, diff, and full text of all 11 changed files throughrepo_read.py. No tests or build commands were run; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the test suite or validate the reported macOS 27 behavior on Apple M4 hardware. No files were excluded from review; the manifest lists all 11 changed files as included.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Quimera996 on 2026-11-26T17:52:33Z.
Review: COMMENTED
Tested on a second Mac. No title was run: I have none.
Setup: Apple M5, macOS 27.2.1, Apple clang 21.0.0 (Xcode 27.2), Python 3.12.15. Relinker-only Release builds (arm64) of
main9f52918eb0and of headeb2759b627merged onto it, which is a clean merge.mainmainThe six are
macos_output,macos_fixed_base,macos_executable_exports,executable_tls_relocations,ignored_string_segmentsandfunction_symbol_roots_executable. They fail on the old base, for example withthe lowest ELF load page is at 0x140010000, not at the default 0x400000andthe default base reserves no low address range. So the updated tests do check the change.Where host memory lands. I converted the fixture of
test_macos_executable_exports.pyand ran it under Rosetta 2 with a stublibkernel.prxthat allocates, prints and waits. I read the process withvmmapand, from inside it, withmach_vm_region. Three runs of each output, all the same:main, default__PAGEZEROup to0x140000000, image from there0x1481bb560main,--macos-fixed-base 0x4000000x3f0000-0x4030000x403000OS Alloc Once, 13Malloc Metadataand 12Malloc Guard Pageregions, 6 mapped files, shared memory and the segments of two more images0x4075600x3f0000-0x402000,__APS5LOW0x402000-0xfffff000with no access,__LINKEDIT0xfffff000-0x100000000__TEXT,__ELF0,__APS5DATA,__LINKEDIT0x1081a8560--macos-fixed-base 0x4000000x1081a8560With this PR,
mach_vm_regionat0x402000returns one region up to0xfffff000with protection 0 and maximum protection 0.vmmapdoes not list it, as it does not list__PAGEZERO. Themallocblocks (64 bytes and 64 MiB) and the stack are above 4 GiB in every case.So here too a low image without the reserve gets dyld's and malloc's memory right behind it, and the reserve keeps everything but the executable above 4 GiB, as the image at
0x140000000did.Converted output that runs here. Among the 1014, these launch converted x86-64 output under Rosetta 2 on this machine and pass with this PR:
macos_executable_exports(native x86_64 imports and dlsym passed, so dyld of macOS 27.2.1 reads the export trie of an image whose__LINKEDITends at 4 GiB),macos_code_signature(first launch anddlopenof a signed guest module),macos_guest_gs,macos_guest_weak_importsandmacos_guest_weak_exports.Not run: a title, macOS 26, an Intel Mac.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T08:34:18Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed code and documentation support the stated macOS default base and low address reserve; I found no verified blocking defect.
What I ran
Reviewed head
a31b05d744498203398b015cb196aa7a70c1dd03from the prepared diff and file snapshots. I did not run commands or tests. The pinned reader served one source range; a later read could not complete because it could not write its read log.Results
Negative control
Not run; no tests were run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the prepared diff and included head snapshots for
core/relinker/cli/src/CliArgs.cpp,core/relinker/elfpatcher/include/elfpatcher/macos/MacOsMachOPatcher.hpp,core/relinker/elfpatcher/src/macos/MacOsImage.cpp,core/relinker/relinker/src/pipeline/Conversion.cpp, six relinker test files, anddocs/user/USAGE.md.files.jsonlists no excluded files.Not verified
I did not run the relinker test suite or verify macOS runtime behavior. The author-reported test and console results were not independently checked. The reader could not provide further repository context after its read-log write failed.
To get this to a good state
Nothing is required. Optional: run the relinker tests and verify the resulting image on macOS, including the low fixed-base case.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T09:50:39Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
cc05dd72a41689710fc7b93e10fc27725de92ae3against basemain. I inspected the prepared description, commits, diff, manifest, and all 12 changed files listed underreviewedusingrepo_read.pyfor pinned source context. No tests or runtime checks were run; no build or compiler was invoked.Results
Negative control
Not run; no tests were executed.
Findings
Blocking
None.
Non-blocking
Sources
Not verified
I did not run the test suite or verify macOS runtime behavior, including the author-reported macOS 27 and title-launch results. All 12 files listed as reviewed were inspected;
files.jsonlists no excluded files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T09:55:26Z.
Review: COMMENTED
Actionable comments
447cef15-3905-4189-84fd-3874fb93b1cdReviewing files that changed from the base of the PR and between
a31b05d744andcc05dd72a4.core/relinker/relinker/src/pipeline/Conversion.cppcore/relinker/relinker/tests/test_macos_output.pydocs/user/USAGE.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T10:11:03Z.
Review: APPROVED
Reviewed — looks good
The change defaults macOS output to a 0x400000 lowest load page and reserves low address space while keeping the export trie within dyld’s 32-bit runtime offset.
What I ran
Reviewed head
b44cc518b049c1343bfa9c7d50671bcfdf28368fusing the prepared diff andrepo_read.pyat the pinned head. No tests or builds were run. The author reports macOS test and title runs in the PR description; I did not independently verify them.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior on macOS, including dyld, malloc, Rosetta, and console title behavior, was not independently verified. No tests or builds were run.
To get this to a good state
Nothing is required.