[llvm-dev] Problems using LLVM as a disassembler.

James Courtier-Dutton via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 3 05:43:15 PDT 2018


Hi,

I have been trying to use LLVM as a disassembler, thus providing a
small part of my decompiler that I am working on.
It currently decompiles from X86_64 binary.o -> LLVM IR.
It works with a small set of test programs so far, so cannot currently
handle large binary programs yet.

The problem is with the LLVM "getInstruction()" method.
It used to have a PC (program counter) parameter that worked. You
could use the PC as an offset within the buffer to start disassembling
from.
In LLVM 4.0 and above the only value of the PC parameter that works is zero.
Please can someone look into fixing this?

Kind Regards

James

P.S. Example code below:


    TripleName = "x86_64-pc-linux-gnu";
    // Get the target.
    std::string Error;
    DecodeAsmX86_64::TheTarget =
llvm::TargetRegistry::lookupTarget(TripleName, Error);
    if (!TheTarget)
        return 1;
...
//  Set up disassembler.
    DisAsm = TheTarget->createMCDisassembler(*STI, *Ctx);
    if (!DisAsm)
        return 1;
...
//  S = DisAsm->getInstruction(*Inst, Size, Bytes_A, PC,
//      /*REMOVE*/ nulls(), nulls());
//  Latest LLVM messes up with the PC set to anything other than zero
    S = DisAsm->getInstruction(*Inst, Size, Bytes_A, 0,
        /*REMOVE*/ nulls(), nulls());


More information about the llvm-dev mailing list