fix(relinker): stop reading pop r/m without REX as XOP in red-zone framing #11063
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11063"
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 roboterspinne on 2026-10-25T16:22:11Z.
What
extensionBitsandmemoryUseincore/relinker/codegen/src/x86/RedZoneFramer.cpptell VEX, EVEX and XOP encodings apart by the lead byte, and both took every8Fwithout REX for an XOP prefix.8Fis alsopop r/m(8F /0). For it, the ModRM byte was read as XOP's inverted R, X and B bits. Bit 5 of a/0ModRM byte is always clear, so B was always set, and the base ofpop qword [rsp-0x10](8f 44 24 f0) looked like R12.memoryUsealso skipped its general-purpose register checks, sopop rspthrough8f c4did not count as a use of RSP. As a result,--frame-red-zoneframed a leaf with a frame pointer that pops to an RSP operand, with the operand left unmoved, and framed leaves of both kinds that pop into RSP through8F. The REX.W forms (48 8f 44 24 f0) are refused asother use of rsp. With the framer of untouchedmain(RedZoneFramer.cppis the same from3a2c51afd2to0119103fa9), the leafpush rbp; mov rbp, rsp; push r15; push rbx; mov [rbp-0x20], rcx; push rdx; pop qword [rsp-0x10]; mov rax, [rbp-0x20]; pop rbx; pop r15; pop rbp; ret, framed withFrameRedZoneFunctionsand run natively on Windows, returns RCX instead of RDX, because after framing the pop stores 0x80 bytes lower. No framer test contained apop r/m.xopPrefixedtakes8Ffor XOP only when the map field (the low five bits) of the next byte is 8 or more. This is the ruleX64InstructionDecoderalready applies (XopMapMin), and the one AMD's APM gives for telling XOP fromPOP Ev.extensionBitsand thevexflag ofmemoryUsenow use it, sopop r/mwithout REX goes through the same checks as its REX forms. In a leaf with a frame pointer, an RSP operand orpop rspisother use of rsp. In a leaf without one,pop rspisother use of rsp, and a pop to an RSP operand has its operand moved like any other RSP operand. That such a leaf also moves RSP in its body is what #11061 refuses.tellsPopsWithoutRexFromXopinRedZoneFramerTests.cpphas two parts:other use of rsp: a leaf with a frame pointer withpush rdx; pop qword [rsp-0x10], one withpush rdx; pop rsp(8f c4), and a leaf without a frame pointer withpop rsp. All three are framed onmain, where the test fails at its firstrequire.vprotb xmm0, [r12], 1(8f c8 78 c0 04 24 01, XOP.B clear) is not an RSP operand and needs no stub, andvprotb xmm0, [rsp-0x10], 1(8f e8 78 c0 44 24 f0 01) is moved.pr_overlap.pyreports no overlap with open pull requests. Three other changes touch the same file: #10999 changes the start ofmemoryUse, #10871 changes the exits and prologues, and #11061 adds the push and pop check. This branch merges cleanly with each, andred_zone_framerpasses on each merge.Tested
Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic leaves only, no title or homebrew.red_zone_framerwith the new test andmain'sRedZoneFramer.cppfails witha pop without REX to an rsp operand or into rsp, read as an XOP prefix, was framed; with the change it passes. Run leaf by leaf,mainframes all three pop leaves, and frames the two XOP controls with the same moved operands as the change.relinker_coreplaces each leaf in executable memory fromVirtualAlloc, frames it withFrameRedZoneFunctions, applies the displacements and sites the wayRedZoneFramerExecutionTests.cppdoes, and calls it with RCX = 0x1111 and RDX = 0x2222.main, the leaf above returns 0x1111 instead of 0x2222. With the change it is refused and returns 0x2222.objdump -M inteldecodes the test bytes as described:8f 44 24 f0ispop QWORD PTR [rsp-0x10],8f c4ispop rsp, and8f c8 78 c0 04 24 01isvprotb xmm0, [r12], 0x1. The relinker's decoder gives the same lengths.ctest -j 8: 292 tests, 289 passed,long_pathsskipped. Two failures come from this machine, not from the change:patch_advisor_unitfails because the path contains spaces (fixed by open #10667), andpr_overlap_encodingfails because the build directory is outside the git checkout; run from the checkout, it passes.python tools/check_conventions.py --base upstream/mainwith this title and description passed.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-25T16:37:13Z.
Review: APPROVED
Reviewed head
3398046c3c. The 0x8F discriminator matches the decoder’s existing XOP map threshold, so POP /0 no longer inherits XOP extension bits while valid XOP forms retain them. The added regressions cover POP to an RSP-based memory operand, POP RSP, and XOP controls. The relinker matrix and ASan checks are green on Linux, Windows, and macOS, and conventions, eligibility, intake, and labels pass. I found no blocking issue in the reviewed diff.