fix(relinker): skip prefixed decodings inside an earlier instruction in the macOS TLS scan #6410

Merged
DavidSamir merged 3 commits from upstream-pr/6410 into main 2026-10-18 23:58:54 +00:00
DavidSamir commented 2026-10-15 14:15:15 +00:00 (Migrated from github.com)

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


What

27 catalog titles cannot be converted for macOS on main, among them SuperTuxKart (PPSA69421), PSXS5 (PPSA97510), SwanStationPS5 (PPSA98510), ProsperoStore (PPSA99000), ProsperoRadio (PPSA99001), ProsperoTV (PPSA99003), SymphonyStation5 (PPSA17641) and OpenNOW (PPSA99082). Each fails on the same two bytes:

FAIL: Unsupported macOS guest TLS instruction (bytes: 65 6e) (offset 0xbabf4d)

They are not code. The titles link OpenSSL, whose assembly keeps CRYPTOGAMS by <[email protected]> in the code segment; at PSXS5's offset 0xbabf4d the bytes are the en of openssl (... 6f 70 | 65 6e 73 73 6c ...). A function range that begins inside an instruction makes the code analysis collect a second decoding from the middle of it, and here that decoding starts with a GS prefix. The Windows TLS rewriter skips a non-FS segment-prefixed decoding inside an earlier collected instruction (90dcd6256, "tolerate unwind ranges that split an instruction"), so the same titles convert for Windows. The macOS scan in MacOsImage.cpp has no such check and refuses the module.

The macOS scan now tracks the end of the decodings it has seen, as the Windows rewriter does, and skips a segment-prefixed decoding that starts inside an earlier one unless the prefix is FS. A GS access at an instruction start is still refused.

With this PR 25 of the 27 convert. The other two get past this refusal and stop on unrelated ones, each with its own PR: Mortalfin (PPSA99141) on Guest TLS access without a non-empty PT_TLS (#6448) and PS5MC (PPSA99420) on the stack-protector check sub %fs:0x28,%rax (#6419).

Three commits:

  1. fix(relinker): skip prefixed decodings inside an earlier instruction in the macOS TLS scan.
  2. test(relinker): convert a function that begins inside an instruction for macOS: a new macos_tls_overlap test converts the Windows coverage group's function-begins-inside-instruction fixture with --macos. A symbol starts inside a movabs whose immediate holds a GS-prefixed decoding (65 2e 62 69 6e). It converts, and the movabs is unchanged in the output.
  3. test(relinker): keep refusing a GS access at an instruction start for macOS.

There is no fourth step to split out.

Tested

Windows host (be5dfd6237 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.

  • Each of the three commits builds, and the relinker tests pass at each (macos|tls_function_coverage|tls_diagnostics|guest_tls|empty_tls, 35/36/36 tests; run on main d92a8dad39 before rebasing onto 0afa6a607e, which changes nothing under core/relinker).

  • macos_tls_overlap fails without the fix: with MacOsImage.cpp as on main, function-begins-inside-instruction stops with Unsupported macOS guest TLS instruction (bytes: 65 2e 62 69 6e c3 c3 c3).

  • Full build and full ctest: 1250/1258 passed. Seven of the eight failures were timeouts or crashes under load early in the run (guest_needed_modules, windows_diagnostic_fixture_isolation, guest_gnu_hash, guest_video_out_resolution_status, agc_shader_mode_register, guest_none_relocations, guest_avplayer); all seven pass when rerun alone. The eighth, check_main_sync, fails the same way on main on this host: its Unicode file name test reads git's UTF-8 output as cp1252 (sp ace é.txt).

  • Linux (WSL2 Ubuntu 24.04, GCC 13.3.0): the relinker builds and the macos|tls tests pass (38/39; guest_force_tls_destructor is not run because only the relinker target was built).

  • macOS conversion of every catalog title (79) with main's relinker and with this branch's, same arguments:

    titles
    byte-identical output 54
    refused on main with (bytes: 65 6e), converted with this PR 25
    refused on main with (bytes: 65 6e), now stopping on a later, unrelated refusal 2 (PPSA99141, PPSA99420)
    output that differs otherwise 0
  • The bytes the refusal named stay in place. In 23 of the converted titles, CRYPTOGAMS by <[email protected]> occurs as often in the macOS output as in the input (20 times each); in the 24th, PPSA99039, the string is present in both input and output.

macOS 26.7.1, Apple M2, MoltenVK 1.4.2, x86-64 under Rosetta, added 2026-10-16: head be5dfd623, converted with --macos --to-rosetta and run 20 s each against the runtime of a local tree of main with the macOS port work merged. 20 of the 25 titles were run, and each loads and runs its own code. Three keep running: PSXS5 (PPSA97510) draws its interface at about 11 ms a frame, SwanStationPS5 (PPSA98510) runs with only its network downloads failing (curl 77), and Nuvio PS5 (PPSA99997) is still running at 20 s. The other 17 run until the AGC driver stops on a GPU feature MoltenVK lacks:

  • viewport depth outside [0, 1] (#4650): PPSA17641, PPSA99001, PPSA99002, PPSA99003, PPSA99009, PPSA99773, PPSA99930;
  • Barycentric geometry SPIR-V: geometry shaders are unavailable (#6222): PPSA74126, PPSA98427, PPSA99039, PPSA99082, PPSA99177, PPSA99474, PPSA99505, PPSA99515;
  • the Float64 interpolation stop #6767 removes: PPSA99000;
  • last provoking vertex requires VK_EXT_provoking_vertex (#6741): PPSA99600.

Not run there: SuperTuxKart (PPSA69421, 712 MB). PPSA99004, PPSA99008, PPSA99288 and PPSA99360 stopped on Forbidden syscall instruction, since these runs didn't pass --skip-syscall-check.

Limits of this Mac's GPU. vulkaninfo on Apple M2 with MoltenVK 1.4.2 reports no geometry shaders, no shaderFloat64, no VK_EXT_depth_range_unrestricted and no VK_EXT_provoking_vertex. AnyPS5 turns MoltenVK's VK_KHR_fragment_shader_barycentric off (5333a2053), so barycentric pixel shaders need the geometry-shader fallback. These are limits of the device, so this PR can't remove them. A title named here as stopping on one of them is not tested past that stop:

  • Barycentric geometry SPIR-V: geometry shaders are unavailable: no geometry shaders; #6222 has a route around it.
  • viewport depth outside [0, 1] requires VK_EXT_depth_range_unrestricted: #4650 works around it.
  • last provoking vertex requires VK_EXT_provoking_vertex: #6741 removes it only for draws whose pixel shader can't observe the provoking vertex.
  • 64-bit float instructions: #6767 removes the need for the 16-bit interpolation steps only.

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: none
  • Unblocks: macOS conversion of PPSA17641, PPSA69421, PPSA74126, PPSA97510, PPSA98427, PPSA98510, PPSA99000, PPSA99001, PPSA99002, PPSA99003, PPSA99004, PPSA99008, PPSA99009, PPSA99039, PPSA99082, PPSA99177, PPSA99288, PPSA99360, PPSA99474, PPSA99505, PPSA99515, PPSA99600, PPSA99773, PPSA99930, PPSA99997; PPSA99141 with #6448 and PPSA99420 with #6419
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4874696824 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6410). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-15T14:15:15Z. --- ### What 27 catalog titles cannot be converted for macOS on `main`, among them SuperTuxKart (PPSA69421), PSXS5 (PPSA97510), SwanStationPS5 (PPSA98510), ProsperoStore (PPSA99000), ProsperoRadio (PPSA99001), ProsperoTV (PPSA99003), SymphonyStation5 (PPSA17641) and OpenNOW (PPSA99082). Each fails on the same two bytes: ``` FAIL: Unsupported macOS guest TLS instruction (bytes: 65 6e) (offset 0xbabf4d) ``` They are not code. The titles link OpenSSL, whose assembly keeps `CRYPTOGAMS by <[email protected]>` in the code segment; at PSXS5's offset 0xbabf4d the bytes are the `en` of `openssl` (`... 6f 70 | 65 6e 73 73 6c ...`). A function range that begins inside an instruction makes the code analysis collect a second decoding from the middle of it, and here that decoding starts with a GS prefix. The Windows TLS rewriter skips a non-FS segment-prefixed decoding inside an earlier collected instruction (90dcd6256, "tolerate unwind ranges that split an instruction"), so the same titles convert for Windows. The macOS scan in [`MacOsImage.cpp`](https://github.com/boykopovar/AnyPS5/blob/0afa6a607e/core/relinker/elfpatcher/src/macos/MacOsImage.cpp) has no such check and refuses the module. The macOS scan now tracks the end of the decodings it has seen, as the Windows rewriter does, and skips a segment-prefixed decoding that starts inside an earlier one unless the prefix is FS. A GS access at an instruction start is still refused. With this PR 25 of the 27 convert. The other two get past this refusal and stop on unrelated ones, each with its own PR: Mortalfin (PPSA99141) on `Guest TLS access without a non-empty PT_TLS` (#6448) and PS5MC (PPSA99420) on the stack-protector check `sub %fs:0x28,%rax` (#6419). Three commits: 1. `fix(relinker): skip prefixed decodings inside an earlier instruction in the macOS TLS scan`. 2. `test(relinker): convert a function that begins inside an instruction for macOS`: a new `macos_tls_overlap` test converts the Windows coverage group's `function-begins-inside-instruction` fixture with `--macos`. A symbol starts inside a `movabs` whose immediate holds a GS-prefixed decoding (`65 2e 62 69 6e`). It converts, and the `movabs` is unchanged in the output. 3. `test(relinker): keep refusing a GS access at an instruction start for macOS`. There is no fourth step to split out. ### Tested Windows host (be5dfd6237 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. - Each of the three commits builds, and the relinker tests pass at each (`macos|tls_function_coverage|tls_diagnostics|guest_tls|empty_tls`, 35/36/36 tests; run on `main` d92a8dad39 before rebasing onto 0afa6a607e, which changes nothing under `core/relinker`). - `macos_tls_overlap` fails without the fix: with `MacOsImage.cpp` as on `main`, `function-begins-inside-instruction` stops with `Unsupported macOS guest TLS instruction (bytes: 65 2e 62 69 6e c3 c3 c3)`. - Full build and full `ctest`: 1250/1258 passed. Seven of the eight failures were timeouts or crashes under load early in the run (`guest_needed_modules`, `windows_diagnostic_fixture_isolation`, `guest_gnu_hash`, `guest_video_out_resolution_status`, `agc_shader_mode_register`, `guest_none_relocations`, `guest_avplayer`); all seven pass when rerun alone. The eighth, `check_main_sync`, fails the same way on `main` on this host: its Unicode file name test reads git's UTF-8 output as cp1252 (`sp ace é.txt`). - Linux (WSL2 Ubuntu 24.04, GCC 13.3.0): the relinker builds and the `macos|tls` tests pass (38/39; `guest_force_tls_destructor` is not run because only the relinker target was built). - macOS conversion of every catalog title (79) with `main`'s relinker and with this branch's, same arguments: | | titles | | - | - | | byte-identical output | 54 | | refused on `main` with `(bytes: 65 6e)`, converted with this PR | 25 | | refused on `main` with `(bytes: 65 6e)`, now stopping on a later, unrelated refusal | 2 (PPSA99141, PPSA99420) | | output that differs otherwise | 0 | - The bytes the refusal named stay in place. In 23 of the converted titles, `CRYPTOGAMS by <[email protected]>` occurs as often in the macOS output as in the input (20 times each); in the 24th, PPSA99039, the string is present in both input and output. macOS 26.7.1, Apple M2, MoltenVK 1.4.2, x86-64 under Rosetta, added 2026-10-16: head be5dfd623, converted with `--macos --to-rosetta` and run 20 s each against the runtime of a local tree of `main` with the macOS port work merged. 20 of the 25 titles were run, and each loads and runs its own code. Three keep running: PSXS5 (PPSA97510) draws its interface at about 11 ms a frame, SwanStationPS5 (PPSA98510) runs with only its network downloads failing (`curl 77`), and Nuvio PS5 (PPSA99997) is still running at 20 s. The other 17 run until the AGC driver stops on a GPU feature MoltenVK lacks: - `viewport depth outside [0, 1]` (#4650): PPSA17641, PPSA99001, PPSA99002, PPSA99003, PPSA99009, PPSA99773, PPSA99930; - `Barycentric geometry SPIR-V: geometry shaders are unavailable` (#6222): PPSA74126, PPSA98427, PPSA99039, PPSA99082, PPSA99177, PPSA99474, PPSA99505, PPSA99515; - the Float64 interpolation stop #6767 removes: PPSA99000; - `last provoking vertex requires VK_EXT_provoking_vertex` (#6741): PPSA99600. Not run there: SuperTuxKart (PPSA69421, 712 MB). PPSA99004, PPSA99008, PPSA99288 and PPSA99360 stopped on `Forbidden syscall instruction`, since these runs didn't pass `--skip-syscall-check`. **Limits of this Mac's GPU.** `vulkaninfo` on Apple M2 with MoltenVK 1.4.2 reports no geometry shaders, no `shaderFloat64`, no `VK_EXT_depth_range_unrestricted` and no `VK_EXT_provoking_vertex`. AnyPS5 turns MoltenVK's `VK_KHR_fragment_shader_barycentric` off (5333a2053), so barycentric pixel shaders need the geometry-shader fallback. These are limits of the device, so this PR can't remove them. A title named here as stopping on one of them is not tested past that stop: - `Barycentric geometry SPIR-V: geometry shaders are unavailable`: no geometry shaders; #6222 has a route around it. - `viewport depth outside [0, 1] requires VK_EXT_depth_range_unrestricted`: #4650 works around it. - `last provoking vertex requires VK_EXT_provoking_vertex`: #6741 removes it only for draws whose pixel shader can't observe the provoking vertex. - 64-bit float instructions: #6767 removes the need for the 16-bit interpolation steps only. ### 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: none - [x] Unblocks: macOS conversion of PPSA17641, PPSA69421, PPSA74126, PPSA97510, PPSA98427, PPSA98510, PPSA99000, PPSA99001, PPSA99002, PPSA99003, PPSA99004, PPSA99008, PPSA99009, PPSA99039, PPSA99082, PPSA99177, PPSA99288, PPSA99360, PPSA99474, PPSA99505, PPSA99515, PPSA99600, PPSA99773, PPSA99930, PPSA99997; PPSA99141 with #6448 and PPSA99420 with #6419 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-15 14:33:57 +00:00 (Migrated from github.com)

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


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
PR 6044 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
PR 7173 core/relinker/CMakeLists.txt
PR 7450 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
PR 7531 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6194615545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6410#issuecomment-6194615545). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T14:33:57Z. --- <!-- 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` | | [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` | | [PR 7173](https://www.github.com/boykopovar/AnyPS5/pull/7173) | `core/relinker/CMakeLists.txt` | | [PR 7450](https://www.github.com/boykopovar/AnyPS5/pull/7450) | `core/relinker/CMakeLists.txt`<br>`core/relinker/elfpatcher/src/macos/MacOsImage.cpp` | | [PR 7531](https://www.github.com/boykopovar/AnyPS5/pull/7531) | `core/relinker/CMakeLists.txt` |
DavidSamir commented 2026-10-16 04:25:37 +00:00 (Migrated from github.com)

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


Hardware run on Apple silicon, as asked in the handoff.

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.

  • PSXS5 (PPSA97510): main's relinker fails with Unsupported macOS guest TLS instruction (bytes: 65 6e) (offset 0xbabf4d); with this branch alone it converts. The converted title runs on the M2 for the full 60 s, drawing its UI (ui: draw 4.1 ms, present 12.6 ms per frame) through MoltenVK.
  • The relinkers of #6419 and #6448 alone stop on the same 65 6e for PSXS5, so this is the change that moves it.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208056177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6410#issuecomment-6208056177). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-16T04:25:37Z. --- Hardware run on Apple silicon, as asked in the handoff. 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. - PSXS5 (PPSA97510): `main`'s relinker fails with `Unsupported macOS guest TLS instruction (bytes: 65 6e) (offset 0xbabf4d)`; with this branch alone it converts. The converted title runs on the M2 for the full 60 s, drawing its UI (`ui: draw 4.1 ms, present 12.6 ms per frame`) through MoltenVK. - The relinkers of #6419 and #6448 alone stop on the same `65 6e` for PSXS5, so this is the change that moves it. AI-assisted: yes
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!6410
No description provided.