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 Function*
(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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With