fix(relinker): let REX.W override 0x66 when sizing decoder immediates #1163
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1163"
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 oguzhanozfe on 2026-10-07T15:52:54Z.
What
Fixes #1162.
In 64-bit mode REX.W takes precedence over the 0x66 operand-size prefix (Intel SDM Vol. 1 §3.6.1, Table 3-4; Vol. 2A §2.2.1.2). The operand size is 64 bits, so the immediate of
81 /n,C7 /0,69,68,A9, the05..3Daccumulator forms and theF7 /0TEST form stays imm32.X64InstructionDecoder::Decodeapplied this only toB8+rand returned a length two bytes short for the others.The decoder now computes the operand-size immediate once after the prefix loop and uses it at the three sites. The
decoderLengthstest gains the seven66 48forms and four controls:66alone, a REX before66(ignored), REX without W, and66 F7TEST.Tested
x86_64-ucrt-posix-sehr7), configured like CI (-G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON). I builtcore/relinker/alland ran its ctest suite. On this branch 29/29 tests pass. With only the fix reverted,amd64_only_converterfails, so the new cases catch the bug.X64InstructionDecoder.cppwith a standalone program that runs the newdecoderLengthssequences throughDecodeandDecodeInstruction.66 48cases were 2 bytes short and the controls passed.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 Dextroid17 on 2026-10-07T16:00:25Z.
Independent check on Linux, because the diagnosis is reproducible without MSVC.
I compiled
X64InstructionDecoder.cppfrommainand from this PR into a standalone harness (g++ -std=c++20 -O0, includescodegen/include+domain/include) and ran your seven new sequences plus the four controls throughDecode, checking the decoded length against the byte count:main66 48 81 C0 imm3266 48 05 imm3266 48 C7 C0 imm3266 48 69 C0 imm3266 48 68 imm3266 48 A9 imm3266 48 F7 C0 imm3266 81 C0 iw48 66 81 C0 iw66 41 81 C0 iw66 F7 C0 iwThe seven cases are two bytes short on
mainand all fourteen pass here, with the controls unchanged — so the added cases do fail without the change, and the change touches nothing else.66 48 81 C0 imm32giving 6 also confirms the downstream effect the report describes:InstructionScannerdecodes the trailing two bytes of the immediate as the next instruction.I also swept the decoder for other operand-size immediate sites this rule could reach. There are none left:
CALL/JMP rel32(line 190) is always rel32 in 64-bit andRET imm16/ENTER(lines 201-206) are fixed-width by definition, so neither is affected by0x66; every other immediate in the table is imm8. The three sites you changed (the imm32 group, theB8+rsibling, andF7 /0) are the whole set.One note for the record: the added sequences sit inside
decoderLengths, which runs as part of the registeredamd64_only_converterctest target, so CI does execute them on Linux — the missing MinGW toolchain is only a local gap.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:23:33Z.
Checked: built on top of current
main, ctest 424/424 green. Reverting only the decoder change makesamd64_only_converterfail, so the new66 48cases and controls pin the fix. The REX-before-66control matches the decoder resettingrexPresenton later prefixes. CI green on the head; merging.