我正在尝试编写具有以下目标的简单LLVM通过:
call
指令。作为示例,请考虑我有以下示例程序:
#include <stdio.h>
#include <stdlib.h>
int times_two(int val);
int main(int argc, char** argv) {
int arg_1 = atoi(argv[1]);
char test_str[] = "Test String";
int res = times_two(arg_1);
printf("%d", res);
return 0;
}
int times_two(int val) {
// ----> INSERT SOME EXTERNAL FUNCTION HERE <----
return val * 2;
}
这是我的LLVM工具的一部分:
/* Begin instrumentation
--------------------- */
for (auto &F : M)
{
for (auto &B : F)
{
for (auto &I : B)
{
IRBuilder<> builder(&I);
// Now we have reached a 'call' instruction
if (auto *CallInstr = dyn_cast<CallInst>(&I))
{
// Cast into Function pointer
Function *called_func = CallInstr->getCalledFunction();
errs() << called_func->getName() << "\n";
// loop into the function, getFirstInstruction, do stuff and break.
for (auto &bb_in_func : *called_func)
{
// Set an Insert point at the first
// line of the external function
BasicBlock::iterator insert_point = bb_in_func.getFirstInsertionPt();
builder.SetInsertPoint(&bb_in_func, insert_point);
// Make an external call
builder.CreateCall(extern1);
break;
}
}
}
}
}
但是,当我遍历模块中的所有功能时,此功能列表似乎也包含内置功能。在上述情况下,我得到以下信息:
atoi
llvm.memcpy.p0i8.p0i8.i64
times_two
printf
我如何忽略这些内置函数,仅考虑times_two?