A question about calling external function in JIT

Hello Sir,

My name is Wei-Fan Chiang.
I am now a graduated student of U. of Utah.
I have a question about call external function in JIT.

Suppose I have a simple program:

int main (int argc, char *argv[]) {
     int i = 2, j = 3, k;
     k = foo(2, 3);
     return 0;

"foo" is an external function (non-native function define in dynamic library) made by us.
In JIT, we just need to natively execute foo and pass the result back. That means, we want to treat "foo(2, 3)" as a constant while doing JIT.

Is it possible?



Hi Wei-Fan,

It is possible to reference an external function from JITed code. You
can use the llvm::sys::DynamicLibrary routines to load your dynamic
library. After loading the library, the JIT engine should be able to
locate 'foo'.


Hello Jeff,

Many thanks for your help!!
I successfully load a function in a dynamic library by using
sys::DynamicLibrary routines.


But I still have another question:
How if 'foo' is defined in a static library ??
Is it possible not compiling the static libraries by llvm and natively call
functions in them?

I'm not sure I understand the question. I understand that you want to
call 'foo' from JIT, and that you have figured out how to do this if
'foo' is in a dynamic library. You now want to use a static library
instead? I'm not sure if that's possible, unless by static library
you mean a bitcode file. In that case, you can link the bitcode
library to your code before JIT (e.g. using llvm-link or llvm-ld), or
you can essentially do the same thing manually in your code. This was
discussed in a previous thread (http://bit.ly/oYbbsD).