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

Vikram S. Adve vadve at uiuc.edu
Fri Dec 7 22:29:27 PST 2007

Assuming the run-time library is in C, is there a reason why you  
cannot also compile that to LLVM?  You could get significantly better  
optimization via LTO that way.


On Dec 8, 2007, at 12:12 AM, Chris Lattner wrote:

> 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
> _______________________________________________
> 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