fix(relinker): preserve opcode-encoded stack register uses #10999
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10999"
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 plexerPK on 2026-10-25T13:43:56Z.
What
A red-zone leaf that reads RSP through an opcode-encoded operand, such as
PUSH RSP; POP RAX, can observe the lowered stack address after framing. Extend the existing rejection of other RSP uses to opcode-encoded PUSH, POP, XCHG, immediate MOV and BSWAP operands, including ESP, SP and SPL. Respect REX.B and distinguish AH from SPL so unrelated registers remain eligible.Tested
macOS arm64, Release relinker-only build at
de2b5de1b76afe51ec909ec9f5991e676edbcf06on maine05ba6feebd000cfc316c1d1f00e37e030aa3d8b. The build and all four affected CTests pass:red_zone_framer,rewrite_boundaries,cli_argsandgame_patches. The BSWAP RSP/ESP and REX.R regressions failed on the previous head, while REX.B R12/R12D controls remain eligible. The added framer regressions cover eleven stack-register cases and five REX.B/AH controls; the regression failed before the guard.python3 tools/check_conventions.py --base origin/main,git diff --checkand the publication-time official overlap check pass. Linux x86-64red_zone_framer_executionis not registered on this host. These results cover framing decisions and generated patch metadata; no Linux/Windows guest execution, title, GPU or hosted-CI result is claimed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T13:52:34Z.
Review: APPROVED
Reviewed the current head
46566d2d032f312d2775d2e70033a050ea0aa3d5. The opcode-register checks correctly account for the REX.B extension when identifying RSP, and the added cases cover PUSH/POP/XCHG/immediate MOV stack-register encodings plus non-stack controls. The change is limited to red-zone eligibility detection and its regression tests.Local validation: relinker-only Release build succeeded; all five focused tests passed (
red_zone_framer,red_zone_framer_execution,rewrite_boundaries,cli_args,game_patches); conventions andgit diff --checkpassed. The full 296-test CTest run completed with 294 passing;masked_store_loweringandamd64_only_converterboth terminate withIllegaland reproduce when rerun alone, unrelated to the touched code. Hosted checks passed for Linux, Windows, macOS arm64, macOS x86_64, ASan, conventions, intake, eligibility and labels; product-only jobs were skipped by workflow policy.Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T14:24:46Z.
Review: COMMENTED
Reviewed head
46566d2d03on basee05ba6feeb(main is at3a2c51afd2now, nocore/relinker/codegen/changes since). Linux x86_64, GCC, Release, relinker-only build.What I ran:
red_zone_framerandred_zone_framer_executionon the head: pass.RedZoneFramer.cpp: fail withan opcode-encoded rsp use was framed, so the regression is real.50-5f,90-97andb0-bfall come out withHasModRmfalse. A REX followed by a legacy prefix gets zeroed, same as the CPU. So41 66 bc imm16(mov sp) still gets skipped and66 41 bc(mov r12w) still gets framed. Checked both through the framer. I found no false positives.One gap: BSWAP.
0f c8+rhas no ModRM either, and the new branch returns early onIsTwoByteOpcode, sobswap rsp/bswap espstill get framed. I added{0x48, 0x0f, 0xcc, 0x48, 0x0f, 0xcc}toskipsOpcodeEncodedRspUseslocally, and it fails on this head (framed=1, 2 sites).0f ccand4c 0f cc(REX.R) give the same result. No compiler emits this in a leaf, butinc rsp,not rspand friends already skip through themod == 3rule, so this is the one register-operand form left.This passes all your tests plus the two bswap cases, and a
49 0f cc(r12) control still frames:Small, up to you whether it goes in here.
Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-25T15:05:18Z.
Review: COMMENTED
Reviewed head
de2b5de1bmerged ontoupstream/main3a2c51afd(2026-10-25); the merge is clean.Environment: Windows 11 Home 10.0.26200, Intel i9-12900H, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2,
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release.Results
long_pathsskipped. The one failure ispatch_advisor_unit. It fails the same way on plainmainon this machine, because the temp path contains a space (#10667), and it is unrelated.red_zone_framerpasses.red_zone_framer_executionis registered only on Linux x86-64 and does not run here.main'sRedZoneFramer.cppunder this test file,red_zone_framer_testsfails withan opcode-encoded rsp use was framed.0x54,0x94,0xbc, the0xb4clause or the new0F CCclause fails the suite.a leaf that allocates with sub after its pushes and spills below its allocation was not framed).0xb4without a REX prefix.0x5csurvives (inline comment).41 40 b4 10is therefore treated as SPL,40 41 b4 10asr12b, and48 66 bc imm16asmov sp, all as on hardware.b4 10without REX (AH) still frames.bswapaddition fromde2b5de1b, the guard covers every form that encodes RSP/ESP/SP/SPL in the opcode (50+4,58+4,90+4,B8+4,B0+4with REX,0F C8+4), with or without0x66and REX.W. The REX.B controls (r12) still frame.check_conventions.py --base upstream/mainpasses with this title and body.Nit: see the inline comment on line 297.
Not checked: execution of framed code (the execution test is Linux-only; ahmadmuj ran it on Linux for the previous head); Linux and macOS locally.
Apart from the nit, I found nothing to change. For disclosure: none of my open PRs touches
RedZoneFramer.cppor its tests.Written with AI assistance (Claude Code). I ran the build, the tests, the counter-check and the mutants above on my Windows 11 machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:06:32Z.
Review: APPROVED
Reviewed exact head
de2b5de1b76afe51ec909ec9f5991e676edbcf06. I configured and built the relinker-only Release target locally;red_zone_framer,rewrite_boundaries,cli_argsandgame_patchesall pass (4/4), and exact-head diff/conventions checks pass. The opcode-encoded register handling correctly distinguishes RSP/ESP/SP/SPL from REX.B-extended registers and preserves AH-versus-SPL behavior; the added cases cover both skipped stack-register uses and eligible non-stack controls. Hosted Ubuntu, Windows, macOS arm64, macOS x86_64 and ASan relinker jobs pass; product jobs are skipped by path policy.