fix(relinker): detect ModRM and vector RSP operands in RedZoneFramer #16432
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16432"
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 Dinsuljevic336 on 2026-11-06T17:23:50Z.
What
Classify missed direct
RSPgeneral-purpose register operands (and stop misclassifyingF3 0F 7Emovq xmm, xmm4as anESPread) inRedZoneFramer::memoryUse(core/relinker/codegen/src/x86/RedZoneFramer.cpp).When
--frame-red-zonelowersRSPat leaf entry and raises it at leaf exit, any leaf that reads or writesRSPdirectly outside the recognized prologue/epilogue adjustments must be skipped (other use of rsp) rather than framed with a shiftedRSP. Previously,memoryUsemissed several instruction families whoseModRM.reg,ModRM.rm(mod == 3), orXOP.vvvvfields encodeRSP/ESP/SP/SPL, while treatingF3 0F 7E(movq xmm, xmm/m64) as a GPRrmread:ModRM.reg(mod != 3):movsxd rsp, m32(0x63) and 3-operandimul rsp, m, imm(0x69,0x6B).0Fscalar and vector-to/from-GPR forms:lar/lsl(0F 02/03),sldt/str/smsw(0F 00/01),cvtsi2ss/cvtsi2sd(F3/F2 0F 2A),cvt[t]ss2si/cvt[t]sd2si(F3/F2 0F 2C/2D),movmskps/movmskpd(0F 50,66 0F 50),setcc spl(40 0F 90..9F),rdfsbase/rdgsbase/wrfsbase/wrgsbase(F3 0F AE /0..3),pinsrw/pextrw(0F C4/C5),rdrand/rdseed/rdpid(0F C7 /6..7), andpmovmskb(0F D7), while distinguishing66 0F 7E/0F 7E(movd/movqto GPR) fromF3 0F 7E(movq xmm, xmm4).0F 38/0F 3Aforms (whereDecodeInstructionrecords the escape byte0x38/0x3Aininfo.Opcodeand the opcode byte atOpcodeOffset + 2):movbe(0F 38 F0/F1),crc32(F2 0F 38 F0/F1, including REX-gatedsplvsah),adcx/adox(66/F3 0F 38 F6),movdir64b/movdiri(66 0F 38 F8,0F 38 F9),pextrb/pextrw/pextrd/pextrq(66 0F 3A 14..16),extractps(66 0F 3A 17), andpinsrb/pinsrd/pinsrq(66 0F 3A 20,22).vmovd/vmovq(map=1,0x6E/0x7Ewithpp=1),vcvtsi2ss/sdandvcvt[t]ss2si/sd2si(0x2A/0x2C/0x2D),vmovmskps/pd(0x50),vpmovmskb(0xD7),vpinsrw/vpextrw(0xC4/0xC5),vpextrb/w/d/q,vextractps, andvpinsrb/d/q(map=3,0x14..17,0x20,0x22), plus XOP TBM (map=9,0x01/0x02) and immediatebextr(map=10,0x10).Tested
Linux x86-64 (GCC 14.2.0,
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), Release and ASan + UBSan (-fsanitize=address,undefined):red_zone_framerandred_zone_framer_executionfail without theRedZoneFramer.cppfix (0/2passed) and pass with the fix (2/2passed, including real-hardware single-step red-zone clobber execution ofmovq xmm0, xmm4and execution verification of skippedvmovq/pinsrq/movbe/imulRSPleaves, plus557/557CTest suite passing).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 gabichuuuuu on 2026-11-08T01:33:31Z.
Review: COMMENTED
Windows check of head
5610f1f9e1, merged ontomain210676ad86(clean merge).Setup: Windows 11, WinLibs GCC 15.2, Release, relinker-only.
red_zone_framerandred_zone_framer_executionpass 2/2. The execution test ran rather than skipping.main'sRedZoneFramer.cppwith this PR's two test files fails both:direct rsp operand case 0 was framedandonly 5 of 6 leaves were framed.0F 6E/7E, the REX gate forsetcc/crc32withsplagainstah, the/1–/3opcode extension excluded fromregfor BMI1F3, and theF2-over-66priority inlegacyPpall match. The gaps I found are privileged or absent on Zen 2 (VERR/VERW,ENQCMD[S],SENDUIPI, CET, AVX-512usiconversions), so they do not affect PS5 code.Merge order: this conflicts textually with #16371 in
RedZoneFramer.cpp. #16371 merges cleanly withmainon its own, so whichever lands second needs a rebase.