This is an archive of the discontinued LLVM Phabricator instance.

[X86] Fix PR23271 - RIP-relative decoding bug in disassembler.
ClosedPublic

Authored by dougk on Apr 20 2015, 7:53 AM.

Details

Summary

REX.b and EVEX.x are not decoded when determining whether the addressing mode is RIP-relative.

Diff Detail

Repository
rL LLVM

Event Timeline

dougk updated this revision to Diff 24023.Apr 20 2015, 7:53 AM
dougk retitled this revision from to [X86] Fix PR23271 - RIP-relative decoding bug in disassembler..
dougk updated this object.
dougk edited the test plan for this revision. (Show Details)
dougk added a subscriber: Unknown Object (MLST).
dougk updated this revision to Diff 25695.May 13 2015, 8:22 AM
dougk updated this object.
dougk edited the test plan for this revision. (Show Details)
dougk added reviewers: m4b, delena.

Just mask the unwanted bits.

chandlerc accepted this revision.May 13 2015, 2:48 PM
chandlerc added a reviewer: chandlerc.
chandlerc added a subscriber: chandlerc.

Looks good with the test case changed as below.

test/MC/Disassembler/X86/x86-64.txt
327 ↗(On Diff #25695)

XFAIL doesn't work this way...

You only write one XFAIL per test file, and it fails the entire file.

I think you want to write the CHECKs as they are today, and as FIXME:s for what they should be.

This revision is now accepted and ready to land.May 13 2015, 2:48 PM
This revision was automatically updated to reflect the committed changes.
m4b edited edge metadata.May 13 2015, 4:27 PM

Besides inline comments, this looks good to me, as typical uses of RIP relative addressing seem to disassemble correctly now.

test/MC/Disassembler/X86/x86-64.txt
314 ↗(On Diff #25695)

I'm getting a #UD on this instruction.

Well, technically on: 62 11 5c 40 58 3d ff 7f ff ff, or vaddps -32769(%rip), %zmm20, %zmm15

I've attached both LLDB and GDB's output (LLDB doesn't use this patch yet, so it doesn't disassemble past the instruction).

Also GDB disassembles it differently from this patch, as it says the RIP relative immediate is -8001, but by my count it should be -32769 (which llvm-mc disassembles it to using this patch).

Note: I monkey-patched a C binary with the instruction, so it's not a proper compiled object, but it should at least execute/segfault; but I get an illegal instruction error on that exact instruction, so I think it's not the patching that's the problem.

Unfortunately I can't seem to find the source or a binary download for the xed program on Intel's website or anywhere, otherwise I'd try to get a "second opinion". Hopefully something else is going on, otherwise we might actually all have disassembler bugs to repair :)

m4b added a comment.May 14 2015, 7:19 AM

Ignore previous comment; I see now that the instruction #UD's because they haven't made/released processors which implement EVEX prefixes yet, so all's right with the world ;)

Carry on!