<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 12, 2014 at 3:12 AM, Ahmed Bougacha <span dir="ltr"><<a href="mailto:ahmed.bougacha@gmail.com" target="_blank">ahmed.bougacha@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Jun,<br>
<br>
FWIW, I think LLVM's right in rejecting this. Per SDM 2.2.1, "Only one<br>
REX prefix is allowed per instruction."<br>
Here, 0x43 and 0x40 are both REX prefixes, so that contradicts the manual.<br>
<br>
However, trunk llvm-mc is still able to disassemble the add, I guess<br>
because it ignores invalid bytes:<br>
<br>
<stdin>:1:1: warning: invalid instruction encoding<br>
0x43 0x40 0x04 0x75<br>
^<br>
addb $117, %al               ## encoding: [0x04,0x75]<br>
                                        ## <MCInst #107 ADD8i8<br>
                                        ##  <MCOperand Imm:117>><br>
<br>
It would be trivial to change the disassembler to accept redundant REX<br>
prefixes (see attached patch, turn that into a loop to accept more<br>
than 2, but that would be even worse).  Then, you have to decide which<br>
one to use: the first, or the last.  Currently, only the last REX<br>
prefix is the one that's actually used for the following instruction:<br>
all the others before are discarded as invalid encodings.<br>
<br>
Now, if LLVM rejected useless REX prefixes (e.g. "40 04 75") that<br>
would be a problem, but that seems to work fine without any change.<br>
<br>
So, to recap: to avoid the problem, I think you should change the way<br>
you use the LLVM Disassembler API. When it's unable to disassemble a<br>
byte, ignore it and try again at the next one.  That's what most<br>
linear disassemblers do, and would correctly ignore the first REX<br>
prefix here.<br></blockquote><div><br><br></div><div>got it, thanks a lot!!!<br></div><div>Jun<br><br><br>
</div></div></div></div>