Hi!
I want to know if it is possible to link llvm object
files with native static/shared libraries. I mean:
without using the provided c/c++ frontend to compile
first the sources of the libraries to llvm and then
-everything being llvm- linking. For example, I would
like to compile XLanguage to llvm and then link the
resulting object against libXRuntime.so. If this can
be done, could you give me a clue?
Thank you in advance.
Regards,
Carlos.
I want to know if it is possible to link llvm object files with native
static/shared libraries.
Absolutely, we do this routinely.
I mean: without using the provided c/c++ frontend to compile first the
sources of the libraries to llvm and then -everything being llvm-
linking. For example, I would like to compile XLanguage to llvm and then
link the resulting object against libXRuntime.so. If this can be done,
could you give me a clue? Thank you in advance. Regards, Carlos.
Yes, this is no problem. You can do something like this:
$ llvmgcc X.c -c -o X.bc
$ llc X.bc -o X.s [or use the C backend at your choice)
$ gcc Y.c -o Y.o -c
$ gcc X.s Y.o -o program
$ ./program
-Chris
Yes, this is no problem. You can do something like
this:$ llvmgcc X.c -c -o X.bc
$ llc X.bc -o X.s
$ gcc Y.c -o Y.o -c
$ gcc X.s Y.o -o program
$ ./program
Ok, fine, and what about the interpreter? It takes
100% llvm, doesn't it? Or is there some kind of import
facility (perhaps as an specially interpreted call or
as an extension to llvm which makes the intrepreter
dlopen the lib and map unresolved symbols in the llvm
to those exported by the lib)?
Thank you again.
Regards,
Carlos.
The tool is `lli' but it serves a dual purpose: it is *both* an
interpreter and a JIT (just-in-time) compiler. On architectures that we
have JIT support for (x86 and Sparc), it is orders of magnitude faster.
Having said that, yes, there is importa facility for loading dynamica
libraries, e.g.
% lli -load=/usr/lib/libfunky.so program.bc
This will run the `program.bc' file and attempt to resolve references in
the .so file provided. You can specify multiple such libraries, e.g.:
% lli -load=/usr/lib/libfoo.so \
-load=/usr/lib/libbar.so program.bc
If you run the compiler llvmgcc as follows:
% llvmgcc program.c -L/usr/lib -lfoo -lbar -o program
then (assuming libfoo.so and libbar.so are in /usr/lib), you will get
two files generated:
1. program.bc -- the compiled, optimized, 100% LLVM bytecode
2. program -- a shell script for running lli on program.bc and loading
shared libraries that you specified
This means you can run the program as follows:
% ./program
HTH,