[LLVMdev] Calling functions defined in .o files in LLVM code executed in lli

Chris Lattner sabre at nondot.org
Fri Dec 7 22:12:02 PST 2007


On Dec 7, 2007, at 6:38 AM, John van Schie wrote:

> Hi,
>
> This is probably an easy question, but I could not find the answer  
> to it.
>
> I'm working on a LLVM back-end for the EHC compiler (a Haskell
> compiler). Currently there is a C back-end and I would like to reuse  
> the
> primitive library functions from this back-end.

Ok.
>

> So I have compiled C sources in a .o file and I would like to call  
> these
> from my LLVM code. If I declare these primitive functions in the LLVM
> code and link the bitcode file and the .o file with llvm-ld it works
> only if I generate native code. If I omit the -native flag to llvm-ld
> and execute the generated shell script a.out I get the following  
> error:
>
> glimi at brodie:~$ llvm-ld ../../prim.o TestExist.bc && ./a.out

This fails because "a.out" is a shell script that is invoking the JIT.

> Is there a way to link the functions declared in the .o file in the
> bitcode without compiling the C sources with llvm-gcc?

Yes, certainly.  If you want the JIT to work, you need to link your .o  
files together into a .so/.dylib file, then use the 'lli -load  
foo.dylib' option to load it.  If you want to natively link your  
application together, just toss your .o files on the native link line.

-Chris



More information about the llvm-dev mailing list