test(relinker): check decoder lengths against an LLVM-generated table #1552
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1552"
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 arvindfroi on 2026-10-08T12:10:03Z.
What
InstructionScannersweeps code linearly withX64InstructionDecoder::Decode, so one wrong length puts the rest of the sweep out of step (#1162, #1167).decoderLengthschecks about 40 hand-picked encodings. This addsdecoder_length: 946 encodings whose lengths come from LLVM's x86 disassembler, each checked three ways:Decodeon a buffer of exactly the instruction returns its length;CodegenException(no read past the end).DecoderLengthCases.hppwas generated by a script that is not in the repository: it builds every one-byte,0F,0F 38and0F 3Aopcode with no prefix,66,F2,F3,REX.W,66 REX.Wand67, and every VEX map 1-3 opcode for eachpp,LandW, each with a register ModRM and a SIB + disp32 memory ModRM. It hasllvm-objdumpdecode them and keeps one case per opcode for each distinct length, plus all four operand-size prefix combinations where they change the length. It skips encodings LLVM rejects, VMREAD/VMWRITE (0F 78/0F 79without an SSE4a prefix, which the decoder rejects on purpose) and66-prefixed near branches, whose length differs between Intel (ignored) and AMD (rel16). Its output is deterministic.The table catches the three length bugs fixed today: run against the decoder of each earlier revision, it fails with
Wrong length for 66480584651122before #1163, andCannot decode 0fa8: Instruction truncated before ModRM bytebefore #1381; MOV moffs (a1…,67 a1…) fails before #1168. On currentmainall 946 pass.Tested
On macOS (Apple clang, arm64):
decoder_length_testsbuilt fromDecoderLengthTests.cppandX64InstructionDecoder.cppwith only the two include directories the CMake target lists,-Wall -Wextraclean, passes onmain; built against the decoder at2959dc53ande66d78c6it fails as described. A second LLVM pass over the table, withint3padding, agrees with every length.tools/check_conventions.py --base origin/mainpasses. Running the script again reproduces the header byte for byte (--objdump objdump --clang clangwith Xcode's LLVM 21). No x86-64 toolchain on this machine, so the Linux and Windows builds are left to CI.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T22:31:09Z.
The tests are worth having. Could you drop the generator script and keep only the generated table and the test? A new tool needing llvm-objdump and clang isn't something we want in tools/ just to regenerate it.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T05:26:41Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/codegen/tests/DecoderLengthCases.hppcore/relinker/codegen/tests/DecoderLengthTests.cpp