fix(relinker): keep FS and GS accesses in place when lowering for macOS #25971

Merged
Gonic0 merged 1 commit from upstream-pr/25971 into main 2026-11-23 09:44:45 +00:00
Gonic0 commented 2026-11-23 02:16:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-11-23T02:16:58Z.


What

relinker --macos --to-rosetta stopped GTA V (PPSA04264) with "AMD-only instruction is also a guest TLS access". At 0xafd542 a 4-byte vmovups %ymm0,(%rbx) is split by the Rosetta lowering and needs a 5-byte jump, so the converter moves a neighbour into its stub. The instruction before it is another 256-bit store with its own stub, so after #7309's preferred non-segment pass the converter falls back to the following movq %fs:0x0,%rax. The macOS image writer rewrites every guest FS access into a TLS stub and every GS access into a trap, so a moved segment access can never be written there, and the writer refuses the image.

The converter now takes keepSegmentAccesses, which only the macOS output sets (the executable in Conversion.cpp and the guest modules in GuestModuleBuilder.cpp). With it, an instruction with an FS or GS prefix is never moved: the window search skips the segment fallback and goes on to an island, islands do not take a segment access into their window, and a short AMD-only instruction whose jump would cover one is refused (or kept when its lowering is optional) instead of failing later in the writer. Linux and Windows output, and the default of MakeAmd64OnlyConverter, are unchanged, so #7309's fallback still applies there.

Tested

Apple M5 Pro, macOS 27.3, x86_64 Release under Rosetta 2, on main 441fa65119.

  • GTA V (PPSA04264) eboot.elf, unwrapped with tools/unwrap_self.py: relinker --macos --registry --to-rosetta on main fails with "AMD-only instruction is also a guest TLS access" at RVA 0xb0d542; with this pull request it completes (147,551 stubs, 2 optional VRCPPS kept for lack of room between branches) and converts the 3 sce_module modules. tools/import_audit.py on the four registries exits 0. The title then starts under AnyPS5 and reaches its DLC scan before a separate memory-mapping stop that this change does not touch.
  • amd64_only_converter: new converterWideStoreKeepsSegmentAccesses covers FS and GS neighbours: with the option a 256-bit store before one is lowered through an island that leaves the access in place, and a store whose only room is such an access is refused; without the option the store still falls back to the access.
  • The 195 relinker tests from core/relinker CMake files pass.
  • tools/check_conventions.py --base upstream/main passes.

Not tested on Linux or Windows output beyond the converter tests, where the default is unchanged.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
  • Fixes: none
  • Unblocks: PPSA04264 (GTA V) conversion for macOS under Rosetta
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5445947974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25971). Originally posted by [Gonic0](https://github.com/Gonic0) on 2026-11-23T02:16:58Z. --- ### What `relinker --macos --to-rosetta` stopped GTA V (PPSA04264) with "AMD-only instruction is also a guest TLS access". At `0xafd542` a 4-byte `vmovups %ymm0,(%rbx)` is split by the Rosetta lowering and needs a 5-byte jump, so the converter moves a neighbour into its stub. The instruction before it is another 256-bit store with its own stub, so after #7309's preferred non-segment pass the converter falls back to the following `movq %fs:0x0,%rax`. The macOS image writer rewrites every guest FS access into a TLS stub and every GS access into a trap, so a moved segment access can never be written there, and the writer refuses the image. The converter now takes `keepSegmentAccesses`, which only the macOS output sets (the executable in `Conversion.cpp` and the guest modules in `GuestModuleBuilder.cpp`). With it, an instruction with an FS or GS prefix is never moved: the window search skips the segment fallback and goes on to an island, islands do not take a segment access into their window, and a short AMD-only instruction whose jump would cover one is refused (or kept when its lowering is optional) instead of failing later in the writer. Linux and Windows output, and the default of `MakeAmd64OnlyConverter`, are unchanged, so #7309's fallback still applies there. ### Tested Apple M5 Pro, macOS 27.3, x86_64 Release under Rosetta 2, on `main` `441fa65119`. - GTA V (PPSA04264) `eboot.elf`, unwrapped with `tools/unwrap_self.py`: `relinker --macos --registry --to-rosetta` on `main` fails with "AMD-only instruction is also a guest TLS access" at RVA `0xb0d542`; with this pull request it completes (147,551 stubs, 2 optional `VRCPPS` kept for lack of room between branches) and converts the 3 `sce_module` modules. `tools/import_audit.py` on the four registries exits 0. The title then starts under AnyPS5 and reaches its DLC scan before a separate memory-mapping stop that this change does not touch. - `amd64_only_converter`: new `converterWideStoreKeepsSegmentAccesses` covers FS and GS neighbours: with the option a 256-bit store before one is lowered through an island that leaves the access in place, and a store whose only room is such an access is refused; without the option the store still falls back to the access. - The 195 relinker tests from `core/relinker` CMake files pass. - `tools/check_conventions.py --base upstream/main` passes. Not tested on Linux or Windows output beyond the converter tests, where the default is unchanged. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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] Fixes: none - [x] Unblocks: PPSA04264 (GTA V) conversion for macOS under Rosetta - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-23 02:21:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T02:21:49Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against db7ae63096:

  • Conventions: tools/check_conventions.py passed.
  • Build: amd64_only_converter_tests built cleanly.
  • CTest (amd64_only_converter):
    1/1 Test #6431: amd64_only_converter .............   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/relinker/codegen/include/codegen/IAmd64OnlyConverter.hpp, core/relinker/codegen/src/Amd64OnlyConverter.cpp, core/relinker/relinker/src/guest/GuestModuleBuilder.cpp, core/relinker/relinker/src/pipeline/Conversion.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified IAmd64OnlyConverter interface extension and default argument keepSegmentAccesses = false preserves existing call sites and semantics across non-macOS targets.
    • Verified WindowPlacer::_movable and WindowPlacer::Window prevent candidate instructions with SegmentPrefix != 0 from being relocated into window or island stubs when _keepSegmentAccesses is true.
    • Verified Amd64OnlyConverter::_convertSegment properly refuses short AMD-only instruction extensions over following segment-prefixed instructions when _keepSegmentAccesses is set.
    • Verified macOS target propagation in Conversion.cpp (options.Target == TargetSystem::MacOs) and GuestModuleBuilder.cpp (macos parameter).
    • Verified AGENTS.md rule compliance: no comments in source code, no title-specific workarounds or magic paths, and Amd64OnlyConverterTests.cpp provides rigorous positive, negative, and fallback coverage for both FS and GS accesses.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015891109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25971#pullrequestreview-6015891109). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-23T02:21:49Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `db7ae63096`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `amd64_only_converter_tests` built cleanly. - **CTest** (`amd64_only_converter`): ``` 1/1 Test #6431: amd64_only_converter ............. Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/relinker/codegen/include/codegen/IAmd64OnlyConverter.hpp`, `core/relinker/codegen/src/Amd64OnlyConverter.cpp`, `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp`, `core/relinker/relinker/src/pipeline/Conversion.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified IAmd64OnlyConverter interface extension and default argument keepSegmentAccesses = false preserves existing call sites and semantics across non-macOS targets. - Verified WindowPlacer::_movable and WindowPlacer::Window prevent candidate instructions with SegmentPrefix != 0 from being relocated into window or island stubs when _keepSegmentAccesses is true. - Verified Amd64OnlyConverter::_convertSegment properly refuses short AMD-only instruction extensions over following segment-prefixed instructions when _keepSegmentAccesses is set. - Verified macOS target propagation in Conversion.cpp (options.Target == TargetSystem::MacOs) and GuestModuleBuilder.cpp (macos parameter). - Verified AGENTS.md rule compliance: no comments in source code, no title-specific workarounds or magic paths, and Amd64OnlyConverterTests.cpp provides rigorous positive, negative, and fallback coverage for both FS and GS accesses. Looks Good To Me
MarcZX10 commented 2026-11-23 02:26:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:26:39Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the exact-head review found no verified defects, and the inspected code supports merging.

What I ran

Reviewed head db7ae630964e46ed25e01a7a161fd3694bb324b3. No commands or tests were run in this review; the test results below are author-reported.

Results

Check Result Note
Changed-file review passed All five changed files read
Automated checks not run Results reported by the author

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently. The reported macOS conversion, relinker tests, conventions check, and Linux or Windows behavior were not independently confirmed. No files were excluded: all five files in the manifest were included and read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015913262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25971#pullrequestreview-6015913262). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:26:39Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the exact-head review found no verified defects, and the inspected code supports merging. ## What I ran Reviewed head `db7ae630964e46ed25e01a7a161fd3694bb324b3`. No commands or tests were run in this review; the test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | All five changed files read | | Automated checks | not run | Results reported by the author | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run independently. The reported macOS conversion, relinker tests, conventions check, and Linux or Windows behavior were not independently confirmed. No files were excluded: all five files in the manifest were included and read. ## To get this to a good state Nothing is required.
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!25971
No description provided.