[LLVMdev] X86 JIT

Eric Rannaud eric.rannaud at gmail.com
Tue Jun 23 11:56:24 PDT 2009

On Tue, Jun 23, 2009 at 02:31:36AM -0700, Eric Rannaud wrote:
> On Mon, Jun 22, 2009 at 4:43 PM, Chris Lattner <clattner at apple.com>
> wrote:
> I do not quite understand why, but it appears that the constructor of
> the static variable
> static struct RegisterJIT {
>   RegisterJIT() { JIT::Register(); }
> } JITRegistrator;
> in lib/ExecutionEngine/JIT/JIT.cpp is only called if either JIT.h or
> Interpreter.h is included. When they are not included, JIT::Register()
> is not called, and ExecutionEngine::JITCtor and
> ExecutionEngine::InterpCtor are both NULL, and ExecutionEngine::create()
> returns NULL.
> ...
> This is quite nasty behavior. I don't know what the proper fix is, but
> relying on static constructors seems misplaced. And certainly, a missing
> header should not result in a runtime fault.

So, at a minimum, JITRegistrator and InterpRegistrator should not have
static linkage. But that is still not enough. As they both are in a
static library (libLLVMJIT.a and libLLVMInterpreter.a), to appear in the
final 'lli' binary all the time, the linker flag --whole-archive needs
to be used (see ld(1)). Without the flag, JITRegistrator and
InterpRegistrator are only included if the .o they live in (JIT.o and
Interpreter.o) are used. This becomes very obscure.

I would personally fix this by getting rid of global variable
constructors for initialization purposes. Otherwise, I'm not sure where
such a linker flag should be added. It would also need to be added to
`llvm-config --ldflags`.


More information about the llvm-dev mailing list