[LLVMdev] REX prefix is not handled properly for X86_64?
junkoi2004 at gmail.com
Fri Dec 12 20:44:52 PST 2014
On Fri, Dec 12, 2014 at 3:12 AM, Ahmed Bougacha <ahmed.bougacha at gmail.com>
> Hi Jun,
> FWIW, I think LLVM's right in rejecting this. Per SDM 2.2.1, "Only one
> REX prefix is allowed per instruction."
> Here, 0x43 and 0x40 are both REX prefixes, so that contradicts the manual.
> However, trunk llvm-mc is still able to disassemble the add, I guess
> because it ignores invalid bytes:
> <stdin>:1:1: warning: invalid instruction encoding
> 0x43 0x40 0x04 0x75
> addb $117, %al ## encoding: [0x04,0x75]
> ## <MCInst #107 ADD8i8
> ## <MCOperand Imm:117>>
> It would be trivial to change the disassembler to accept redundant REX
> prefixes (see attached patch, turn that into a loop to accept more
> than 2, but that would be even worse). Then, you have to decide which
> one to use: the first, or the last. Currently, only the last REX
> prefix is the one that's actually used for the following instruction:
> all the others before are discarded as invalid encodings.
> Now, if LLVM rejected useless REX prefixes (e.g. "40 04 75") that
> would be a problem, but that seems to work fine without any change.
> So, to recap: to avoid the problem, I think you should change the way
> you use the LLVM Disassembler API. When it's unable to disassemble a
> byte, ignore it and try again at the next one. That's what most
> linear disassemblers do, and would correctly ignore the first REX
> prefix here.
got it, thanks a lot!!!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev