llvm / llvm/llvm-project

x86: prefix decoding issues

Open
#187,045 2 comments 0 reactions 0 assignees View on GitHub
backend:X86 inline-asm
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I recently fixed a [prefix decoding issue in Capstone](https://github.com/capstone-engine/capstone/pull/2856). It fixes an issue where certain instructions are decoded incorrectly when mandatory prefixes appear multiple times or in an unexpected order. I also fixed an issue where [segment overrides were not ignored when they should be](https://github.com/capstone-engine/capstone/pull/2819).

It looks like LLVM is also using the [same code](https://github.com/llvm/llvm-project/blob/a93560d13eabde5da82eb2214e7c1bc27ec57e6f/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp#L222).

Would there be any interest in a patch porting my fixes from Capstone to LLVM?

---

As an example:

In `test.c`:
```c
int main() {
__asm__ volatile(
".byte 0x66, 0x4e, 0xf3, 0x67, 0x0f, 0x38, 0xf6, 0x24, 0x27\n"\
".byte 0xf3, 0x3e, 0x66, 0x67, 0x0f, 0xa4, 0x84, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00"
);

return 0;
}
```

Then execute:
```shell
clang test.c -o test
llvm-objdump test
```

This will print the following two instructions inside `main`:

```
113b: 66 4e f3 67 0f 38 f6 24 27 adcxl (%edi,%eiz), %esp
1144: f3 3e 66 67 0f a4
```

Both of these are incorrectly decoded: the first should be `adox` and the second should be `shld`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.