问题
I want to insert a function all before a certain instruction but the function call is defined in another file. I tried
IRBuilder<> Builder(pi);
CallInst *callOne = Builder.CreateCall(func_ins, "foo");
where func_ins
is func*(or Value* to be more general)
and foo
is the variable name prefix of calling function got assigned.
Since this function is defined in another file I've no idea where the pointer func_ins
should point to so I just set it to NULL but it didn't work.
Can anyone give me some hints on how to resolve this problem?
One more issue is can I use WriteBitcodeToFile
to dump the instrumented code which has external function call to file because I‘m wondering it may report Referencing function in another module
or Broken Module
while performing module checking?
回答1:
You may only call a function from the same Module
, and you may not use NULL
as the callee.
If the function is defined in another module, you need to first declare it in the module in which you want to make the call, then make the call using the declaration.
To declare it, create an identical function in the new module (via Function::Create) and just don't assign it a body.
来源:https://stackoverflow.com/questions/24331498/llvm-insert-function-call-defined-from-another-file