[LLVMdev] Having JIT resolve extern "C" functions declared in executible

Carter Cheng carter_cheng at yahoo.com
Thu Jul 2 05:30:22 PDT 2009

Hi John,

Thanks. I was considering pursuing option 2) initially but also started thinking about option 1) and I suspect with that hint I will be able to figure it out. Thanks.



--- On Thu, 7/2/09, John McCall <rjmccall at apple.com> wrote:

> From: John McCall <rjmccall at apple.com>
> Subject: Re: [LLVMdev] Having JIT resolve extern "C" functions declared in executible
> To: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu>
> Date: Thursday, July 2, 2009, 2:06 AM
> On Jul 2, 2009, at 1:05 AM, Carter
> Cheng wrote:
> > I am having some difficulties getting the LLVM JIT to
> resolve extern  
> > "C" functions which I have defined in source file and
> invoking them  
> > via EE::runFunction() after generating a Function
> prototype for it.  
> > Is this possible or do I need to generate a .so for my
> functions are  
> > link against it?
> If the JIT needs a pointer to a function, and that function
> has no  
> body, it'll ask the ModuleProvider to materialize the
> function.  If  
> the MP returns false, it'll just ask the dynamic linker for
> the  
> function with that name.  If no such function is
> linked into your  
> program, then the JIT will just give up.  So you have
> three options:
> (1)  You can circumvent this entire process by giving
> the JIT an  
> explicit pointer to the function using
> JIT::addGlobalMapping().   
> Obviously this requires the function to be compiled and
> linked into  
> your program.
> (2)  You can compile and link the function into your
> program in such a  
> way that the dynamic linker will find it.
> (3)  You can give the JIT a custom module provider
> which somehow  
> materializes IR for the given function.
> The highest-performance option is probably #1, but #2 can
> be more  
> convenient.  If the code is totally static, I see no
> reason to do #3  
> unless you really need the IR (e.g. if you want to inline
> the function).
> Is that what you were asking?
> John.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu 
>        http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


More information about the llvm-dev mailing list