[PR #1392] x64_recomp: handle 0x67 address-size override in memory and moffs operands (X64-RECOMP-ADDRSIZE-67) #1421

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

📋 Pull Request Information

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

Base: main ← Head: fix/x64-recomp-addrsize-67


📝 Commits (1)

  • 442ef0a x64_recomp: handle 0x67 address-size override in memory and moffs operands

📊 Changes

2 files changed (+284 additions, -27 deletions)

View changed files

➕ tests/test_x64_recomp_addrsize67.py (+253 -0)
📝 tools/x64_recomp.py (+31 -27)

📄 Description

Item ID: X64-RECOMP-ADDRSIZE-67

Summary

Fixes handling of the 0x67 address-size override prefix (32-bit effective addressing in 64-bit mode) in tools/x64_recomp.py:

  • moffs (A0..A3, token Q) in _finish: reads a 4-byte unsigned moffs32 when ins.addrsize is set instead of always reading 8 bytes (which previously consumed subsequent instruction bytes or raised DecodeError("truncated imm")).
  • Memory operand metadata & EIP-relative addressing in _finish and _finish_group: tags memory operands with addrsize = 4 when ins.addrsize is set, and truncates RIP-relative effective addresses to 32 bits ((ins.addr + ins.size + disp) & 0xFFFFFFFF) per Intel SDM Vol. 2A §2.2.1.6.
  • 32-bit effective address codegen in _mem_addr: emits sf=0 (W-register) ARM64 arithmetic/moves/shifts (MOV, ADD, SUB, ADD (shifted reg), LSL) and masks immediate/absolute/disp32-only addresses to 32 bits when m.get("addrsize") == 4, wrapping modulo 2^32 and zero-extending to 64 bits (including disp == 0 with base == rd, [disp32] zero-extension vs 64-bit sign-extension, and large displacements >= 4096 / <= -4096).

Tests & Verification

  • AI-assisted: yes
  • Host / hardware: macOS (Apple M5, arm64)
  • Standalone checks on this branch (upstream/main 28a32e190):
    • python3 -m compileall -q make_game.py tools tests — OK
    • python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_addrsize67.py — OK
    • python3 -I tests/test_x64_recomp_addrsize67.py -v — 3 static decode/codegen tests OK (3 exec tests skip cleanly without #1174 runner)
    • python3 -I tests/test_x64_recomp.py — 6 static OK (26 exec skipped)
    • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • Live Apple M5 mutation proof (tests/test_x64_recomp_addrsize67.py on unpatched upstream/main + #1174): 19 failures (FAILED (failures=19)).
  • Native Apple M5 execution (20-way scratch merge with #1174 + all 18 other open x64_recomp PR branches):
    • 0 merge conflicts across all 20 branches
    • tests/test_x64_recomp_addrsize67.py: 6/6 OK (0 skipped) on native Apple M5 arm64
    • All 19 tests/test_x64_recomp_*.py suites combined: 138/138 OK (0 skipped)

🔄 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/1392 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/x64-recomp-addrsize-67` --- ### 📝 Commits (1) - [`442ef0a`](https://github.com/ubiquitarianism/leonida/commit/442ef0a6637b80dfc446f3e223fb1c89e8f11815) x64_recomp: handle 0x67 address-size override in memory and moffs operands ### 📊 Changes **2 files changed** (+284 additions, -27 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_x64_recomp_addrsize67.py` (+253 -0) 📝 `tools/x64_recomp.py` (+31 -27) </details> ### 📄 Description Item ID: `X64-RECOMP-ADDRSIZE-67` ## Summary Fixes handling of the `0x67` address-size override prefix (32-bit effective addressing in 64-bit mode) in `tools/x64_recomp.py`: - **`moffs` (`A0`..`A3`, token `Q`) in `_finish`**: reads a 4-byte unsigned `moffs32` when `ins.addrsize` is set instead of always reading 8 bytes (which previously consumed subsequent instruction bytes or raised `DecodeError("truncated imm")`). - **Memory operand metadata & EIP-relative addressing in `_finish` and `_finish_group`**: tags memory operands with `addrsize = 4` when `ins.addrsize` is set, and truncates RIP-relative effective addresses to 32 bits (`(ins.addr + ins.size + disp) & 0xFFFFFFFF`) per Intel SDM Vol. 2A §2.2.1.6. - **32-bit effective address codegen in `_mem_addr`**: emits `sf=0` (`W`-register) ARM64 arithmetic/moves/shifts (`MOV`, `ADD`, `SUB`, `ADD (shifted reg)`, `LSL`) and masks immediate/absolute/disp32-only addresses to 32 bits when `m.get("addrsize") == 4`, wrapping modulo `2^32` and zero-extending to 64 bits (including `disp == 0` with `base == rd`, `[disp32]` zero-extension vs 64-bit sign-extension, and large displacements `>= 4096` / `<= -4096`). ## Tests & Verification - **AI-assisted**: yes - **Host / hardware**: macOS (Apple M5, arm64) - Standalone checks on this branch (`upstream/main` `28a32e190`): - `python3 -m compileall -q make_game.py tools tests` — OK - `python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp_addrsize67.py` — OK - `python3 -I tests/test_x64_recomp_addrsize67.py -v` — 3 static decode/codegen tests OK (3 exec tests skip cleanly without `#1174` runner) - `python3 -I tests/test_x64_recomp.py` — 6 static OK (26 exec skipped) - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - **Live Apple M5 mutation proof** (`tests/test_x64_recomp_addrsize67.py` on unpatched `upstream/main` + `#1174`): **19 failures** (`FAILED (failures=19)`). - **Native Apple M5 execution (20-way scratch merge with `#1174` + all 18 other open `x64_recomp` PR branches)**: - 0 merge conflicts across all 20 branches - `tests/test_x64_recomp_addrsize67.py`: **6/6 OK (0 skipped)** on native Apple M5 arm64 - All 19 `tests/test_x64_recomp_*.py` suites combined: **138/138 OK (0 skipped)** --- <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#1421
No description provided.