test(relinker): check ADX guest state preservation #7531
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7531"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:29:57Z.
What
Adds generated-stub regression checks for the ADCX/ADOX lowering in #7173. For both widths and instructions, the test covers every destination except RSP and every source register including RSP, with four flag images and zero, mixed, and all-ones register patterns. It checks the result, every unrelated guest GPR, the guest RSP, arithmetic flags, and the caller's 128-byte red zone.
This is test-only and depends on #7173. The preservation gap and independent validation matrix were reported by plokmklo in #7157; this follow-up credits that contribution and omits the VEX forms whose validity was not established in that discussion.
Tested
ctest -R '^adx_lowering$'passes (1/1), including the new preservation matrix.python3 tools/check_conventions.py --base upstream/mainpasses.git diff --checkpasses.Checklist
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T14:44:03Z.
Ran this under Rosetta, head
6d7eddffcmerged intomaina62c724c3.Machine: Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release builds, x86_64 (
-DCMAKE_OSX_ARCHITECTURES=x86_64, Xcode's Python 3.9.6, run under Rosetta 2) and native arm64.adx_lowering_testsruns the new preservation matrix under Rosetta and passes. On arm64 the execution part is compiled out, as expected.mov scratch, [rsp]fromEmitAdx's epilogue, so the scratch register is not restored. The new test fails (ADX changed an unrelated guest register or produced the wrong destination). #7173's tests on010ce9b02still pass with that change.The red-zone check looks at the wrong side of RSP. The wrapper writes the sentinels at
[rsp]..[rsp+120]afterlea rsp, [rsp-128], then saves that RSP as the guest RSP (cell 72). So the 128 bytes it checks sit above the guest RSP, in the wrapper's own frame. The red zone thatEmitAdx's 144-byte frame steps over is the 128 bytes below the guest RSP, and nothing checks those. To show it, I shrank the lowering's frame from 144 to 16 bytes (kFrameSizeand bothleas). The scratch and flags spills then land at guest RSP-16 and RSP-8, inside the red zone, and the test still passes.A version that checks the bytes below the guest RSP works for me under Rosetta:
push/popf) before thelea.[rsp-128+8*i].raxaround the copy, before the wrapper pushes anything. Then fillRedZonefrom the cells.With that version, the real lowering passes. A 16-byte frame and a 128-byte frame both fail with
ADX changed the caller red zone. The dropped scratch restore still fails with the register message. The 19-line diff is below. I only ran it under Rosetta, not on a native Linux or Windows x86-64 host.Test diff
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T16:51:20Z.
Fixed in
f1fcb95f4. The fixture now plants and reads sentinels in the 128 bytes below the guest RSP. It captures those bytes immediately after the lowered instruction and before the wrapper pushes registers, then checks them after restoring the wrapper state. The focused Linuxadx_loweringCTest passes (1/1);git diff --checkandpython3 tools/check_conventions.py --base upstream/mainpass.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:53:21Z.
Thanks for the independent Rosetta check and the short-frame negative control. The updated head
f1fcb95f4now places and checks the sentinel region below the guest RSP, and the focused Linux test plus Linux/macOS/Rosetta/Windows relinker CI are green. I also see the PR is currently DIRTY against main; this looks like a base update/rebase item before merge.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T12:01:24Z.
Review: COMMENTED
Reviewed
3fbc2fd4913e7feede88f43a78c5cc241e37b11b— comment; dependent integration remains pending.Fresh Windows/GCC 15.2 Release relinker-only build:
adx_loweringpassed 1/1. The preservation matrix checks both ADCX/ADOX widths, guest registers including RSP sources, arithmetic flags and the caller's red zone. The author merge base has noadx_lowering_teststarget; that absence is expected, not a product regression.This head includes the production lowering from its declared dependency #7173, which is still open at the refreshed head
db9db10676a6ae4215b7854126555882ac6661bb. I have not completed a full review of that underlying lowering or validated this test delta after landing/retargeting the dependency. The local pass supports the submitted test head, not final approval of the combined production change. Recheck that integration before final approval. No game or full product execution is claimed.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-29T06:23:33Z.
Review: COMMENTED
Re-reviewed
4fc006aa12fcffee2efcc209d95ba29cba9f829cagainst2227f1366188cda5699dd20e2e756a18006a5d4b. The added matrix checks both instruction/width combinations, every supported destination and every source including RSP, unrelated GPRs, arithmetic flags, guest RSP, and the caller's 128-byte red zone. No actionable issue found in these assertions.Windows/GCC 15.3 Release: built
adx_lowering_testsand passed its registered CTest. Its execution branch is Linux/macOS-only, so that unmodified Windows pass does not exercise the preservation matrix. I therefore compiled a separate review-only adapter replacing mmap/mprotect with Win32 page allocation/protection and using an explicit SysV ABI pointer for the generated preservation wrapper. With the submitted arithmetic, lowering and preservation checks unchanged, it passed all 11,520 matrix cases plus the existing execution/native-ADX comparisons on this ADX-capable x64 host.Independent negative control: a separate copy reduces the spill frame from 144 to 128 bytes with matching stack adjustments. It compiles but the matrix exits 1 with
ADX changed the caller red zone; the submitted implementation passes. No tracked source was modified by either adapter.The declared prerequisite #7173 is still open. This validates the submitted combined branch, not integration after that dependency lands. Native Linux/macOS and actual Rosetta execution were not independently run locally, so I am leaving a formal COMMENT with the execution evidence rather than treating this as merge readiness.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:56:56Z.
Review: COMMENTED
Replies checked — docs duplicate confirmed, one answer needed, no code finding
The docs file at this head has two identical "
--to-rosettalowers what Rosetta lacks" entries, which is the duplicate a reviewer reported after merge with main.What I ran
2d2915b3f839bba156db404e0f9092c448b0116c(OPEN, unchanged from batch).gh apicomments, reviews and review comments on #7531, newer than 2026-10-18T18:53:21Z, excluding MarcZX10 and bots.gh pr view 7531 --json body,statusCheckRollup;gh pr view 7173 --json state.git show 2d2915b3:docs/dev/debt/relinker.md;git merge-tree --write-tree upstream/main 2d2915b3, then a grep count of the merged file.Results
merge-treevs upstream/mainrelinker.mdentries at headrelinker.mdentrieswindows,linux,register-context,write-watchSKIPPEDFindings
Sources
github.com/boykopovar/AnyPS5@2d2915b3f8/docs/dev/debt/relinker.md (L49-L50)Not verified
Imported from boykopovar/AnyPS5. Originally posted by catminou4 on 2026-11-25T06:20:29Z.
Review: CHANGES_REQUESTED
Built on Linux x86_64 (relinker-only Release build, GCC), merged into current
main(3cab484efb).main:ctest -R '^adx_lowering$'passes.main, with this PR'sAdxLoweringTests.cppon top),adx_lowering_testsfails immediately withADCX address-size source was mistaken for RIP-relative. #7173 has since gained84075b7712(relocate address-size RIP-relative ADCX/ADOX sources) and5f8c0b7958, so it now expectssixth->Memory->RipRelativeto be true. This branch still asserts the opposite.AdxLowering.cpp,AdxLoweringTests.cppanddocs/dev/debt/relinker.md.The new preservation matrix itself (every destination except RSP and every source, four flag images, unrelated GPRs, RSP and the 128-byte red zone) looks like the right check. Rebase it on the current #7173 head (or on
mainafter #7173 merges) and keep only the test commits.Not mergeable as is: the branch is stale against its dependency.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:01:05Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONand ranadx_loweringon Linux x86-64. The fixture passed its guest state preservation checks.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.