【发布时间】:2017-04-28 21:18:33
【问题描述】:
让x 是运行时程序中全局变量g 的地址。 LLVM IR 生成如下所示的存储指令:
store i32 30, i32* @g, align 4
我正在编写一个 LLVM pass,它将检测程序,以便在运行时将 x 传递给检测函数 func(int addr)。我可以使用IRBuilder 成功插入对func 的呼叫。我无法做的是插入仪器来收集x。
if (StoreInst *store_inst = dyn_cast<StoreInst>(&I)) {
Value* po = store_inst->getPointerOperand();
if(isa<GlobalVariable>(po)) {
errs() << "store [pointer]: " << *po << '\n';
Constant *instrument_func = F.getParent()->getOrInsertFunction("func", Type::getVoidTy(Ctx), Type::getInt32Ty(Ctx), NULL);
IRBuilder<> builder(&I);
builder.SetInsertPoint(&B, ++builder.GetInsertPoint());
Value* args[] = {po};
builder.CreateCall(instrument_func, args);
}
}
运行opt的结果是:
Call parameter type does not match function signature!
i32* @a
i32 call void bitcast (void (i64)* @func to void (i32)*)(i32* @a)
LLVM ERROR: Broken function found, compilation aborted!
【问题讨论】:
-
@g是x。在 C 或 C++ 程序中,g的值是load @g。
标签: llvm llvm-clang llvm-ir