从另一个文件定义的LLVM插入函数调用 [英] LLVM Insert function call defined from another file

查看:75
本文介绍了从另一个文件定义的LLVM插入函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在某个指令之前全部插入一个函数,但是该函数调用是在另一个文件中定义的.我尝试过

  IRBuilder<>生成器(pi);CallInst * callOne = Builder.CreateCall(func_ins,"foo"); 

其中 func_ins func *(或更一般地说是Value *),而 foo 是分配了调用函数的变量名前缀.由于此函数是在另一个文件中定义的,因此我不知道指针 func_ins 指向何处,因此我只是将其设置为 NULL ,但它不起作用.

任何人都可以给我一些有关如何解决此问题的提示吗?

另一个问题是,我可以使用 WriteBitcodeToFile 来转储具有对文件的外部函数调用的检测代码,因为我想知道它可能会在另一个模块中报告 Referencing函数或在执行模块检查时 Broken Module ?

解决方案

您只能从相同的 Module 调用函数,并且不能使用 NULL 作为被呼叫者.

如果函数是在另一个模块中定义的,则需要先在要进行调用的模块中声明,然后使用该声明进行调用.

要声明它,请在新模块中创建一个相同的函数(通过 Function :: Create ),而只是不为其指定一个正文.

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?

解决方案

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.

这篇关于从另一个文件定义的LLVM插入函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆