fix(relinker): decode the 64-bit address of MOV moffs instructions #1168
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1168"
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-07T16:01:45Z.
What
Fixes #1167.
A0-A3(MOV AL/eAX/rAXto and frommoffs) have no ModRM byte. In 64-bit mode they carry an 8-byte absolute address, or 4 bytes with a 0x67 prefix (Intel SDM Vol. 2A §2.2.1.4). The decoder added nothing for the address, so the linear scanner decoded the address bytes as instructions. The decoder now records the 0x67 prefix and adds the address size for these opcodes.The
decoderLengthstest gainsA0/A2with no prefix,48 A1,64 48 A3,67 A1and48 67 A3. In the last one, a REX before 0x67 is ignored and the address is 4 bytes.This touches the same file as #1163, but the hunks are separate, and the two branches merge cleanly.
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 30/30 tests pass. With only the fix reverted,amd64_only_converterfails, so the new cases catch the bug.X64InstructionDecoder.cppandInstructionScanner.cppwith a standalone program. It checks 11A0-A3forms and 5 controls (A8,A9,67 8B 00,A4,48 A5) throughDecodeandDecodeInstruction, and scansmovabs rax, [0x8C0780F66]; ret.[0,+2] [2,+6] [8,+2] [10,+1].[0,+10] [10,+1].add_executable(relinker ...)source list. These Python tests pass with it:dynamic_segment,elf_offsets,optional_plt,linux_load_alignment,string_table_bounds,executable_segments,elf_header,linux_entry_argv,input_magic,empty_tlsandtls_function_coverage.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 hikazey on 2026-10-08T07:07:42Z.
Checked on Ubuntu 24.04, GCC 14.2:
amd64_only_convertere8f73a55)main, new test cases keptThe semantics match the SDM (Vol. 2B, MOV, opcodes A0-A3): in 64-bit mode the moffs operand is 8 bytes, or 4 bytes with the
67prefix.66and REX.W change only the accumulator size, not the moffs width, which is what the0x48/0x64 0x48cases cover. Moving0x67out of the skipped-prefix list into its own branch leaves prefix scanning unchanged, since it still continues the loop.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:39:56Z.
Checked: build + full ctest on this head merged onto current main (424/424), and
amd64_only_converterfails with the decoder change reverted, so the newA0-A3cases pin the fix. Prefix handling is right (0x67 only sets the flag, a REX before it is dropped, as the48 67 A3case pins). CI green on linux and windows; merging.