【问题标题】:LLVM insert opcode before instructionLLVM 在指令前插入操作码
【发布时间】:2013-11-15 01:03:44
【问题描述】:

我想在 BasicBlock 终止符之前插入特定的操作码,在我的情况下是在 ReturnInst 之前。

有可能吗?

例子:

TerminatorInst* terminator = BasicBlock->getTerminator();
if (isa<ReturnInst>(terminator))  
{
//Insert opcode here.    
}

【问题讨论】:

    标签: llvm llvm-ir llvm-c++-api


    【解决方案1】:

    “操作码”我猜你的意思是“指令”。

    所有指令都有一个构造函数,它接收另一条指令作为其最后一个参数;该构造函数创建新指令,然后将其插入作为最后一个参数给出的指令之前,这正是您要查找的内容。

    有关这方面的更多信息,请参阅"creating and inserting new instruction" section of the user guide

    【讨论】:

    • 谢谢!我如何添加 LLVM (Instructions.h) 中不存在的指令?
    • @Denis 你能举个例子说明你想插入什么吗?
    • 简单,我想在ret之前插入nop(0x90)指令
    • @Denis 0x90 是 x86 二进制文件 中的 nop 指令,而不是 LLVM IR - 它们是两种不同的不同语言(尽管 you can embed assembly inside LLVM IR)。您可以查看the LLVM Language Reference manual 中所有 LLVM IR 指令的列表 - 特别是,那里没有 nop 指令。
    • 是的,我知道,有什么破解方法吗?
    【解决方案2】:

    使用 llvm::InlineAsm

    解决的问题
    llvm::InlineAsm *AsmCode = llvm::InlineAsm::get(Asm, nopInstruction, "", true, false, llvm::InlineAsm::AD_Intel);
    

    其中 Asm - llvm::FunctionType,nopInstruction - llvm::StringRef(char*)

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 2014-12-28
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多