fix(relinker): do not take instructions another AMD-only stub moved as a short instruction's followers #8001

Merged
mopga merged 1 commit from upstream-pr/8001 into main 2026-10-20 17:30:39 +00:00
mopga commented 2026-10-19 17:15:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mopga on 2026-10-19T17:15:48Z.


What

A short AMD-only instruction takes the following instructions into its stub until its site fits a jump. That loop did not check which instructions an earlier 256-bit store island had already claimed, so with --to-rosetta two trampolines could cover the same bytes.

Reproduced with relinker --to-rosetta on current main (je to the RCPPS, jmp over nothing, vmovups [rdi],ymm0, rcpps xmm1,xmm2, four add rax,rcx, padding, ret):

74 06 EB 00 C5 FC 11 07 0F 53 CA 48 01 C8 ×4 90 ×8 C3

The store's forward window is blocked by the branch target and its backward window by the jmp, so it is lowered through an island that claims the adds. RCPPS then took the same adds as its followers: the converter returned trampolines at +8 (6 bytes) and +11 (6 bytes), and the conversion failed with AMD-only site bytes changed before patching (offset 0x1008). With RDPID (F3 0F C7 F8) instead of RCPPS the result is the same.

A claimed follower now ends the attempt: an optional instruction such as RCPPS, RSQRTPS, RDPID or RDTSCP is kept, and any other instruction fails with an error naming the moved follower instead of producing overlapping sites.

Tested

Windows 11, AMD Ryzen 7 7800X3D (Zen 4), MinGW-w64 GCC 15.2.0 (WinLibs r7), relinker-only build of this branch on current main:

  • New converterClaimedFollower in Amd64OnlyConverterTests.cpp (RCPPS and RDPID variants; no two trampolines overlap and the short instruction is kept) fails on main with overlapping sites and passes with the fix.
  • Both sequences convert with relinker --to-rosetta.
  • Differential run on this AMD host: the converted code matches native execution (all GPRs, flags, YMM registers, memory and stack) for 200 random register states for both variants; on main the converted code crashes.
  • ctest: 211/211 passed.
  • python3 tools/check_conventions.py --base origin/main passes. A trial merge with the open PRs that change these files (#2780, #7363, #7651, #7660) shows no conflict caused by this change; it also merges cleanly with #7999, which changes the same test file.

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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4924651874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8001). Originally posted by [mopga](https://github.com/mopga) on 2026-10-19T17:15:48Z. --- ### What A short AMD-only instruction takes the following instructions into its stub until its site fits a jump. That loop did not check which instructions an earlier 256-bit store island had already claimed, so with `--to-rosetta` two trampolines could cover the same bytes. Reproduced with `relinker --to-rosetta` on current `main` (`je` to the RCPPS, `jmp` over nothing, `vmovups [rdi],ymm0`, `rcpps xmm1,xmm2`, four `add rax,rcx`, padding, `ret`): `74 06 EB 00 C5 FC 11 07 0F 53 CA 48 01 C8 ×4 90 ×8 C3` The store's forward window is blocked by the branch target and its backward window by the `jmp`, so it is lowered through an island that claims the adds. RCPPS then took the same adds as its followers: the converter returned trampolines at +8 (6 bytes) and +11 (6 bytes), and the conversion failed with `AMD-only site bytes changed before patching (offset 0x1008)`. With RDPID (`F3 0F C7 F8`) instead of RCPPS the result is the same. A claimed follower now ends the attempt: an optional instruction such as RCPPS, RSQRTPS, RDPID or RDTSCP is kept, and any other instruction fails with an error naming the moved follower instead of producing overlapping sites. ### Tested Windows 11, AMD Ryzen 7 7800X3D (Zen 4), MinGW-w64 GCC 15.2.0 (WinLibs r7), relinker-only build of this branch on current `main`: - New `converterClaimedFollower` in `Amd64OnlyConverterTests.cpp` (RCPPS and RDPID variants; no two trampolines overlap and the short instruction is kept) fails on `main` with overlapping sites and passes with the fix. - Both sequences convert with `relinker --to-rosetta`. - Differential run on this AMD host: the converted code matches native execution (all GPRs, flags, YMM registers, memory and stack) for 200 random register states for both variants; on `main` the converted code crashes. - `ctest`: 211/211 passed. - `python3 tools/check_conventions.py --base origin/main` passes. A trial merge with the open PRs that change these files (#2780, #7363, #7651, #7660) shows no conflict caused by this change; it also merges cleanly with #7999, which changes the same test file. ### 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](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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
wachi35676 commented 2026-10-19 23:18:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T23:18:01Z.


Verdict: confirmed on Windows and Linux, and it works together with #7999.

Environment: Windows 11 Home 10.0.26300, Ryzen 5 9600X (Zen 5), WinLibs GCC 15.2.0 r7, relinker-only Release build. This PR was merged onto main 9127ea36d, alone and together with #7999.

  • Reproduction through the CLI: both of your sequences as the body of a test_tls_function_coverage.py make_image image, converted with relinker --skip-sce-module --to-rosetta. The RCPPS one is 74 06 eb 00 c5 fc 11 07 0f 53 ca (48 01 c8)x4 (90)x8 c3.
    • main: rc 2, Intel conversion: 0 in place, 3 stubs, 0 kept, FAIL: AMD-only site bytes changed before patching (offset 0x1248), for both RCPPS and RDPID.
    • This PR: rc 0, 2 stubs, 1 kept, for both.
  • Negative control: with only Amd64OnlyConverter.cpp reverted to main, amd64_only_converter_tests fails with A short instruction's site overlaps instructions another stub already moved.
  • ctest:
    • Windows: 212/212. Three tests that timed out under -j4 because of host load, and also do so on main, passed on a serial rerun.
    • WSL Ubuntu 24.04, GCC 13.3: 216/217. The one failure, shader_cache_runtime_sources, fails intermittently on main too.
  • With #7999 merged as well, the build merges cleanly and passes Windows 212/212 and WSL 217/217. In the combined build, your two cases are kept and the six in-place-follower cases from #7999 convert. #7999 changes MatchSequence and this PR adds the claimed check in the follower loop of _convertSegment. An in-place follower that #7999 moves into the stub goes into taken/consumed, not claimed, so the two changes don't interact.
  • Homebrew: PS5 OpenGL Showcase 1.0.2 (PPSA99005), PPSA47402, PS5LM Plus 0.8.4 (PPSA99581), and Prospero Win v0.2.0 (PPSA99995) with its 16 Wine modules. I relinked them with --windows --to-intel, --macos --to-rosetta and Linux --to-intel. These conversions produce real stubs: 1/5/22/0 under --to-intel and 4495/16745/51131/192 under --to-rosetta, for PPSA47402/PPSA99005/PPSA99581/PPSA99995 respectively, with 0 kept. All 12 output sets are byte-identical to main, both with this PR alone and combined with #7999. None of these stubs hit the claimed-follower case.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279479813 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8001#issuecomment-6279479813). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-19T23:18:01Z. --- Verdict: confirmed on Windows and Linux, and it works together with #7999. Environment: Windows 11 Home 10.0.26300, Ryzen 5 9600X (Zen 5), WinLibs GCC 15.2.0 r7, relinker-only Release build. This PR was merged onto `main` 9127ea36d, alone and together with #7999. - Reproduction through the CLI: both of your sequences as the body of a `test_tls_function_coverage.py` `make_image` image, converted with `relinker --skip-sce-module --to-rosetta`. The RCPPS one is `74 06 eb 00 c5 fc 11 07 0f 53 ca (48 01 c8)x4 (90)x8 c3`. - `main`: rc 2, `Intel conversion: 0 in place, 3 stubs, 0 kept`, `FAIL: AMD-only site bytes changed before patching (offset 0x1248)`, for both RCPPS and RDPID. - This PR: rc 0, `2 stubs, 1 kept`, for both. - Negative control: with only `Amd64OnlyConverter.cpp` reverted to `main`, `amd64_only_converter_tests` fails with `A short instruction's site overlaps instructions another stub already moved`. - `ctest`: - Windows: 212/212. Three tests that timed out under `-j4` because of host load, and also do so on `main`, passed on a serial rerun. - WSL Ubuntu 24.04, GCC 13.3: 216/217. The one failure, `shader_cache_runtime_sources`, fails intermittently on `main` too. - With #7999 merged as well, the build merges cleanly and passes Windows 212/212 and WSL 217/217. In the combined build, your two cases are kept and the six in-place-follower cases from #7999 convert. #7999 changes `MatchSequence` and this PR adds the `claimed` check in the follower loop of `_convertSegment`. An in-place follower that #7999 moves into the stub goes into `taken`/`consumed`, not `claimed`, so the two changes don't interact. - Homebrew: PS5 OpenGL Showcase 1.0.2 (PPSA99005), PPSA47402, PS5LM Plus 0.8.4 (PPSA99581), and Prospero Win v0.2.0 (PPSA99995) with its 16 Wine modules. I relinked them with `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`. These conversions produce real stubs: 1/5/22/0 under `--to-intel` and 4495/16745/51131/192 under `--to-rosetta`, for PPSA47402/PPSA99005/PPSA99581/PPSA99995 respectively, with 0 kept. All 12 output sets are byte-identical to `main`, both with this PR alone and combined with #7999. None of these stubs hit the claimed-follower case. AI-assisted: yes (Claude Code); results above were run on this machine.
github-actions[bot] commented 2026-10-20 11:24:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T11:24:02Z.


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 8042 core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289752379 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8001#issuecomment-6289752379). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T11:24:02Z. --- <!-- 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 8042](https://www.github.com/boykopovar/AnyPS5/pull/8042) | `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!8001
No description provided.