fix(relinker): decode 0F A8-AA without a ModRM and MOV CR/DR without a memory operand #1381
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1381"
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-08T01:14:35Z.
What
Two groups of two-byte opcodes are sized with bytes they do not have by
X64InstructionDecoder::Decode, and described wrongly byDecodeInstruction:PUSH GS,POP GSandRSM(0F A8,0F A9,0F AA) have no ModRM byte, but they are inside the0F A3-0F ABModRM range (TwoByteModRmRangeA). The decoder reads the next byte as a ModRM and adds its SIB and displacement. The range now ends at0F A7, andBTS(0F AB) is listed on its own.MOVto and from control and debug registers (0F 20-0F 23) ignores the ModRM mod field: the operand is always a register (Intel SDM Vol. 2B, MOV—Move to/from Control Registers and Debug Registers). The decoder treated mod 00/01/10 as memory forms, added a SIB and displacement, andDecodeInstructionreported mod 00 r/m 101 as a RIP-relative disp32. The mod field is now ignored for these opcodes. The 0F 38 opcodes 20-23 (PMOVSX*) keep their memory forms.Decodeon main0F A80F A90F AA0F 20 050F 22 040F 21 45InstructionScannersweeps linearly, so one of these, or data in.textthat looks like one, puts the rest of the sweep out of step. Compilers do not emit them in user code, so this is decoder correctness, not a fix for a title. Expected lengths agree with Capstone 5.0.7.Tested
aarch64 Debian 13 with clang (Zig 0.16 toolchain). 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, including the newdecoderTwoByteOpcodeLengths, which fails without the fix. The 6*Executionfunctions were not run.0F 20-23and0F A8-AA. On 6,782 unique instructions from x86-64-march=znver2 -O2objects nothing changed (0 mismatches before and after).X64InstructionDecoder.cppcompiles for x86_64-linux-gnu and x86_64-windows-gnu with-Wall -Wextra -Werror.python3 tools/check_conventions.py --base origin/mainpasses.Left as they are:
0F B9(UD1) keeps its ModRM, as in the Intel SDM and LLVM (Capstone decodes it without one);0F A6/0F A7, which are undefined in 64-bit mode, keep their old ModRM sizing.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)