This is an archive of the discontinued LLVM Phabricator instance.

Fix for Bug 30718 - Failure to disassemble certain MOV with rex.R
ClosedPublic

Authored by avt77 on Oct 11 2017, 1:31 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

avt77 created this revision.Oct 11 2017, 1:31 AM
craig.topper added inline comments.Oct 13 2017, 9:36 AM
lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp
1487 ↗(On Diff #118557)

I think the correct fix is to change this to "if ((index & 0x7) > 5)" We shouldn't be resampling modRM.

avt77 added inline comments.Oct 16 2017, 4:30 AM
lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp
1487 ↗(On Diff #118557)

I thought about such a variant but on the other hand all other values of modRM could fail segment index. If you insist I'll use your variant of the fix but please say it again.

craig.topper added inline comments.Oct 16 2017, 11:49 AM
lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp
1487 ↗(On Diff #118557)

There are really two different versions of this function, one called with regFromModRM and one called with rmFromModRM. While I don't think the rmFromModRM version will ever be called with SEGMENT_REG, it feels wrong to assume which field of ModRM we should be using inside the routine.

We either need to mask the index inside the method, or the caller should mask it before the call.

avt77 added inline comments.Oct 17 2017, 5:14 AM
lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp
1487 ↗(On Diff #118557)

I tried your version but it does not work because there is the folowing code to invoke the function:

insn->reg = (Reg)fixupRegValue(insn,
                               (OperandType)op->type,
                               insn->reg - insn->regBase,
                               &valid);

It means we can't simply mask index here: we could check TYPE_SEGMENTREG at call time or we can use my approach. What's better? As I understand you'd prefer the caller masks the index properly, right?

avt77 updated this revision to Diff 119636.Oct 20 2017, 1:38 AM

I did changes accordingly to Craig's requirement: now it works (it seems there were problems with trunk updating).

This revision is now accepted and ready to land.Oct 20 2017, 7:07 PM
This revision was automatically updated to reflect the committed changes.