fix(relinker): trap guest GS accesses in macOS output instead of refusing the module #6458

Merged
DavidSamir merged 5 commits from upstream-pr/6458 into main 2026-10-19 00:56:45 +00:00
DavidSamir commented 2026-10-15 16:18:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-15T16:18:36Z.


What

Prospero Win (PPSA99995, the catalog's Wine port) cannot be converted for macOS. As jotitadev measured on an M2 Max in #6102, the macOS writer refuses its Wine ntdll the way the Windows writer did:

FAIL: Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00) (offset 0x3214c)

ntdll has six instructions that address memory through GS (mov %gs:0x378,%rcx ×3, mov %gs:0x30,%r13 ×2, mov %gs:0x330,%r10). On x86-64 macOS, under Rosetta too, the host owns GS: it holds the pthread TSD base, which the writer's own TLS stubs read (65 48 8b 04 c5 in the stubs). So the scan in MacOsImage.cpp cannot translate a GS access the way it rewrites FS accesses, and it refuses the whole module.

This is the macOS half of #6102, as a follow-up PR: the scan now records each GS-prefixed instruction, and the writer overwrites it in place with ud2 and NOP padding of its own length before the sections become segments. The module converts, and an instruction that is reached faults. Only a GS-prefixed decoding at an instruction start is trapped: one that starts inside an earlier collected instruction is skipped first, as #6410 does (and as the Windows rewriter does), so bytes inside another instruction, such as OpenSSL's CRYPTOGAMS by <[email protected]> string in 24 catalog titles, are never overwritten. A GS instruction that is also an AMD-only trampoline site is refused, as a TLS access there already is. FS accesses are unchanged. The change is independent of #6102.

This branch is stacked on #6410, so its first three commits are #6410's; this PR adds four:

  1. fix(relinker): trap guest GS accesses in macOS output instead of refusing the module. The macos_tls_overlap test from #6410 checked that a GS access at an instruction start is refused; it now checks that it is trapped.
  2. test(relinker): cover GS loads, stores and ALU reads trapped in macOS output: a new macos_gs_traps test converts the two loads Wine's ntdll uses, a store, an ALU read and a 4-byte register-address form with --macos, and checks that each becomes ud2 and NOPs before the next instruction, with none of the original bytes left.
  3. test(relinker): trap a GS access in a macOS module without a TLS segment: the writer sets up guest TLS only for a module with a non-empty PT_TLS; a GS access in a module without one must still be trapped.
  4. docs(debt): record that guest GS accesses trap in macOS output.

Tested

Windows host (ee644bde66 on #6410 on main 0afa6a607e, Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release). The relinker writes macOS output on any host:

  • tools/check_conventions.py --base origin/main: passed. tools/pr_overlap.py: no overlap with open pull requests.
  • With a relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), the relinker builds at each of the four commits (on #6410) and every test that runs passes. The 27 that fail are the same at every commit and come from that build: 25 test programs it does not compile, windows_diagnostic_fixture_isolation, which copies one of them, and check_main_sync, which reads git's UTF-8 output as cp1252 on this host (sp ace é.txt) and fails the same way on main. The change is in MacOsImage.cpp, which only the relinker links, so the relinker-only build runs every test that can see it.
  • macos_gs_traps fails without the fix: with #6410's relinker, gs-load-rcx stops with Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00).
  • Linux (WSL2 Ubuntu 24.04, GCC 13.3.0): the relinker builds and the macos|tls tests pass (guest_force_tls_destructor is not run because only the relinker target was built).
  • macOS conversion of every catalog title (79), #6410's relinker against this branch's, same arguments: 78 outputs are byte-identical, and Prospero Win (PPSA99995) now converts. In its converted ntdll.prx, none of the six GS instructions is left (65 48 8b 0c 25 78 03 00 00 ×3, 65 4c 8b 2c 25 30 00 00 00 ×2, 65 4c 8b 14 25 30 03 00 00 ×1 in the input), and ud2 followed by seven NOPs occurs exactly six times. With #6410, #6419 and #6448, every one of the 79 catalog titles then converts for macOS.

Not run on macOS: I have no Mac, so neither that a converted module loads there nor that a trap is reported there is checked.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #6410 (follow-up to #6102, which does the same for Windows output)
  • Unblocks: PPSA99995 (Prospero Win) conversion for macOS
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4876374963 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6458). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-15T16:18:36Z. --- ### What Prospero Win (PPSA99995, the catalog's Wine port) cannot be converted for macOS. As jotitadev measured on an M2 Max in #6102, the macOS writer refuses its Wine `ntdll` the way the Windows writer did: ``` FAIL: Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00) (offset 0x3214c) ``` `ntdll` has six instructions that address memory through GS (`mov %gs:0x378,%rcx` ×3, `mov %gs:0x30,%r13` ×2, `mov %gs:0x330,%r10`). On x86-64 macOS, under Rosetta too, the host owns GS: it holds the pthread TSD base, which the writer's own TLS stubs read (`65 48 8b 04 c5` in the stubs). So the scan in [`MacOsImage.cpp`](https://github.com/boykopovar/AnyPS5/blob/0afa6a607e/core/relinker/elfpatcher/src/macos/MacOsImage.cpp) cannot translate a GS access the way it rewrites FS accesses, and it refuses the whole module. This is the macOS half of #6102, as a follow-up PR: the scan now records each GS-prefixed instruction, and the writer overwrites it in place with `ud2` and NOP padding of its own length before the sections become segments. The module converts, and an instruction that is reached faults. Only a GS-prefixed decoding at an instruction start is trapped: one that starts inside an earlier collected instruction is skipped first, as #6410 does (and as the Windows rewriter does), so bytes inside another instruction, such as OpenSSL's `CRYPTOGAMS by <[email protected]>` string in 24 catalog titles, are never overwritten. A GS instruction that is also an AMD-only trampoline site is refused, as a TLS access there already is. FS accesses are unchanged. The change is independent of #6102. This branch is stacked on #6410, so its first three commits are #6410's; this PR adds four: 1. `fix(relinker): trap guest GS accesses in macOS output instead of refusing the module`. The `macos_tls_overlap` test from #6410 checked that a GS access at an instruction start is refused; it now checks that it is trapped. 2. `test(relinker): cover GS loads, stores and ALU reads trapped in macOS output`: a new `macos_gs_traps` test converts the two loads Wine's `ntdll` uses, a store, an ALU read and a 4-byte register-address form with `--macos`, and checks that each becomes `ud2` and NOPs before the next instruction, with none of the original bytes left. 3. `test(relinker): trap a GS access in a macOS module without a TLS segment`: the writer sets up guest TLS only for a module with a non-empty `PT_TLS`; a GS access in a module without one must still be trapped. 4. `docs(debt): record that guest GS accesses trap in macOS output`. ### Tested Windows host (ee644bde66 on #6410 on `main` 0afa6a607e, Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release). The relinker writes macOS output on any host: - `tools/check_conventions.py --base origin/main`: passed. `tools/pr_overlap.py`: no overlap with open pull requests. - With a relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`), the relinker builds at each of the four commits (on #6410) and every test that runs passes. The 27 that fail are the same at every commit and come from that build: 25 test programs it does not compile, `windows_diagnostic_fixture_isolation`, which copies one of them, and `check_main_sync`, which reads git's UTF-8 output as cp1252 on this host (`sp ace é.txt`) and fails the same way on `main`. The change is in `MacOsImage.cpp`, which only the relinker links, so the relinker-only build runs every test that can see it. - `macos_gs_traps` fails without the fix: with #6410's relinker, `gs-load-rcx` stops with `Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00)`. - Linux (WSL2 Ubuntu 24.04, GCC 13.3.0): the relinker builds and the `macos|tls` tests pass (`guest_force_tls_destructor` is not run because only the relinker target was built). - macOS conversion of every catalog title (79), #6410's relinker against this branch's, same arguments: 78 outputs are byte-identical, and Prospero Win (PPSA99995) now converts. In its converted `ntdll.prx`, none of the six GS instructions is left (`65 48 8b 0c 25 78 03 00 00` ×3, `65 4c 8b 2c 25 30 00 00 00` ×2, `65 4c 8b 14 25 30 03 00 00` ×1 in the input), and `ud2` followed by seven NOPs occurs exactly six times. With #6410, #6419 and #6448, every one of the 79 catalog titles then converts for macOS. Not run on macOS: I have no Mac, so neither that a converted module loads there nor that a trap is reported there is checked. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #6410 (follow-up to #6102, which does the same for Windows output) - [x] Unblocks: PPSA99995 (Prospero Win) conversion for macOS - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-15 16:37:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T16:37:15Z.


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.

Pull request Shared files not compared
PR 2780 core/relinker/CMakeLists.txt
PR 5021 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 6044 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7173 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7450 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
docs/dev/debt/relinker.md
PR 7531 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7594 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6197191446 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6458#issuecomment-6197191446). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T16:37:15Z. --- <!-- pr-overlap --> 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. | Pull request | Shared files not compared | |---|---| | [PR 2780](https://www.github.com/boykopovar/AnyPS5/pull/2780) | `core/relinker/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7173](https://www.github.com/boykopovar/AnyPS5/pull/7173) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7450](https://www.github.com/boykopovar/AnyPS5/pull/7450) | `core/relinker/CMakeLists.txt`<br>`core/relinker/elfpatcher/src/macos/MacOsImage.cpp`<br>`docs/dev/debt/relinker.md` | | [PR 7531](https://www.github.com/boykopovar/AnyPS5/pull/7531) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7594](https://www.github.com/boykopovar/AnyPS5/pull/7594) | `core/relinker/CMakeLists.txt` |
jotitadev commented 2026-10-15 16:39:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T16:39:25Z.

Review: COMMENTED


Tested on Apple silicon. This is the macOS follow-up of #6102, and it builds directly on the M2 Max measurement I reported there, so I validated it on the same machine.

Machine: Apple M2 Max, macOS 27.2.
Head: ee644bde6. Merges onto current main (0029e62f9) cleanly, no conflicts (only core/relinker/CMakeLists.txt and docs/dev/debt/relinker.md auto-merge). The stack applies as expected: 3 commits from #6410 plus the 4 of this PR.
Build: relinker-only (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), both arm64 and x86_64 (-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3, Python 3.9.6).

Results:

  • arm64: 174/174 pass, including the two new tests.
  • x86_64 + Python 3.9.6: 171/174. The three failures (pr_overlap_tools, release_package, linux_fixed_base) are the known Python 3.9 incompatibilities (str.write_text(newline=) and zip(strict=) are 3.10+), unrelated to this PR.

macos_gs_traps and macos_tls_overlap run on macOS (not skipped) and pass on both architectures.

The new tests protect against the regression. Running only the two test scripts against a main relinker built without the fix, both fail with the original refusal:

  • macos_gs_traps: FAIL: Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00).
  • macos_tls_overlap: FAIL: Unsupported macOS guest TLS instruction (bytes: 65 2e 62 69 6e c3 c3 c3) — the split-function case, where main wrongly treats a GS-prefixed decoding that starts inside a movabs immediate as a real TLS access.

Real behavior, GS fixture (mov rcx, gs:[0x378], 9 bytes) converted with --macos:

  • On main: FAIL: Unsupported macOS guest TLS instruction ... (offset 0x1240), the #6102 refusal, exit 2.
  • With this PR: converts, exit 0. At the site the Mach-O holds 0f 0b 90 90 90 90 90 90 90 c3 — UD2 + seven NOP (matching the 9-byte original) + the following RET. So the module loads and runs until a GS access is actually reached, then faults, as the debt note describes.

The case the PR is careful about is covered: in test_macos_tls_overlap the movabs rcx, 0x6e69622e65000000 immediate (48 b9 00 00 00 65 2e 62 69 6e, the same shape as OpenSSL's "CRYPTOGAMS by [email protected]" literal) contains a 0x65 byte that would decode as a GS-prefixed instruction if the scan started mid-instruction. The PR skips prefixed decodings that start inside an earlier instruction, so the immediate is left intact; main refuses the whole module. Confirmed: the immediate survives the conversion with the fix and the module is refused without it.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5536655408 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6458#pullrequestreview-5536655408). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T16:39:25Z. **Review:** COMMENTED --- Tested on Apple silicon. This is the macOS follow-up of #6102, and it builds directly on the M2 Max measurement I reported there, so I validated it on the same machine. Machine: Apple M2 Max, macOS 27.2. Head: ee644bde6. Merges onto current `main` (0029e62f9) cleanly, no conflicts (only `core/relinker/CMakeLists.txt` and `docs/dev/debt/relinker.md` auto-merge). The stack applies as expected: 3 commits from #6410 plus the 4 of this PR. Build: relinker-only (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`), both arm64 and x86_64 (`-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3`, Python 3.9.6). Results: - arm64: 174/174 pass, including the two new tests. - x86_64 + Python 3.9.6: 171/174. The three failures (`pr_overlap_tools`, `release_package`, `linux_fixed_base`) are the known Python 3.9 incompatibilities (`str.write_text(newline=)` and `zip(strict=)` are 3.10+), unrelated to this PR. `macos_gs_traps` and `macos_tls_overlap` run on macOS (not skipped) and pass on both architectures. The new tests protect against the regression. Running only the two test scripts against a `main` relinker built without the fix, both fail with the original refusal: - `macos_gs_traps`: `FAIL: Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00)`. - `macos_tls_overlap`: `FAIL: Unsupported macOS guest TLS instruction (bytes: 65 2e 62 69 6e c3 c3 c3)` — the split-function case, where `main` wrongly treats a GS-prefixed decoding that starts inside a `movabs` immediate as a real TLS access. Real behavior, GS fixture (`mov rcx, gs:[0x378]`, 9 bytes) converted with `--macos`: - On `main`: `FAIL: Unsupported macOS guest TLS instruction ... (offset 0x1240)`, the #6102 refusal, exit 2. - With this PR: converts, exit 0. At the site the Mach-O holds `0f 0b 90 90 90 90 90 90 90 c3` — `UD2` + seven `NOP` (matching the 9-byte original) + the following `RET`. So the module loads and runs until a GS access is actually reached, then faults, as the debt note describes. The case the PR is careful about is covered: in `test_macos_tls_overlap` the `movabs rcx, 0x6e69622e65000000` immediate (`48 b9 00 00 00 65 2e 62 69 6e`, the same shape as OpenSSL's "CRYPTOGAMS by <[email protected]>" literal) contains a `0x65` byte that would decode as a GS-prefixed instruction if the scan started mid-instruction. The PR skips prefixed decodings that start inside an earlier instruction, so the immediate is left intact; `main` refuses the whole module. Confirmed: the immediate survives the conversion with the fix and the module is refused without it. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
DavidSamir commented 2026-10-16 04:25:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-16T04:25:39Z.


Hardware run on Apple silicon.

macOS 26.7.1, Apple M2 (8 GB), Rosetta 2, AppleClang 21.0.0. Relinkers built (-DANYPS5_RELINKER_ONLY=ON, Release) from main 5d9dcc42d alone and with this branch merged; catalog releases, sha256 checked, eboot and modules unwrapped with tools/unwrap_self.py, converted with --macos --to-rosetta. For the runs, libraries from a local tree of main ce991f1ec with #4627, #4630, #6124, #6028, #6135 and mugurc's macOS branches merged, so they build on macOS; MoltenVK from the LunarG SDK 1.4.363.

  • Prospero Win (PPSA99995), all 17 Wine modules unwrapped and converted with --trap-sdk-syscall-stubs --module-dir win/wine/lib/wine/x86_64-unix: the relinkers of main, #6410, #6419 and #6448 each fail with Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00) (offset 0x3214c); this branch converts all 17 modules.
  • Run with the game files in app0 and the converted modules over them: still running at 90 s, swapchain created (2008x1130 on the M2's display) and the mouse attached through Cocoa. The log also shows libc++abi: terminating due to uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument twice while the title keeps running; I haven't traced where that comes from yet.
  • PSXS5 (PPSA97510) also converts and runs with this branch, as it includes #6410.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208056578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6458#issuecomment-6208056578). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-16T04:25:39Z. --- Hardware run on Apple silicon. macOS 26.7.1, Apple M2 (8 GB), Rosetta 2, AppleClang 21.0.0. Relinkers built (`-DANYPS5_RELINKER_ONLY=ON`, Release) from `main` 5d9dcc42d alone and with this branch merged; catalog releases, sha256 checked, eboot and modules unwrapped with `tools/unwrap_self.py`, converted with `--macos --to-rosetta`. For the runs, libraries from a local tree of `main` ce991f1ec with #4627, #4630, #6124, #6028, #6135 and mugurc's macOS branches merged, so they build on macOS; MoltenVK from the LunarG SDK 1.4.363. - Prospero Win (PPSA99995), all 17 Wine modules unwrapped and converted with `--trap-sdk-syscall-stubs --module-dir win/wine/lib/wine/x86_64-unix`: the relinkers of `main`, #6410, #6419 and #6448 each fail with `Unsupported macOS guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00) (offset 0x3214c)`; this branch converts all 17 modules. - Run with the game files in `app0` and the converted modules over them: still running at 90 s, swapchain created (2008x1130 on the M2's display) and the mouse attached through Cocoa. The log also shows `libc++abi: terminating due to uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument` twice while the title keeps running; I haven't traced where that comes from yet. - PSXS5 (PPSA97510) also converts and runs with this branch, as it includes #6410. AI-assisted: yes
Destroyers212x commented 2026-10-18 11:09:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Destroyers212x on 2026-10-18T11:09:22Z.


Rosetta results for this PR (ee644bd), M1 with macOS 26.6.2, relinker-only Release build:

  • x86-64 build (CMAKE_OSX_ARCHITECTURES=x86_64, tests running under Rosetta): 165/165 passed, including macos_tls_overlap and macos_gs_traps.
  • Native arm64 build: 165/165 passed, including both new tests.

Both new tests only check the converted output (no execution step), so they ran in full on both builds.

One issue: ScanTls traps every instruction with a 0x65 prefix, including ones with no memory operand. A segment override only selects the segment for a memory operand (Intel SDM Vol. 2A §2.1.1, Group 2 prefixes), so these instructions never touch GS and don't need trapping. Reproduction with make_image("register", "unwind", body=instruction + b"\xc3") from test_tls_function_coverage.py, then relinker --macos --skip-sce-module (x86-64 build):

instruction main this PR
65 90 (gs nop) refused: "Unsupported macOS guest TLS instruction" 0f 0b (UD2)
65 48 89 c8 (mov rax, rcx) refused 0f 0b 90 90
65 48 b8 <imm64> (movabs rax, imm64) refused 0f 0b + 9 NOPs

Expected: these are left unchanged. I checked that they run correctly under Rosetta in an x86-64 test binary: mov and movabs give the expected values, and the nop runs. Before this PR, such a module failed at conversion. Now it converts and then faults at runtime on an instruction that would have worked. Only trapping decodings that have a memory operand (ModRM with mod != 3, or the moffs forms A0–A3) would avoid this.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249148934 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6458#issuecomment-6249148934). Originally posted by [Destroyers212x](https://github.com/Destroyers212x) on 2026-10-18T11:09:22Z. --- Rosetta results for this PR (ee644bd), M1 with macOS 26.6.2, relinker-only Release build: - x86-64 build (`CMAKE_OSX_ARCHITECTURES=x86_64`, tests running under Rosetta): 165/165 passed, including `macos_tls_overlap` and `macos_gs_traps`. - Native arm64 build: 165/165 passed, including both new tests. Both new tests only check the converted output (no execution step), so they ran in full on both builds. One issue: `ScanTls` traps every instruction with a 0x65 prefix, including ones with no memory operand. A segment override only selects the segment for a memory operand (Intel SDM Vol. 2A §2.1.1, Group 2 prefixes), so these instructions never touch GS and don't need trapping. Reproduction with `make_image("register", "unwind", body=instruction + b"\xc3")` from `test_tls_function_coverage.py`, then `relinker --macos --skip-sce-module` (x86-64 build): | instruction | main | this PR | |---|---|---| | `65 90` (gs nop) | refused: "Unsupported macOS guest TLS instruction" | `0f 0b` (UD2) | | `65 48 89 c8` (mov rax, rcx) | refused | `0f 0b 90 90` | | `65 48 b8 <imm64>` (movabs rax, imm64) | refused | `0f 0b` + 9 NOPs | Expected: these are left unchanged. I checked that they run correctly under Rosetta in an x86-64 test binary: `mov` and `movabs` give the expected values, and the `nop` runs. Before this PR, such a module failed at conversion. Now it converts and then faults at runtime on an instruction that would have worked. Only trapping decodings that have a memory operand (ModRM with mod != 3, or the moffs forms A0–A3) would avoid this. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!6458
No description provided.