feat(relinker): support SSE guest GS memory accesses #11689

Open
Felipebmaitan wants to merge 59 commits from upstream-pr/11689 into main
Felipebmaitan commented 2026-10-27 02:53:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Felipebmaitan on 2026-10-27T02:53:20Z.


What

The relinker replays bounded legacy SSE memory moves through the protected guest GS frame. Native instructions supply widths, alignment, lane and MXCSR behavior. Unmodeled arithmetic, prefixes, MMX and VEX/EVEX/XOP keep the UD2 fallback.

The follow-up adds native load and store coverage for a short GS instruction followed by a borrowed mov ebx, imm32 and a GS SSE move using RBX as its base or scaled index. The first replay restores its scratch before the follower runs. The later replay reads the new RBX for address formation, then saves and restores it around the SSE instruction. The reported clobber did not reproduce and the follow-up changes only the test.

This remains a draft targeting main. The latest published #11661 head b813f34cfbbadc2d73e879b1e973491add56377c is already included. Its follow-up was unpublished when its worker ended, so current-main integration and fresh validation of that stack are pending. View the SSE increment over #11661.

Tested

Fresh validation on faf9d25c09f105a84ed01c3c9785651d9d989281 used native Windows 11 Pro build 26300, an x86-64 Ryzen 7 9800X3D, WinLibs GCC 15.2.0, Ninja and Release. A clean relinker-only configure and build passed 50/50 focused CTests across scalar, short and SSE GS replay, faults, fallback, relocations, lookup, entry bounds, TLS and ELF reader bounds. The SSE address test passed all 85 cases, including the four borrowed RBX cases.

With that fresh relinker and the saved production libc and fixtures, all 85 production SSE address cases and the relocation/startup integration fixture passed. The production build did not start because the shared build mutex remained held on retry.

In the earlier control run on native Windows 11 Pro build 26300 (x86-64 Ryzen 7 9800X3D), I ran the updated SSE address group against the saved WinLibs GCC 15.2 Release relinker and both the standalone and production-libc runners. Both passed 85/85 cases, including the four new cases. The saved sources matched the reviewed head 5551631d9e9263e8634e44d272d683966e1d18b5 across 622 relinker, libc and build inputs after line-ending normalization. In separate controls, removing RBX from the emitted replay address record caused each new case to fail the expected vector-state or store-footprint assertion.

Local conventions and diff whitespace checks passed before this head was pushed. Hosted Conventions reported the unchecked current-main checklist item. Hosted Conventions result. The function-name overlap scan searched 2,235 open PRs and reported no matches for the queried names. The candidate faf9d25c09f105a84ed01c3c9785651d9d989281 changes only the Python test relative to the reviewed head. The earlier 37/37 Windows production/relinker results and hosted checks were reported for 5551631d9e9263e8634e44d272d683966e1d18b5. A fresh production libc build, a current-main merged run, hosted production checks and title execution remain pending.

One independent reviewer inspected the immutable 5551631d9e..faf9d25c09 range and runtime path and found no blocking issues. The current-main merge still has inherited ELF reader, bounds-test and debt conflicts. MarcZX10’s follow-up found no blocking defect in the inspected ranges and recorded a comment without formal approval. GitHub previously denied the re-review request because this account lacks upstream write access. A collaborator with upstream access can request formal review and run the production workflow once the stack can merge. MarcZX10’s follow-up review.

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: #11661, #10861 (merge order, with transitive #11628 and #10518)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5027845915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11689). Originally posted by [Felipebmaitan](https://github.com/Felipebmaitan) on 2026-10-27T02:53:20Z. --- ### What The relinker replays bounded legacy SSE memory moves through the protected guest GS frame. Native instructions supply widths, alignment, lane and MXCSR behavior. Unmodeled arithmetic, prefixes, MMX and VEX/EVEX/XOP keep the UD2 fallback. The follow-up adds native load and store coverage for a short GS instruction followed by a borrowed `mov ebx, imm32` and a GS SSE move using RBX as its base or scaled index. The first replay restores its scratch before the follower runs. The later replay reads the new RBX for address formation, then saves and restores it around the SSE instruction. The reported clobber did not reproduce and the follow-up changes only the test. This remains a draft targeting main. The latest published #11661 head `b813f34cfbbadc2d73e879b1e973491add56377c` is already included. Its follow-up was unpublished when its worker ended, so current-main integration and fresh validation of that stack are pending. [View the SSE increment over #11661](https://github.com/boykopovar/AnyPS5/compare/b813f34cfbbadc2d73e879b1e973491add56377c...faf9d25c09f105a84ed01c3c9785651d9d989281). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Fresh validation on `faf9d25c09f105a84ed01c3c9785651d9d989281` used native Windows 11 Pro build 26300, an x86-64 Ryzen 7 9800X3D, WinLibs GCC 15.2.0, Ninja and Release. A clean relinker-only configure and build passed **50/50 focused CTests** across scalar, short and SSE GS replay, faults, fallback, relocations, lookup, entry bounds, TLS and ELF reader bounds. The SSE address test passed all 85 cases, including the four borrowed RBX cases. With that fresh relinker and the saved production `libc` and fixtures, all 85 production SSE address cases and the relocation/startup integration fixture passed. The production build did not start because the shared build mutex remained held on retry. In the earlier control run on native Windows 11 Pro build 26300 (x86-64 Ryzen 7 9800X3D), I ran the updated SSE address group against the saved WinLibs GCC 15.2 Release relinker and both the standalone and production-libc runners. Both passed **85/85 cases**, including the four new cases. The saved sources matched the reviewed head `5551631d9e9263e8634e44d272d683966e1d18b5` across 622 relinker, libc and build inputs after line-ending normalization. In separate controls, removing RBX from the emitted replay address record caused each new case to fail the expected vector-state or store-footprint assertion. Local conventions and diff whitespace checks passed before this head was pushed. Hosted Conventions reported the unchecked current-main checklist item. [Hosted Conventions result](https://github.com/boykopovar/AnyPS5/actions/runs/44786733834/job/136463462795). The function-name overlap scan searched 2,235 open PRs and reported no matches for the queried names. The candidate `faf9d25c09f105a84ed01c3c9785651d9d989281` changes only the Python test relative to the reviewed head. The earlier 37/37 Windows production/relinker results and hosted checks were reported for `5551631d9e9263e8634e44d272d683966e1d18b5`. A fresh production libc build, a current-main merged run, hosted production checks and title execution remain pending. One independent reviewer inspected the immutable `5551631d9e..faf9d25c09` range and runtime path and found no blocking issues. The current-main merge still has inherited ELF reader, bounds-test and debt conflicts. MarcZX10’s follow-up found no blocking defect in the inspected ranges and recorded a comment without formal approval. GitHub previously denied the re-review request because this account lacks upstream write access. A collaborator with upstream access can request formal review and run the production workflow once the stack can merge. [MarcZX10’s follow-up review](https://github.com/boykopovar/AnyPS5/pull/11689#pullrequestreview-6002068041). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [ ] 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: <!-- #PR, or none --> #11661, #10861 (merge order, with transitive #11628 and #10518) - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
CnRJay commented 2026-11-01 19:49:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:26Z.

Review: COMMENTED


Correction (2026-11-01): this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows Unblocks: none; a title is only required when the PR fixes a title. The technical points below are unaffected.

No title ID and no log line. The Tested section states "No PS5, title, title-unblock or performance verification is claimed". Maintainers close PRs that name no title ID plus a log line proving a title reaches the change on main. Which title runs SSE %gs: accesses through this path, and what does main log for it today?

Stacked branch. 43 commits and 39 files (+2336) because the branch carries #11624, #11628, #11661 and the carried #11090/#11276 prerequisites. The main-target diff mixes four PRs. Please keep this draft until the prerequisites merge, or retarget it so only the SSE layer is reviewed. #11698 builds on this one in the same way, so the same applies there.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729922266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11689#pullrequestreview-5729922266). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:26Z. **Review:** COMMENTED --- **Correction (2026-11-01):** this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows `Unblocks: none`; a title is only required when the PR fixes a title. The technical points below are unaffected. **No title ID and no log line.** The Tested section states "No PS5, title, title-unblock or performance verification is claimed". Maintainers close PRs that name no title ID plus a log line proving a title reaches the change on main. Which title runs SSE `%gs:` accesses through this path, and what does main log for it today? **Stacked branch.** 43 commits and 39 files (+2336) because the branch carries #11624, #11628, #11661 and the carried #11090/#11276 prerequisites. The main-target diff mixes four PRs. Please keep this draft until the prerequisites merge, or retarget it so only the SSE layer is reviewed. #11698 builds on this one in the same way, so the same applies there.
MarcZX10 commented 2026-11-20 09:28:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T09:28:13Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: preserve the original scratch-register value when a borrowed follower modifies it.

What I ran

Reviewed head 5551631d9e9263e8634e44d272d683966e1d18b5; no local commands or tests were run. I inspected the prepared diff and all changed-file contents listed in the review manifest. No merged-preview check was run.

Results

Check Result Note
Changed-file review passed All 34 changed files read
Local tests not run Author reports 37 focused tests passed at this head
Negative control not run No local test environment

Findings

Blocking

  • core/relinker/elfpatcher/src/windows/WindowsTlsBuilder.cpp:278 accepts a borrowed follower that writes the scratch register selected for the preceding GS replay. For example, a GS memory instruction followed by mov ebx, 1 and then a GS SSE memory instruction can borrow the mov into the latter's replay span. WindowsGuestGs::TryAppend chooses EBX as the second instruction's scratch for common vector moves (core/relinker/elfpatcher/src/windows/WindowsGuestGs.cpp:53-54). The first replay restores EBX before resuming at the second GS instruction, but the borrowed mov ebx, 1 then changes EBX before the second replay computes its effective address from it. The result is a wrong memory access and potentially corrupted guest state. Reject borrowing when a follower clobbers a register used as a later replay base/index, or preserve and restore that register across the borrowed span. The borrowed-follower tests do not cover this register dependency.

Non-blocking

None.

Not verified

No machine-side tests were run. The author reports focused Windows tests at the reviewed head; this review did not reproduce them. PS5/title behavior, physical non-AVX behavior, and performance remain unverified as stated in the PR description. No files were excluded by the review manifest.

To get this to a good state

Add a regression covering a borrowed follower that writes the next GS replay's base or index register, fix the register preservation or borrowing policy, and rerun the focused Windows GS tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5990402338 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11689#pullrequestreview-5990402338). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T09:28:13Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: preserve the original scratch-register value when a borrowed follower modifies it. ## What I ran Reviewed head `5551631d9e9263e8634e44d272d683966e1d18b5`; no local commands or tests were run. I inspected the prepared diff and all changed-file contents listed in the review manifest. No merged-preview check was run. ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | All 34 changed files read | | Local tests | not run | Author reports 37 focused tests passed at this head | | Negative control | not run | No local test environment | ## Findings ### Blocking - `core/relinker/elfpatcher/src/windows/WindowsTlsBuilder.cpp:278` accepts a borrowed follower that writes the scratch register selected for the preceding GS replay. For example, a GS memory instruction followed by `mov ebx, 1` and then a GS SSE memory instruction can borrow the `mov` into the latter's replay span. `WindowsGuestGs::TryAppend` chooses EBX as the second instruction's scratch for common vector moves (`core/relinker/elfpatcher/src/windows/WindowsGuestGs.cpp:53-54`). The first replay restores EBX before resuming at the second GS instruction, but the borrowed `mov ebx, 1` then changes EBX before the second replay computes its effective address from it. The result is a wrong memory access and potentially corrupted guest state. Reject borrowing when a follower clobbers a register used as a later replay base/index, or preserve and restore that register across the borrowed span. The borrowed-follower tests do not cover this register dependency. ### Non-blocking None. ## Not verified No machine-side tests were run. The author reports focused Windows tests at the reviewed head; this review did not reproduce them. PS5/title behavior, physical non-AVX behavior, and performance remain unverified as stated in the PR description. No files were excluded by the review manifest. ## To get this to a good state Add a regression covering a borrowed follower that writes the next GS replay's base or index register, fix the register preservation or borrowing policy, and rerun the focused Windows GS tests.
MarcZX10 commented 2026-11-21 02:06:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T02:06:12Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected code shows no verified blocking defect, but a formal approval is not justified because the full changed-file set and fresh validation on this head were not reviewed or run.

What I ran

Head: faf9d25c09f105a84ed01c3c9785651d9d989281. I used repo_read.py to inspect the prepared review bundle and targeted repository ranges. No build or tests were run.

Results

Check Result Note
Bundle and diff inspection passed Prepared bundle read
Targeted code inspection passed Runtime and SSE test context
Build and tests not run No commands run
Current-main integration not run Description says integration is pending

Findings

Blocking

None identified in the inspected ranges.

Non-blocking

  • The PR description says current-main integration and fresh production validation are pending. Complete those checks on the candidate head before treating the reported Windows results from an earlier head as validation of this revision.

Not verified

I read description.md, commits.md, manifest.json, and diff.patch, plus targeted ranges from core/relinker/elfpatcher/src/windows/WindowsGuestGs.cpp, core/relinker/relinker/tests/test_windows_guest_gs_sse.py, and core/libs/tests/GuestGsLookup.cpp. The prepared file listing shows 34 changed files, all included; I did not read every changed file or every hunk. review/files.json was not available as a review document. Build, tests, current-main merge, hosted checks, and title or console execution were not verified here.

To get this to a good state

Nothing is required. Optional: complete current-main integration and fresh production validation on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002068041 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11689#pullrequestreview-6002068041). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T02:06:12Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected code shows no verified blocking defect, but a formal approval is not justified because the full changed-file set and fresh validation on this head were not reviewed or run. ## What I ran Head: `faf9d25c09f105a84ed01c3c9785651d9d989281`. I used `repo_read.py` to inspect the prepared review bundle and targeted repository ranges. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Bundle and diff inspection | passed | Prepared bundle read | | Targeted code inspection | passed | Runtime and SSE test context | | Build and tests | not run | No commands run | | Current-main integration | not run | Description says integration is pending | ## Findings ### Blocking None identified in the inspected ranges. ### Non-blocking - The PR description says current-main integration and fresh production validation are pending. Complete those checks on the candidate head before treating the reported Windows results from an earlier head as validation of this revision. ## Not verified I read `description.md`, `commits.md`, `manifest.json`, and `diff.patch`, plus targeted ranges from `core/relinker/elfpatcher/src/windows/WindowsGuestGs.cpp`, `core/relinker/relinker/tests/test_windows_guest_gs_sse.py`, and `core/libs/tests/GuestGsLookup.cpp`. The prepared file listing shows 34 changed files, all included; I did not read every changed file or every hunk. `review/files.json` was not available as a review document. Build, tests, current-main merge, hosted checks, and title or console execution were not verified here. ## To get this to a good state Nothing is required. Optional: complete current-main integration and fresh production validation on this head.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/11689:upstream-pr/11689'
git switch 'upstream-pr/11689'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/11689'
git switch 'upstream-pr/11689'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/11689'
git switch 'upstream-pr/11689'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/11689'
git switch 'main'
git merge --squash 'upstream-pr/11689'
git switch 'main'
git merge --ff-only 'upstream-pr/11689'
git switch 'main'
git merge 'upstream-pr/11689'
git push origin 'main'
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!11689
No description provided.