fix(relinker): do not add the F6/F7 TEST immediate to EVEX instructions #1303
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1303"
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 overlordxrz-source on 2026-10-07T22:51:12Z.
What
X64InstructionDecoder::Decodeadds theTEST r/m, immimmediate when the opcode isF6/F7and ModRM.reg is 0 or 1. The check skips VEX and two-byte opcodes but not EVEX, so after an EVEX prefix the map-1 opcodeF6(VPSADBW, EVEX.66.0F.WIG F6 /r, no immediate) with ModRM.reg 0 or 1 is sized as if it carried an imm8:Decode62 F1 75 48 F6 C262 F1 7D 48 F6 05 disp3262 F1 6D 48 F6 4C 24 01InstructionScannersweeps linearly, so the byte after such an instruction is skipped and the rest of the sweep is out of step. The check now also excludes EVEX. Expected lengths are from Intel SDM Vol. 2B (VPSADBW) and agree with LLVM MC and Capstone 5.0.7.PS5 code does not use AVX-512, so this is decoder correctness, not a fix for a title.
Tested
aarch64 Debian 13 with clang (Zig 0.16 toolchain, libc++). A full CMake build was not possible on this host because the project needs x86-64.
amd64_only_converter_tests: every case that does not execute x86 code passes (21 of 27 functions,decoderLengthsincluded). The newdecoderLengthsentries fail without the fix. The 6*Executionfunctions were not run.DecodeandDecodeInstructionagainst Capstone 5.0.7 on about 64,000 generated encodings (legacy, 0F, 0F38, 0F3A, VEX and EVEX opcodes across prefix and ModRM/SIB forms) and on 6,782 unique instructions from x86-64-march=znver2 -O2objects. The VPSADBW length mismatches are gone, and no other length, RIP-relative flag or displacement offset changed.X64InstructionDecoder.cppcompiles for x86_64-linux with-Wall -Wextra -Werror.python3 tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T02:20:22Z.
Review: COMMENTED
Built and ran it, and proved the new cases actually bite rather than passing either way.
Linux (CachyOS, GCC, Release):
Mutation check — the decoder from
pr-1303^with your test kept, so only the guard differs:So the three new
0x62 … F6/F7cases genuinely exercise the bug, and the!evexPresentguard is what makes them pass. That is the check worth having: a decoder test that passes on both sides tells you nothing.The guard is now complete, and it matches how the prefix is treated elsewhere. The one-byte TEST rule already excluded VEX and the
0Ftwo-byte map; EVEX was the third encoding that can carry anF6/F7byte where it is notTEST. Line 98 in the same file already treats the two prefix kinds together (if (vexPresent || evexPresent)), so this makes the immediate rule consistent with that rather than adding a special case.Why it matters beyond one instruction: the length this function computes is what the scan uses to step to the next instruction. Consuming a byte as a
TESTimmediate that is not one shortens or lengthens this instruction by one, and every boundary after it in that pass is then wrong — so a single misread is a misplacement, not a local error. The three cases cover both a plain ModRM and a disp8 form, including the RIP-relative one, which is the shape a relink actually has to relocate.I checked for the same gap elsewhere in the file and did not find one. The other scanner (the RIP-relative/control-flow pass) handles
VEX2/VEX3/EVEXwith an earlyreturnbefore it reaches its own!twoByteOpcodeblock, so it never applies a one-byte immediate rule to a prefixed instruction. The equivalent of this fix was already there by construction; no follow-up needed.This is a comment, not an approval — I have no merge rights here.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-08T02:48:59Z.
@Dextroid17 Thanks for taking the time to build it and run the mutation check, and for looking at the other scanner too. Much appreciated.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T03:05:43Z.
You're welcome — the guard is a real fix, and the
0x62 … F6/F7cases earning a***Failedon the parent decoder is what makes it worth merging. Good luck with it.