fix(relinker): move a neighbour without an FS or GS prefix with a 256-bit store first #7309

Merged
morten-holm merged 2 commits from upstream-pr/7309 into main 2026-10-17 23:18:03 +00:00
morten-holm commented 2026-10-17 22:40:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by morten-holm on 2026-10-17T22:40:57Z.


What

A 256-bit store (vmovups ymm) is 4 bytes long. The jump to its stub needs 5 bytes, so the stub window takes a neighbouring instruction.

The window took the following instruction first. In PPSA21567 that instruction is the thread-pointer read mov rax, fs:0. The macOS writer cannot rewrite a TLS access inside a stub, so it refuses the module:

FAIL: AMD-only instruction is also a guest TLS access (offset 0x4b9f8c)

The window now tries a neighbour without an FS or GS prefix first, the following one and then the preceding one. It uses the old order only when no such neighbour fits. Output does not change where the access can stay in the stub.

Tested

  • macOS (Apple M2), relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON) on main b4f05ab32: 178 of 178 tests pass. check_conventions.py passes.
  • The new checks in converterWideStoreWindows fail when the fix is reverted. They cover an FS read and a GS read after the store, and the fallback when the store has no other neighbour.
  • relinker --macos --to-rosetta on PPSA21567: without the fix it stops with the error above. With the fix it relinks (164,493 stubs, 1 module converted).
  • Converter output on the PPSA21567 executable, with and without the fix: both produce 164,493 sites. Without the fix, 3 sites contain an FS access (0x4a9f8c, 0x4b5bb26, 0x603ab66). With the fix, none do. Only these 3 sites differ: each 16-byte window (store plus mov rax, fs:0) becomes an 8-byte window that starts 4 bytes earlier. The other 164,490 sites are identical.
  • Not tested: Linux and Windows hosts. The title does not run on macOS yet (it stops later on the missing mesh shader path), so the stubs did not run. This PR only fixes the relink.

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 (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA21567 #357 (macOS relink only)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4904542109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7309). Originally posted by [morten-holm](https://github.com/morten-holm) on 2026-10-17T22:40:57Z. --- ### What A 256-bit store (`vmovups ymm`) is 4 bytes long. The jump to its stub needs 5 bytes, so the stub window takes a neighbouring instruction. The window took the following instruction first. In PPSA21567 that instruction is the thread-pointer read `mov rax, fs:0`. The macOS writer cannot rewrite a TLS access inside a stub, so it refuses the module: ``` FAIL: AMD-only instruction is also a guest TLS access (offset 0x4b9f8c) ``` The window now tries a neighbour without an FS or GS prefix first, the following one and then the preceding one. It uses the old order only when no such neighbour fits. Output does not change where the access can stay in the stub. ### Tested - macOS (Apple M2), relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`) on `main` b4f05ab32: 178 of 178 tests pass. `check_conventions.py` passes. - The new checks in `converterWideStoreWindows` fail when the fix is reverted. They cover an FS read and a GS read after the store, and the fallback when the store has no other neighbour. - `relinker --macos --to-rosetta` on PPSA21567: without the fix it stops with the error above. With the fix it relinks (164,493 stubs, 1 module converted). - Converter output on the PPSA21567 executable, with and without the fix: both produce 164,493 sites. Without the fix, 3 sites contain an FS access (0x4a9f8c, 0x4b5bb26, 0x603ab66). With the fix, none do. Only these 3 sites differ: each 16-byte window (store plus `mov rax, fs:0`) becomes an 8-byte window that starts 4 bytes earlier. The other 164,490 sites are identical. - Not tested: Linux and Windows hosts. The title does not run on macOS yet (it stops later on the missing mesh shader path), so the stubs did not run. This PR only fixes the relink. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA21567 #357 (macOS relink only) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-17 22:55:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T22:55:14Z.


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/codegen/tests/Amd64OnlyConverterTests.cpp
PR 6111 core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6242642301 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7309#issuecomment-6242642301). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T22:55:14Z. --- <!-- 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/codegen/tests/Amd64OnlyConverterTests.cpp` | | [PR 6111](https://www.github.com/boykopovar/AnyPS5/pull/6111) | `core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp` |
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!7309
No description provided.