[PR #1174] x64_recomp: native JIT-free arm64 Mach-O userland runner for Apple Silicon (X64-RECOMP-MACHO-RUNNER) #1207

Open
opened 2026-11-26 20:20:27 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1174
Author: @IlyassRS3
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: feat/x64-recomp-darwin-macho-runner


📝 Commits (1)

  • ad64b4f x64_recomp: native JIT-free arm64 Mach-O userland runner for Apple Silicon (X64-RECOMP-MACHO-RUNNER)

📊 Changes

3 files changed (+812 additions, -57 deletions)

View changed files

📝 docs/mobile.md (+29 -6)
📝 tests/test_x64_recomp.py (+309 -25)
📝 tools/x64_recomp.py (+474 -26)

📄 Description

Claimed in the coordination issue as: X64-RECOMP-MACHO-RUNNER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142321014)

What and why

Implements Next Step #4 of docs/mobile.md: a pure-Python, JIT-free arm64 Mach-O + mmap userland runner in tools/x64_recomp.py so translated x86-64 functions run natively on Apple Silicon macOS (including the macos-26 CI runner) without qemu-system-aarch64, clang, codesign, or MAP_JIT.

  • pack_macho_arm64 wraps PIE arm64 code in a 64-bit MH_EXECUTE (MH_PIE, 4 GiB __PAGEZERO, 16 KiB-aligned __TEXT/__LINKEDIT) with a pure-Python ad-hoc SHA-256 LC_CODE_SIGNATURE (CodeDirectory v0x20400, CS_ADHOC | CS_LINKER_SIGNED, validated by codesign -vvv).
  • emit_rt(..., darwin=True) uses Asm.adr + signed 64-bit pc_table offsets so call/ret and indirect jumps work under any ASLR slide.
  • build_test_macho / run_macho / run_macho_result map guest RW memory at 0x10047000000 (MAP_PRIVATE | MAP_ANON, no MAP_FIXED, clean exit 77 on collision), zero guest GPRs and NZCV, and support map_code=True (read-only mapped guest code for RIP-relative reads).
  • tests/test_x64_recomp.py runs all 26 existing ExecTests natively on Apple Silicon plus 6 cross-platform MachOBuilderTests and 8 MachONativeTests. Verified clean against main and zero conflicts with open x64_recomp PRs (#847, #950, #1120, #1121).

Tested

  • python3 -I tests/test_x64_recomp.py -v on Apple M5 / macOS 27.2.1 (Python 3.14): 46/46 passed (5 consecutive runs, 0 failures), including codesign -vvv, RIP-relative reads, multi-page signed images, and PIE indirect dispatch across ASLR runs.
  • python3 -m compileall -q make_game.py tools tests and python3 -I make_game.py --help: clean.
  • python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md: clean.
  • tests/test_recomp_census.py, tests/test_report_paths.py, tests/test_text_write_line_endings.py, tests/test_ci_registration.py, tests/test_tool_startup.py, and all tests/test_docs_*.py: all passed.

GPUs tested: n/a (CPU x86-64 -> arm64 recompiler; tested natively on Apple M5 arm64, macOS 27.2.1)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1174 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/x64-recomp-darwin-macho-runner` --- ### 📝 Commits (1) - [`ad64b4f`](https://github.com/ubiquitarianism/leonida/commit/ad64b4f43c628db8cfda03508eba1e2bad8b029c) x64_recomp: native JIT-free arm64 Mach-O userland runner for Apple Silicon (X64-RECOMP-MACHO-RUNNER) ### 📊 Changes **3 files changed** (+812 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `docs/mobile.md` (+29 -6) 📝 `tests/test_x64_recomp.py` (+309 -25) 📝 `tools/x64_recomp.py` (+474 -26) </details> ### 📄 Description Claimed in the coordination issue as: X64-RECOMP-MACHO-RUNNER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142321014) ### What and why Implements Next Step #4 of `docs/mobile.md`: a pure-Python, JIT-free arm64 Mach-O + `mmap` userland runner in `tools/x64_recomp.py` so translated x86-64 functions run natively on Apple Silicon macOS (including the `macos-26` CI runner) without `qemu-system-aarch64`, `clang`, `codesign`, or `MAP_JIT`. - `pack_macho_arm64` wraps PIE arm64 code in a 64-bit `MH_EXECUTE` (`MH_PIE`, 4 GiB `__PAGEZERO`, 16 KiB-aligned `__TEXT`/`__LINKEDIT`) with a pure-Python ad-hoc SHA-256 `LC_CODE_SIGNATURE` (`CodeDirectory` v`0x20400`, `CS_ADHOC | CS_LINKER_SIGNED`, validated by `codesign -vvv`). - `emit_rt(..., darwin=True)` uses `Asm.adr` + signed 64-bit `pc_table` offsets so `call`/`ret` and indirect jumps work under any ASLR slide. - `build_test_macho` / `run_macho` / `run_macho_result` map guest RW memory at `0x10047000000` (`MAP_PRIVATE | MAP_ANON`, no `MAP_FIXED`, clean exit 77 on collision), zero guest GPRs and `NZCV`, and support `map_code=True` (read-only mapped guest code for RIP-relative reads). - `tests/test_x64_recomp.py` runs all 26 existing `ExecTests` natively on Apple Silicon plus 6 cross-platform `MachOBuilderTests` and 8 `MachONativeTests`. Verified clean against `main` and zero conflicts with open `x64_recomp` PRs (#847, #950, #1120, #1121). ### Tested - `python3 -I tests/test_x64_recomp.py -v` on Apple M5 / macOS 27.2.1 (Python 3.14): 46/46 passed (5 consecutive runs, 0 failures), including `codesign -vvv`, RIP-relative reads, multi-page signed images, and PIE indirect dispatch across ASLR runs. - `python3 -m compileall -q make_game.py tools tests` and `python3 -I make_game.py --help`: clean. - `python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md`: clean. - `tests/test_recomp_census.py`, `tests/test_report_paths.py`, `tests/test_text_write_line_endings.py`, `tests/test_ci_registration.py`, `tests/test_tool_startup.py`, and all `tests/test_docs_*.py`: all passed. GPUs tested: n/a (CPU x86-64 -> arm64 recompiler; tested natively on Apple M5 arm64, macOS 27.2.1) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1207
No description provided.