LLVM Insert function call defined from another file

家住魔仙堡 提交于 2021-02-18 17:15:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!