test(relinker): execute the in-place Rosetta replacements #8236

Merged
javierUDP merged 3 commits from upstream-pr/8236 into main 2026-10-26 08:59:05 +00:00
javierUDP commented 2026-10-20 05:22:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-20T05:22:39Z.


What

The --to-rosetta replacements for RDPID, RDSEED and CLWB are checked through their bytes, but none of them is ever executed, while the SSE4A, SHA, CLZERO, reciprocal, RDPRU, MCOMMIT and RDTSCP stubs are. All three of these raise an illegal instruction on a Rosetta host, which is the reason the replacements exist, so running them is what shows they stand in correctly.

The execution section now calls each one and checks what it leaves behind:

  • RDPID: the stub returns 0 in the destination register and does not disturb the flags.
  • RDSEED: the replacement is the same length, reports a value through the carry flag, and is retried up to 16 times so a transient RDRAND failure cannot make the test flaky.
  • CLWB: the replacement is the same length, leaves its address register and an unrelated register untouched, and does not disturb the flags.

Tested

Apple M5, macOS 26.4, AppleClang 21.0.0, relinker-only build of current main.

  • -DCMAKE_OSX_ARCHITECTURES=x86_64, executed under Rosetta: 209/209, with the three new checks running.
  • Native arm64: 209/209; the section is x86-64 only and stays out of the build.
  • Control: inverting each new assertion fails the run with that assertion's message, so the stubs really execute rather than being skipped. Reverting them restores the pass.
  • Measured on this host, for context: RDPID, RDSEED and CLWB each die with SIGILL when executed directly under Rosetta, while RDRAND and the NOP that replaces CLWB run.
  • python3 tools/check_conventions.py --base origin/main passes.

No Linux or Windows host was available; the section also builds there and the checks are host-independent.

#7999 moves in-place AMD-only replacements into a short instruction window and touches the same file. These checks exercise that path rather than change it, so there is no functional dependency either way.

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: n/a, test-only change
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: n/a
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4931398937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8236). Originally posted by [javierUDP](https://github.com/javierUDP) on 2026-10-20T05:22:39Z. --- ### What The `--to-rosetta` replacements for RDPID, RDSEED and CLWB are checked through their bytes, but none of them is ever executed, while the SSE4A, SHA, CLZERO, reciprocal, RDPRU, MCOMMIT and RDTSCP stubs are. All three of these raise an illegal instruction on a Rosetta host, which is the reason the replacements exist, so running them is what shows they stand in correctly. The execution section now calls each one and checks what it leaves behind: - RDPID: the stub returns 0 in the destination register and does not disturb the flags. - RDSEED: the replacement is the same length, reports a value through the carry flag, and is retried up to 16 times so a transient RDRAND failure cannot make the test flaky. - CLWB: the replacement is the same length, leaves its address register and an unrelated register untouched, and does not disturb the flags. ### Tested Apple M5, macOS 26.4, AppleClang 21.0.0, relinker-only build of current `main`. - `-DCMAKE_OSX_ARCHITECTURES=x86_64`, executed under Rosetta: 209/209, with the three new checks running. - Native arm64: 209/209; the section is x86-64 only and stays out of the build. - Control: inverting each new assertion fails the run with that assertion's message, so the stubs really execute rather than being skipped. Reverting them restores the pass. - Measured on this host, for context: RDPID, RDSEED and CLWB each die with SIGILL when executed directly under Rosetta, while RDRAND and the NOP that replaces CLWB run. - `python3 tools/check_conventions.py --base origin/main` passes. No Linux or Windows host was available; the section also builds there and the checks are host-independent. #7999 moves in-place AMD-only replacements into a short instruction window and touches the same file. These checks exercise that path rather than change it, so there is no functional dependency either way. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file: n/a, test-only change - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: n/a - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
javierUDP commented 2026-10-20 06:19:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-20T06:19:49Z.


On the overlap notice: #7918 does not merge into main on its own. Merged into main 1ed63f63c by itself it conflicts in core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp, the same file the notice lists, so the conflict is between that pull request and main rather than with this one, and it needs a rebase either way.

This branch only appends three functions to the x86-64 execution section of that file and three calls in main(), so once #7918 is rebased the two should compose without touching the same lines.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284759648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8236#issuecomment-6284759648). Originally posted by [javierUDP](https://github.com/javierUDP) on 2026-10-20T06:19:49Z. --- On the overlap notice: #7918 does not merge into `main` on its own. Merged into `main` `1ed63f63c` by itself it conflicts in `core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp`, the same file the notice lists, so the conflict is between that pull request and `main` rather than with this one, and it needs a rebase either way. This branch only appends three functions to the x86-64 execution section of that file and three calls in `main()`, so once #7918 is rebased the two should compose without touching the same lines.
fogydes commented 2026-10-20 07:32:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-20T07:32:29Z.

Review: COMMENTED


Reviewed the diff and CI results.

Code: Adds execution tests for three Rosetta in-place replacements that were previously only checked through byte comparison:

  • RDPID: maps the stub into executable memory, calls it, verifies the destination register receives 0 and the flags are preserved (CF checked via stc + setc). Correct — the trampoline stub for RDPID returns processor 0 as documented.
  • RDSEED: verifies the replacement has the same byte length as the original, executes it, and retries up to 16 times to account for transient RDRAND failures. The carry-flag check (produced = carry == 1) is the right way to detect a valid seed value.
  • CLWB: verifies same-length replacement, executes it, and checks that both the address register and an unrelated register (rbx = 0x5A...) are preserved, plus flags unchanged. Correct — CLWB should be a no-op from the caller's perspective.

All three follow the established pattern from rdtscpExecution() / mcommitExecution() above: mmap executable page, copy stub, inline asm call with sub $128, %%rsp for red-zone, check results, munmap.

The non-x86-64 stubs (void rdpidExecution() {} etc.) are correctly added in the #else branch to keep the test compilable on all platforms.

CI: All green — conventions, intake, labels, eligibility pass. The relinker tests themselves pass on all four platform/compiler combinations: macOS ARM64, macOS x86_64 (Rosetta — where these stubs are actually exercised), Ubuntu g++, and Windows g++.

PR body: Complete template, honest about the host used (Apple M5 under Rosetta). Notes the overlap with #7999 and correctly explains why there's no functional dependency.

No issues found. Well-structured test addition that fills a real coverage gap.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5582015380 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8236#pullrequestreview-5582015380). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-20T07:32:29Z. **Review:** COMMENTED --- Reviewed the diff and CI results. **Code**: Adds execution tests for three Rosetta in-place replacements that were previously only checked through byte comparison: - **RDPID**: maps the stub into executable memory, calls it, verifies the destination register receives 0 and the flags are preserved (CF checked via `stc` + `setc`). Correct — the trampoline stub for RDPID returns processor 0 as documented. - **RDSEED**: verifies the replacement has the same byte length as the original, executes it, and retries up to 16 times to account for transient RDRAND failures. The carry-flag check (`produced = carry == 1`) is the right way to detect a valid seed value. - **CLWB**: verifies same-length replacement, executes it, and checks that both the address register and an unrelated register (`rbx` = `0x5A...`) are preserved, plus flags unchanged. Correct — CLWB should be a no-op from the caller's perspective. All three follow the established pattern from `rdtscpExecution()` / `mcommitExecution()` above: mmap executable page, copy stub, inline asm call with `sub $128, %%rsp` for red-zone, check results, munmap. The non-x86-64 stubs (`void rdpidExecution() {}` etc.) are correctly added in the `#else` branch to keep the test compilable on all platforms. **CI**: All green — `conventions`, `intake`, `labels`, `eligibility` pass. The relinker tests themselves pass on all four platform/compiler combinations: macOS ARM64, macOS x86_64 (Rosetta — where these stubs are actually exercised), Ubuntu g++, and Windows g++. **PR body**: Complete template, honest about the host used (Apple M5 under Rosetta). Notes the overlap with #7999 and correctly explains why there's no functional dependency. No issues found. Well-structured test addition that fills a real coverage gap.
jotitadev commented 2026-10-21 21:34:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T21:34:23Z.

Review: COMMENTED


Independent run on Apple silicon under Rosetta 2, which the thread had not covered yet.

Apple M2 Max, macOS 27.2 (26B5091g), Apple clang, CMake 4.4.4, Ninja, relinker-only Release build. Head d5886fce8 merged onto current main 0c6a5bd59 (clean). Built arm64 and x86-64 (-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3, Python 3.9.6).

  • x86-64 under Rosetta: amd64_only_converter passes. The three new execution tests run the converted in-place replacements as real code: RDPID leaves processor 0 in RAX and keeps the carry flag set, RDSEED reports a random value (CF set) within the 16 attempts, and CLWB is a no-op that leaves its address register, an unrelated register and the flags unchanged.
  • arm64: the same test compiles (the executions are __x86_64__-only no-ops there) and amd64_only_converter passes.
  • No production code changes, so the tests also pass on main; this is the added execution coverage running on an Apple host under Rosetta.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5606524954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8236#pullrequestreview-5606524954). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-21T21:34:23Z. **Review:** COMMENTED --- Independent run on Apple silicon under Rosetta 2, which the thread had not covered yet. Apple M2 Max, macOS 27.2 (26B5091g), Apple clang, CMake 4.4.4, Ninja, relinker-only Release build. Head `d5886fce8` merged onto current main `0c6a5bd59` (clean). Built arm64 and x86-64 (`-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3`, Python 3.9.6). - x86-64 under Rosetta: `amd64_only_converter` passes. The three new execution tests run the converted in-place replacements as real code: RDPID leaves processor 0 in RAX and keeps the carry flag set, RDSEED reports a random value (CF set) within the 16 attempts, and CLWB is a no-op that leaves its address register, an unrelated register and the flags unchanged. - arm64: the same test compiles (the executions are `__x86_64__`-only no-ops there) and `amd64_only_converter` passes. - No production code changes, so the tests also pass on `main`; this is the added execution coverage running on an Apple host under Rosetta. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
THEMANnt commented 2026-10-26 03:53:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T03:53:51Z.

Review: APPROVED


Re-reviewed e27a9d3e01e51eb1cc549ba80ba1b2f1b356c83a. Approve; the earlier blocker is resolved.

The earlier merge-conflict blocker is cleared. Reviewed the complete current test-only patch: RDPID and CLWB checks verify relevant register/flag preservation, RDSEED checks the replacement length and bounded success, and inline calls protect the red zone. The new execution bodies remain guarded for Linux/macOS x86-64.

Validation: The exact current file compiles in C++23 with current matching relinker headers. Hosted Build 40256933244 logs show amd64_only_converter passes on Ubuntu (job 121360738660) and macOS x86-64 (job 121360738706); the respective full relinker CTest runs report 309 and 299 tests passing. Current Conventions passes.

Scope: Local Windows syntax does not execute the guarded bodies; execution evidence comes from the hosted merged-PR jobs. No game/performance or broad CPU-feature portability claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5647167057 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8236#pullrequestreview-5647167057). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T03:53:51Z. **Review:** APPROVED --- Re-reviewed `e27a9d3e01e51eb1cc549ba80ba1b2f1b356c83a`. Approve; the earlier blocker is resolved. The earlier merge-conflict blocker is cleared. Reviewed the complete current test-only patch: RDPID and CLWB checks verify relevant register/flag preservation, RDSEED checks the replacement length and bounded success, and inline calls protect the red zone. The new execution bodies remain guarded for Linux/macOS x86-64. **Validation:** The exact current file compiles in C++23 with current matching relinker headers. Hosted Build 40256933244 logs show amd64_only_converter passes on Ubuntu (job 121360738660) and macOS x86-64 (job 121360738706); the respective full relinker CTest runs report 309 and 299 tests passing. Current Conventions passes. **Scope:** Local Windows syntax does not execute the guarded bodies; execution evidence comes from the hosted merged-PR jobs. No game/performance or broad CPU-feature portability claim.
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!8236
No description provided.