fix(relinker): decode the MOV moffs address and give REX.W precedence over 0x66 #1226
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1226"
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 Dextroid17 on 2026-10-07T18:27:44Z.
What
Fixes #1162 and #1167. Both are
X64InstructionDecoder::Decodereturning a short length — one for an immediate it sized wrong, one for an address it never counted — so they are one change to one function.#1162 — REX.W wins over 0x66
Decodesized the immediate as imm16 whenever the 0x66 operand-size prefix was present, even when REX.W was too. In 64-bit mode REX.W takes precedence (Intel SDM Vol. 1 §3.6.1 Table 3-4; Vol. 2A §2.2.1.2), so the operand size is 64 bits and the immediate stays imm32. TheB8+rcase in the same function already applied that rule; the imm32 opcodes and theF7 /0TEST form did not, andDecodeInstructionandInstructionScannerinherited the short length.66 48 81 C0 imm3266 48 05 imm3266 48 C7 C0 imm3266 48 69 C0 imm3266 48 68 imm3266 48 A9 imm3266 48 F7 C0 imm32The four controls the report lists as already correct are in the test and unchanged:
66 81 C0 iw(5),48 66 81 C0 iw(REX not directly before the opcode, 6),66 41 81 C0 iw(REX without W, 6),66 48 B8 imm64(11).#1167 — the MOV moffs address
One-byte
A0-A3had no case, so the 8-byte address (4 bytes with0x67) was never counted.Decodenow records the0x67prefix and sizes the operand at imm64, or imm32 with0x67.A1+ 8-byte address48 A1+ 8-byte address48 A3+ 8-byte address64 48 A1+ 8-byte address67 A1+ 4-byte addressThis is the one with a visible consequence:
InstructionScannersweeps linearly, so for48 A1 66 0F 78 C0 08 00 00 00 C3it reported an EXTRQ inside the address, which--to-intelwould have rewritten.Tested
Linux (CachyOS), Release, lavapipe with
GALLIUM_OVERRIDE_CPU_CAPS=avxandANYPS5_REQUIRE_VULKAN=1: the full suite reports100% tests passed out of 399. Windows through CI.Not tested: no title, and I did not re-run the reporter's MSVC reproduction; the sequences are decoded on Linux instead.
The new block in
decoderLengthscovers all fifteen sequences above and fails on the old decoder rather than merely passing on the new one: withX64InstructionDecoder.cppreverted it reportsAn immediate or moffs operand was decoded with the wrong lengthand exits 1.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)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-07T19:09:35Z.
Closing this — both halves are already covered by open PRs, and both were opened first.
F7 /0TEST form, the same test vectors and controls, and a clearer formulation (operandImmediateSizecomputed once) than the per-branch booleans I used here.addressSizeOverridetracking, same sizing, same five test vectors — plus ascannerMovMoffstest that pins the scanner consequence directly, which this PR did not.Two PRs for one change is two reviews for one result, so I would rather not spend yours.
Sorry for the noise, @oguzhanozfe and @emirplus — I read the issues and wrote the fix without first checking the open PRs, which is my mistake and now a standing step for me.
Pull request closed