feat(relinker): support short scalar guest GS instructions #11661

Open
Felipebmaitan wants to merge 41 commits from upstream-pr/11661 into main
Felipebmaitan commented 2026-10-27 01:28:20 +00:00 (Migrated from github.com)

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


What

Support three- and four-byte scalar GS instructions by borrowing complete, safe neighboring instructions for the jump. Relocate supported followers, preserve original fault locations, and avoid replaying the completed GS operation when a repaired follower resumes. Unsafe borrowed spans keep the reviewed own-length UD2 fallback and leave following bytes untouched.

Refreshed bottom-up onto main 4138defef7c468835190768e5143e411bce92d6a, preserving every published November head and maintainer commit. Retains GS entry guards, original fault/resume behavior, unsupported-form fallback, deferred dependency controls, RELRO protection records and power-of-two alignment validation.

The full native Windows build exposed a GS runtime-fixture link conflict: relinker static C++ exception symbols collided with libc exports. The libc-linked fixture targets now have a scoped CMake directory that follows the production library exception/link policy.

Increment over #11628: github.com/boykopovar/[email protected]. This PR stays draft targeting main until prerequisites and external review gates are satisfied.

Tested

Fresh native Windows evidence at exact head b813f34cfbbadc2d73e879b1e973491add56377c: Windows 11 Pro build 26300, x86-64 Ryzen 7 9800X3D, WinLibs GCC 15.2, Release, Ninja, at most two build/test jobs. Full project CMake configuration succeeds using isolated immutable source exports with the pinned submodules, including MbedTLS framework ced31491c5ec907a6be533512f19dc1779230ac1. Complete libc/libkernel targets and the relevant runtime/relinker test targets build through normal project CMake. 25/25 focused production/relinker tests pass, including thread/sysarch tests, native GS replay, production-libc execution, emitted executable/module startup, entry bounds/roots, RELRO and deferred dependencies. The complete graphics/media library set and GPU suite were not built or run.

Conventions against origin/main and diff whitespace checks pass. Public-header audit: 407 libraries and 30,931 exports pass. The full scalar relinker-only suite also passed 246/246 at integration commit 1cd120090b3150edbc1a8be834d84851bca61bd4, before the fixture link-policy fix. Earlier macOS, translated Linux and ARM64 Windows results remain historical at the revisions in the November 5 evidence; they are not relabeled as testing this head.

The overlap scan ran across 1,768 open PRs and failed closed for 82 conflicting/stale peers. Direct shared-path patches were inspected (the first scan had 19 source peers and 64 documentation-only peers; the final scan resolved #10861 to a debt-only overlap); no competing GS implementation was found. Known merge-order/integration work remains: declared #10518 and separately owned #10861, and shared entry-stub API lines with #15245. #15345 adds independent covered-SCE-RELRO range checks. No peer implementation was imported or author agreement/combined runtime validation claimed. Proposed #15245 coordination: retain both GS runtime setup and executable-export/module arguments when resolving the shared signatures/call site; agree merge order before either lands.

Main advanced after the pinned refresh; later upstream commits are not covered by these local results. Fresh collaborator re-review and required hosted production checks remain gates. A fresh selected-chain workflow dispatch after publication returned HTTP 403: admin rights required; a collaborator must dispatch gh workflow run build.yml --repo boykopovar/AnyPS5 --ref main --field pr="11628 11661 11689 11698" --field full=true --field select=true. No PS5/title, physical non-AVX or performance verification is claimed. No paired performance captures are required or invented for this PR's absent speed claim.

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: #11628 (transitive #10518)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5027176619 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11661). Originally posted by [Felipebmaitan](https://github.com/Felipebmaitan) on 2026-10-27T01:28:20Z. --- ### What Support three- and four-byte scalar GS instructions by borrowing complete, safe neighboring instructions for the jump. Relocate supported followers, preserve original fault locations, and avoid replaying the completed GS operation when a repaired follower resumes. Unsafe borrowed spans keep the reviewed own-length UD2 fallback and leave following bytes untouched. Refreshed bottom-up onto main `4138defef7c468835190768e5143e411bce92d6a`, preserving every published November head and maintainer commit. Retains GS entry guards, original fault/resume behavior, unsupported-form fallback, deferred dependency controls, RELRO protection records and power-of-two alignment validation. The full native Windows build exposed a GS runtime-fixture link conflict: relinker static C++ exception symbols collided with libc exports. The libc-linked fixture targets now have a scoped CMake directory that follows the production library exception/link policy. Increment over #11628: https://github.com/boykopovar/AnyPS5/compare/f013da972573fa4dfca95607f2462501d6ad2234...b813f34cfbbadc2d73e879b1e973491add56377c. This PR stays draft targeting main until prerequisites and external review gates are satisfied. ### Tested Fresh native Windows evidence at exact head `b813f34cfbbadc2d73e879b1e973491add56377c`: Windows 11 Pro build 26300, x86-64 Ryzen 7 9800X3D, WinLibs GCC 15.2, Release, Ninja, at most two build/test jobs. Full project CMake configuration succeeds using isolated immutable source exports with the pinned submodules, including MbedTLS framework `ced31491c5ec907a6be533512f19dc1779230ac1`. Complete libc/libkernel targets and the relevant runtime/relinker test targets build through normal project CMake. **25/25 focused production/relinker tests pass**, including thread/sysarch tests, native GS replay, production-libc execution, emitted executable/module startup, entry bounds/roots, RELRO and deferred dependencies. The complete graphics/media library set and GPU suite were not built or run. Conventions against origin/main and diff whitespace checks pass. Public-header audit: 407 libraries and 30,931 exports pass. The full scalar relinker-only suite also passed 246/246 at integration commit `1cd120090b3150edbc1a8be834d84851bca61bd4`, before the fixture link-policy fix. Earlier macOS, translated Linux and ARM64 Windows results remain historical at the revisions in the [November 5 evidence](https://github.com/boykopovar/AnyPS5/pull/11698#issuecomment-6656983673); they are not relabeled as testing this head. The overlap scan ran across 1,768 open PRs and failed closed for 82 conflicting/stale peers. Direct shared-path patches were inspected (the first scan had 19 source peers and 64 documentation-only peers; the final scan resolved #10861 to a debt-only overlap); no competing GS implementation was found. Known merge-order/integration work remains: declared #10518 and separately owned #10861, and shared entry-stub API lines with #15245. #15345 adds independent covered-SCE-RELRO range checks. No peer implementation was imported or author agreement/combined runtime validation claimed. Proposed #15245 coordination: retain both GS runtime setup and executable-export/module arguments when resolving the shared signatures/call site; agree merge order before either lands. Main advanced after the pinned refresh; later upstream commits are not covered by these local results. Fresh collaborator re-review and required hosted production checks remain gates. A fresh selected-chain workflow dispatch after publication returned HTTP 403: admin rights required; a collaborator must dispatch `gh workflow run build.yml --repo boykopovar/AnyPS5 --ref main --field pr="11628 11661 11689 11698" --field full=true --field select=true`. No PS5/title, physical non-AVX or performance verification is claimed. No paired performance captures are required or invented for this PR's absent speed claim. <!-- 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. --> ### 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) - [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 --> #11628 (transitive #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
MarcZX10 commented 2026-10-27 01:35:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T01:35:45Z.

Review: CHANGES_REQUESTED


The code and test review of the incremental #11628..#11661 changes did not find a confirmed defect. I cannot approve the performance claim/evaluation without the required paired captures, though.

Please provide all of the following from the same title, scene, and machine:

  • The aps5-summary.jsonl line for main and the line for this change.
  • Both trace files attached to the PR.
  • The output of python3 tools/trace_digest.py <trace> for each trace.

The current PR description reports synthetic relinker/runtime correctness tests, but contains no performance captures or digest output. Until this evidence is available, the performance impact is unverified. At the time of review, conventions, intake, eligibility, Ubuntu relinker, ASan, register-context and macOS write-watch checks passed; Windows relinker and several macOS jobs were still pending. This review covers the incremental changes after #11628; the prerequisite remains independently reviewable.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661252630 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11661#pullrequestreview-5661252630). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T01:35:45Z. **Review:** CHANGES_REQUESTED --- The code and test review of the incremental #11628..#11661 changes did not find a confirmed defect. I cannot approve the performance claim/evaluation without the required paired captures, though. Please provide all of the following from the same title, scene, and machine: - The `aps5-summary.jsonl` line for `main` and the line for this change. - Both trace files attached to the PR. - The output of `python3 tools/trace_digest.py <trace>` for each trace. The current PR description reports synthetic relinker/runtime correctness tests, but contains no performance captures or digest output. Until this evidence is available, the performance impact is unverified. At the time of review, conventions, intake, eligibility, Ubuntu relinker, ASan, register-context and macOS write-watch checks passed; Windows relinker and several macOS jobs were still pending. This review covers the incremental changes after #11628; the prerequisite remains independently reviewable.
MarcZX10 commented 2026-10-29 07:49:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T07:49:57Z.

Review: CHANGES_REQUESTED


Re-review — changes requested

A blocking global exception-path cost remains in the Windows continuation handling.

What I checked

  • Reviewed head 339b7e0fd9bafe4bccbebb27777bb05752534b46 and its Windows call chain in CrashReport.cpp and GuestGs.cpp.
  • Confirmed the hosted Windows, Linux/macOS relinker, sanitizer, and conventions jobs pass for this head. Linux product CI is skipped.
  • I did not run a local Windows/title performance test.

Finding

[P1] Keep PE discovery off the process-wide first-chance exception path

CrashReport.cpp installs ReportCrash as a first-chance vectored exception handler. It calls GuestGsHandleException_nid_no_patch for each exception. In this head, that function calls MovedAddress(context.Rip, false) before checking whether the exception is EXCEPTION_ILLEGAL_INSTRUCTION. MovedAddress calls Section, which performs VirtualQuery, reads PE headers with ReadProcessMemory, and scans section headers. The continuation handler similarly calls MovedAddress for exceptions that continue.

This makes ordinary exceptions in every process pay image-discovery and process-memory-read costs even when no GS replay or moved guest image is involved. The correctness tests and passing CI do not measure that system-wide runtime cost. The earlier paired-title-capture request is resolved because the PR now explicitly makes no performance claim; this is a separate regression risk introduced by the global handler.

Please add a cheap path that avoids PE discovery when the current image cannot have registered GS/moved-image metadata, and avoid installing the continuation handler for processes that do not need it. If the intended behavior requires the global handler, provide a representative exception-heavy title measurement against the same main build and show the overhead is acceptable. Keep the existing replay/fault tests passing.

Not verified

No local Windows build, GPU run, console/title run, or exception-heavy performance measurement was performed in this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5694403836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11661#pullrequestreview-5694403836). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T07:49:57Z. **Review:** CHANGES_REQUESTED --- # Re-review — changes requested A blocking global exception-path cost remains in the Windows continuation handling. ## What I checked - Reviewed head `339b7e0fd9bafe4bccbebb27777bb05752534b46` and its Windows call chain in `CrashReport.cpp` and `GuestGs.cpp`. - Confirmed the hosted Windows, Linux/macOS relinker, sanitizer, and conventions jobs pass for this head. Linux product CI is skipped. - I did not run a local Windows/title performance test. ## Finding ### [P1] Keep PE discovery off the process-wide first-chance exception path `CrashReport.cpp` installs `ReportCrash` as a first-chance vectored exception handler. It calls `GuestGsHandleException_nid_no_patch` for each exception. In this head, that function calls `MovedAddress(context.Rip, false)` before checking whether the exception is `EXCEPTION_ILLEGAL_INSTRUCTION`. `MovedAddress` calls `Section`, which performs `VirtualQuery`, reads PE headers with `ReadProcessMemory`, and scans section headers. The continuation handler similarly calls `MovedAddress` for exceptions that continue. This makes ordinary exceptions in every process pay image-discovery and process-memory-read costs even when no GS replay or moved guest image is involved. The correctness tests and passing CI do not measure that system-wide runtime cost. The earlier paired-title-capture request is resolved because the PR now explicitly makes no performance claim; this is a separate regression risk introduced by the global handler. Please add a cheap path that avoids PE discovery when the current image cannot have registered GS/moved-image metadata, and avoid installing the continuation handler for processes that do not need it. If the intended behavior requires the global handler, provide a representative exception-heavy title measurement against the same main build and show the overhead is acceptable. Keep the existing replay/fault tests passing. ## Not verified No local Windows build, GPU run, console/title run, or exception-heavy performance measurement was performed in this review.
CnRJay commented 2026-11-01 19:49:27 +00:00 (Migrated from github.com)

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

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 body claims synthetic ISA and emitted-program fixtures only, with no title run. Maintainers close PRs that cannot name a title and show a log line from main that reaches the change. Which title hits a short scalar %gs: instruction today, and what does main print?

Stacked branch. 33 commits and 36 files (+1769) because it carries #11624, #11628 and the #11090/#11276 prerequisite heads. #11689 and #11698 stack on this in turn, so the same diff is being reviewed up to four times. Please keep this draft until #11628 merges, or retarget it onto that branch so the diff shows only the short-instruction increment.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729922323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11661#pullrequestreview-5729922323). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:27Z. **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 body claims synthetic ISA and emitted-program fixtures only, with no title run. Maintainers close PRs that cannot name a title and show a log line from main that reaches the change. Which title hits a short scalar `%gs:` instruction today, and what does main print? **Stacked branch.** 33 commits and 36 files (+1769) because it carries #11624, #11628 and the #11090/#11276 prerequisite heads. #11689 and #11698 stack on this in turn, so the same diff is being reviewed up to four times. Please keep this draft until #11628 merges, or retarget it onto that branch so the diff shows only the short-instruction increment.
MarcZX10 commented 2026-11-14 06:57:18 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — comments

The core GS replay and relocation paths were inspected at head b813f34cfbbadc2d73e879b1e973491add56377c; the review is incomplete because not every changed file was read.

What I ran

Used the repo_read.py review reader to inspect the prepared description, commit list, manifest, diff, and selected repository files at the pinned head. No build or tests were run in this review.

Results

Check Result Note
Prepared change and selected code passed Reviewed GS runtime and relinker paths
Build and tests not run Author-reported results were not independently verified
Complete changed-file review not run Several changed files were not read

Findings

Blocking

None verified in the code inspected.

Non-blocking

None.

Not verified

The full text of changed files was available through the reader, but I read only selected portions. In particular, I did not inspect all changed test, build, loader, and documentation files, so their behavior and coverage are not verified. No tests were run; the Windows build and test results in the PR description are author-reported.

To get this to a good state

Nothing is required. Optional: complete review of the remaining changed files and independently run the relevant checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5902457035 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11661#pullrequestreview-5902457035). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T06:57:18Z. **Review:** COMMENTED --- # Reviewed — comments The core GS replay and relocation paths were inspected at head `b813f34cfbbadc2d73e879b1e973491add56377c`; the review is incomplete because not every changed file was read. ## What I ran Used the `repo_read.py` review reader to inspect the prepared description, commit list, manifest, diff, and selected repository files at the pinned head. No build or tests were run in this review. ## Results | Check | Result | Note | |---|---|---| | Prepared change and selected code | passed | Reviewed GS runtime and relinker paths | | Build and tests | not run | Author-reported results were not independently verified | | Complete changed-file review | not run | Several changed files were not read | ## Findings ### Blocking None verified in the code inspected. ### Non-blocking None. ## Not verified The full text of changed files was available through the reader, but I read only selected portions. In particular, I did not inspect all changed test, build, loader, and documentation files, so their behavior and coverage are not verified. No tests were run; the Windows build and test results in the PR description are author-reported. ## To get this to a good state Nothing is required. Optional: complete review of the remaining changed files and independently run the relevant checks.
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/11661:upstream-pr/11661'
git switch 'upstream-pr/11661'

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