[LLVMdev] lli problem with a simple OpenGL

Tim Northover t.p.northover at gmail.com
Sat Jan 26 10:22:41 PST 2013


Hi,

> But, adding the -emit-llvm option to clang, does not work as below
> $ clang -O3 -emit-llvm simple.c  -o simple.bc -lglut
> /usr/bin/ld: /usr/local/bin/../lib/LLVMgold.so: error loading plugin
> /usr/bin/ld: /usr/local/bin/../lib/LLVMgold.so: error in plugin cleanup (ignored)
> clang: error: linker command failed with exit code 1 (use -v to see invocation)

What Clang is actually trying to do here is generate a .bc (LLVM IR)
file and feed that into the linker to produce a final fully native
output (which you happen to have decided should be called simple.bc --
it's still going to be an ELF file). Since linkers don't natively
understand LLVM's IR, this needs a plugin which calls back to LLVM for
some of the work. That's the LLVMgold.so plugin it's referring to.

My guess is that it doesn't exist on your machine; compiling it would
require extra effort.

If you want a .bc containing LLVM IR, give clang the "-c" ("compile
only") option (and not -lglut, though it'll be harmless). Then it
won't bother trying to link.

> Also, removing the -lglut option worked with clang but failed with lli as below
> $ clang -O3 -emit-llvm simple.c -c -o simple.bc
> $ lli simple.bc
> LLVM ERROR: Program used external function 'glutInit' which could not be resolved!
>
> Please advice how to run it using the llvm jit 'lli'

The problem here is that lli looks inside its own dynamic context for
functions referenced externally. I couldn't see an option to lli which
will make it load a specified dynamic library. Someone else may reply
with one I've missed of course. I suppose if you were creating your
own JIT compiler you'd want to handle that yourself anyway.

A hack that worked for me was to tell the system itself to load the
required library, rather than lli:

$ LD_PRELOAD=/usr/lib/libglut.so lli -use-mcjit simple.bc

Hope this helps.

Tim.



More information about the llvm-dev mailing list