[LLVMdev] [Help] How can we call an object's virtual function inside IR?
kennethuil at gmail.com
Wed Jan 6 04:38:55 PST 2010
On Wed, Jan 6, 2010 at 4:39 AM, Duncan Sands <baldrick at free.fr> wrote:
> Hi Gyounghwa Kim,
>> First of all, thank you very much for your answer.
>> I tried your sugestion and found out that it is not what I wanted.
>> What I have to do is call a native C function from inside this
>> generated function.
>> Is there any way that we can find and call native C functions not
>> created by LLVM IR?
> You can insert a declaration of the function into the IR, then call
> it. Of course, for this to work you need to link in the native function
> when running. If you are building a standalone application then this
> is no problem. If you are running the IR using the JIT then it is also
> possible, hopefully someone else will explain how.
If you are running the IR using the JIT:
1. If the function is exported from the executable itself, or if it is
in a static library linked with the executable using the -rdynamic
flag, then you can insert a declaration of the function into the IR
and then call it.
2. Otherwise, you can insert a declaration of the function into the
IR, call ExecutionEngine::addGlobalMapping with the llvm::Function
object and a native function pointer to link the declaration to the
actual function, and then call it.
More information about the llvm-dev