feat(relinker): support VEX guest GS memory accesses #11698

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

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


What

Replay bounded C4/C5 VEX guest GS memory moves through the protected Windows GS frame. The replay preserves effective addresses, native alignment and transfer widths, and upper YMM lane behavior. Unsupported encodings retain their own-length UD2 fallback. Conversion and startup are host-AVX-independent. Reaching VEX replay without OS-enabled AVX state reports an illegal instruction at the original guest RIP with the stack and registers restored.

This follow-up adds four cases for C4/C5 RIP-relative VMOVDQU loads borrowed by a short GS instruction, covering both 128-bit and 256-bit forms. It merges the published #11689 head faf9d25c09f105a84ed01c3c9785651d9d989281, which adds coverage for a borrowed EBX write feeding an SSE load or store through RBX. The candidate changes two Python tests relative to the previous published VEX head. VEX increment over #11689.

This PR stays draft targeting main. The #11661 worker ended with its current-main integration unpublished, so the updated short replay and scalar replay-fault work are still pending in the published stack. The merge preview against main c8f72e905cce039a05970ed39d2373f770217901 has inherited conflicts in the ELF reader, ELF bounds tests and libc/libkernel debt. #10518 and #10861 remain open. The shared entry-stub signatures with #15245 still need merge-order coordination.

Tested

On native Windows 11 Pro build 26300, x86-64 Ryzen 7 9800X3D, 79/79 focused tests passed with the test scripts at 74746df3147c84663716e32f0fd7dc920cbe2ed8 and archived WinLibs GCC 15.2 Release binaries. Hashes for 774 archived relinker, libc, libkernel and build inputs matched the previous published VEX head f16c9e062bd1d7607e1b3c976a6071904a81960c after line-ending normalization. The run covered scalar and short GS replay, SSE and VEX faults and fallback, synthetic --no-avx and cached lookup, production-libc replay, executable and module startup, entry roots and bounds, relocations, TLS, deferred dependencies and sysarch/pthread. Both runners passed 81/81 VEX and 85/85 SSE address cases.

Negative controls shifted the four new VEX replay displacements by one byte. Each failed the expected YMM-state assertion. Conventions passed against origin/main using both checker versions, and the diff whitespace check passed. The function-name overlap scan found no matching open implementations for the queried names. Existing shared-file and merge-order work remains documented above.

One independent reviewer inspected f16c9e062b..74746df314, verified both published ancestors, checked the archived source correspondence and JUnit results, and reran the four displacement controls. They found no blocking issues. The public-header audit verified unique declarations and umbrella coverage for 407 libraries and 30,931 exports.

The earlier contributor-reported 50-test production run and hosted checks apply to f16c9e062bd1d7607e1b3c976a6071904a81960c. Fresh current-main binaries, hosted production CI and collaborator re-review remain gates. Physical non-AVX hardware and title execution remain unverified.

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: #11689 (transitive #11661, #11628, #10518 and #10861)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5028353347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11698). Originally posted by [Felipebmaitan](https://github.com/Felipebmaitan) on 2026-10-27T03:59:20Z. --- ### What Replay bounded C4/C5 VEX guest GS memory moves through the protected Windows GS frame. The replay preserves effective addresses, native alignment and transfer widths, and upper YMM lane behavior. Unsupported encodings retain their own-length `UD2` fallback. Conversion and startup are host-AVX-independent. Reaching VEX replay without OS-enabled AVX state reports an illegal instruction at the original guest RIP with the stack and registers restored. This follow-up adds four cases for C4/C5 RIP-relative `VMOVDQU` loads borrowed by a short GS instruction, covering both 128-bit and 256-bit forms. It merges the published #11689 head `faf9d25c09f105a84ed01c3c9785651d9d989281`, which adds coverage for a borrowed EBX write feeding an SSE load or store through RBX. The candidate changes two Python tests relative to the previous published VEX head. [VEX increment over #11689](https://github.com/boykopovar/AnyPS5/compare/faf9d25c09f105a84ed01c3c9785651d9d989281...74746df3147c84663716e32f0fd7dc920cbe2ed8). This PR stays draft targeting main. The #11661 worker ended with its current-main integration unpublished, so the updated short replay and scalar replay-fault work are still pending in the published stack. The merge preview against main `c8f72e905cce039a05970ed39d2373f770217901` has inherited conflicts in the ELF reader, ELF bounds tests and libc/libkernel debt. #10518 and #10861 remain open. The shared entry-stub signatures with #15245 still need merge-order coordination. ### 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. --> On native Windows 11 Pro build 26300, x86-64 Ryzen 7 9800X3D, **79/79 focused tests passed** with the test scripts at `74746df3147c84663716e32f0fd7dc920cbe2ed8` and archived WinLibs GCC 15.2 Release binaries. Hashes for 774 archived relinker, libc, libkernel and build inputs matched the previous published VEX head `f16c9e062bd1d7607e1b3c976a6071904a81960c` after line-ending normalization. The run covered scalar and short GS replay, SSE and VEX faults and fallback, synthetic `--no-avx` and cached lookup, production-libc replay, executable and module startup, entry roots and bounds, relocations, TLS, deferred dependencies and sysarch/pthread. Both runners passed 81/81 VEX and 85/85 SSE address cases. Negative controls shifted the four new VEX replay displacements by one byte. Each failed the expected YMM-state assertion. Conventions passed against `origin/main` using both checker versions, and the diff whitespace check passed. The function-name overlap scan found no matching open implementations for the queried names. Existing shared-file and merge-order work remains documented above. One independent reviewer inspected `f16c9e062b..74746df314`, verified both published ancestors, checked the archived source correspondence and JUnit results, and reran the four displacement controls. They found no blocking issues. The public-header audit verified unique declarations and umbrella coverage for 407 libraries and 30,931 exports. The earlier contributor-reported 50-test production run and hosted checks apply to `f16c9e062bd1d7607e1b3c976a6071904a81960c`. Fresh current-main binaries, hosted production CI and collaborator re-review remain gates. Physical non-AVX hardware and title execution remain unverified. ### 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 --> #11689 (transitive #11661, #11628, #10518 and #10861) - [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:25 +00:00 (Migrated from github.com)

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

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 says "No PS5/title, performance, non-AVX-host or macOS verification is claimed", and the checklist has no title. Maintainers close PRs that cannot show a title reaching the change on main. Which title executes VEX-encoded %gs: accesses, and what log line on main (with the UD2 trap from the current fallback) shows it?

Stacked branch. This is 53 commits and 40 files, +2665, because it carries the prerequisite stack (#11624, #11628, #11661, #11689, plus the carried #11090/#11276 heads). The feature increment is one nine-file commit. Reviewers cannot approve the main-target diff as shown. Please keep it draft until the prerequisites merge, or retarget it onto the prerequisite branch.

AVX hosts. The description says non-AVX hosts were not verified. The converted Windows output now executes VEX instructions on the user's CPU. What does the relinker do when the host lacks AVX: refuse to convert, keep the UD2 trap, or emit code that faults at run time? That choice should be in the code and covered by a test, not left unverified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729922223 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11698#pullrequestreview-5729922223). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:25Z. **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 says "No PS5/title, performance, non-AVX-host or macOS verification is claimed", and the checklist has no title. Maintainers close PRs that cannot show a title reaching the change on main. Which title executes VEX-encoded `%gs:` accesses, and what log line on main (with the UD2 trap from the current fallback) shows it? **Stacked branch.** This is 53 commits and 40 files, +2665, because it carries the prerequisite stack (#11624, #11628, #11661, #11689, plus the carried #11090/#11276 heads). The feature increment is one nine-file commit. Reviewers cannot approve the main-target diff as shown. Please keep it draft until the prerequisites merge, or retarget it onto the prerequisite branch. **AVX hosts.** The description says non-AVX hosts were not verified. The converted Windows output now executes VEX instructions on the user's CPU. What does the relinker do when the host lacks AVX: refuse to convert, keep the UD2 trap, or emit code that faults at run time? That choice should be in the code and covered by a test, not left unverified.
MarcZX10 commented 2026-11-14 06:56:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T06:56:32Z.

Review: COMMENTED


Reviewed — no blocking findings

The pinned head is f16c9e062bd1d7607e1b3c976a6071904a81960c; the inspected paths show the advertised GS replay and startup wiring, but this review is incomplete, so approval is not justified.

What I ran

No commands or tests were run. The repository reader was used to inspect the prepared diff and source at the pinned head.

Results

Check Result Note
Prepared diff review passed Inspected selected runtime and relinker changes
Programmatic checks not run No test execution in this review

Findings

Blocking

None verified in the inspected code.

Non-blocking

None.

Not verified

The manifest lists 35 changed files, all marked included. I read the description, commits, manifest, changed-file listing, selected ranges of diff.patch, GuestGs.cpp, and WindowsGuestGs.cpp. I did not read every listed changed file or every changed hunk, including the full test suite, other runtime and entry-stub changes, and CMake changes. The author-reported Windows build and 50 focused test results were not independently verified. No checks were run.

To get this to a good state

Nothing is required. Optional: complete review of the remaining changed files and run the focused checks on this head before relying on the reported results.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5902454792 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11698#pullrequestreview-5902454792). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T06:56:32Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The pinned head is `f16c9e062bd1d7607e1b3c976a6071904a81960c`; the inspected paths show the advertised GS replay and startup wiring, but this review is incomplete, so approval is not justified. ## What I ran No commands or tests were run. The repository reader was used to inspect the prepared diff and source at the pinned head. ## Results | Check | Result | Note | |---|---|---| | Prepared diff review | passed | Inspected selected runtime and relinker changes | | Programmatic checks | not run | No test execution in this review | ## Findings ### Blocking None verified in the inspected code. ### Non-blocking None. ## Not verified The manifest lists 35 changed files, all marked included. I read the description, commits, manifest, changed-file listing, selected ranges of `diff.patch`, `GuestGs.cpp`, and `WindowsGuestGs.cpp`. I did not read every listed changed file or every changed hunk, including the full test suite, other runtime and entry-stub changes, and CMake changes. The author-reported Windows build and 50 focused test results were not independently verified. No checks were run. ## To get this to a good state Nothing is required. Optional: complete review of the remaining changed files and run the focused checks on this head before relying on the reported results.
MarcZX10 commented 2026-11-20 18:58:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T18:58:11Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: fix replay-table lookup so guest GS accesses after an earlier unsupported instruction are not silently skipped.

What I ran

Reviewed head 74746df3147c84663716e32f0fd7dc920cbe2ed8 from the prepared diff and pinned source using repo_read.py. No build or tests were run; the Windows 11 test results in the description are author-reported.

Results

Check Result Note
Diff and targeted source review passed Reviewed replay generation and runtime lookup
Tests in this review not run Author-reported runs are not independently verified

Findings

Blocking

  • core/libs/prx/libc/src/specifics/windows/GuestGs.cpp:196 — Find only accepts the trap address when it equals record + 29, but WindowsGuestGs::TryAppend emits each guest instruction’s trap at record + 24 (core/relinker/elfpatcher/src/windows/WindowsGuestGs.cpp:155). As written, the runtime never recognizes the generated UD2, so supported GS accesses always fall through as illegal instructions instead of replaying. Match the emitted trap offset (and keep the replay-address bounds consistent).

Non-blocking

None.

Not verified

  • No tests/build were run, so the reported Windows 11 results and physical-console behavior were not independently confirmed.
  • The prepared manifest lists all changed files as included. I read the description, commits, manifest, diff, and targeted runtime/emitter/builder sources; I did not read every changed file’s full text.

To get this to a good state

  • Correct the replay trap offset in Find, then rerun the focused GS replay tests, including VEX loads. I would rerun no commands on this head because no checks were run in this review.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5997878760 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11698#pullrequestreview-5997878760). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T18:58:11Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: fix replay-table lookup so guest GS accesses after an earlier unsupported instruction are not silently skipped. ## What I ran Reviewed head `74746df3147c84663716e32f0fd7dc920cbe2ed8` from the prepared diff and pinned source using `repo_read.py`. No build or tests were run; the Windows 11 test results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Reviewed replay generation and runtime lookup | | Tests in this review | not run | Author-reported runs are not independently verified | ## Findings ### Blocking - `core/libs/prx/libc/src/specifics/windows/GuestGs.cpp:196` — `Find` only accepts the trap address when it equals `record + 29`, but `WindowsGuestGs::TryAppend` emits each guest instruction’s trap at `record + 24` (`core/relinker/elfpatcher/src/windows/WindowsGuestGs.cpp:155`). As written, the runtime never recognizes the generated `UD2`, so supported GS accesses always fall through as illegal instructions instead of replaying. Match the emitted trap offset (and keep the replay-address bounds consistent). ### Non-blocking None. ## Not verified - No tests/build were run, so the reported Windows 11 results and physical-console behavior were not independently confirmed. - The prepared manifest lists all changed files as included. I read the description, commits, manifest, diff, and targeted runtime/emitter/builder sources; I did not read every changed file’s full text. ## To get this to a good state - Correct the replay trap offset in `Find`, then rerun the focused GS replay tests, including VEX loads. I would rerun no commands on this head because no checks were run in this review.
ligmaSec commented 2026-12-03 22:56:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:56:40Z.

Review: COMMENTED


The trial merge conflicts in ElfReader.cpp and ElfReaderBoundsTests.cpp. The VEX replay path should retain the native comparison for 128- and 256-bit moves, alignment faults, and upper YMM state. Please keep the host-feature-denial control too. Its conversion should still succeed without AVX and the guest instruction should take its documented fallback at execution. Please use debt fragments for the three library and relinker changes. I reviewed this in source and did not run native Windows tests.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6180103658 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11698#pullrequestreview-6180103658). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:56:40Z. **Review:** COMMENTED --- The trial merge conflicts in `ElfReader.cpp` and `ElfReaderBoundsTests.cpp`. The VEX replay path should retain the native comparison for 128- and 256-bit moves, alignment faults, and upper YMM state. Please keep the host-feature-denial control too. Its conversion should still succeed without AVX and the guest instruction should take its documented fallback at execution. Please use debt fragments for the three library and relinker changes. I reviewed this in source and did not run native Windows tests. AI-assisted: yes.
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/11698:upstream-pr/11698'
git switch 'upstream-pr/11698'

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