X86 JIT

Hi,

for some reason I could not get the machine code generator for x86 working. The interpreter is the only thing that works, is there anything that I am missing here?

– Kasra |

This recently changed. In your main program, please #include “llvm/Target/TargetSelect.h” and call InitializeNativeTarget(); before setting up the execution engine,

-Chris

Actually, you also need to include:

#include <llvm/ExecutionEngine/JIT.h>
or
#include <llvm/ExecutionEngine/Interpreter.h>

If not, you can get a segfault.

To reproduce, apply:

Index: tools/lli/lli.cpp

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`.

Thanks,
Eric.

ExecutionEngine::create() can return NULL with an empty error message
(admittedly, it did so because of global variable initialization
problems). The code currently lets NULL go through if ErrorMsg is empty,
and segfaults later.

When EE is NULL but ErrorMsg is empty, simply do not try to
print it and exit.

Index: tools/lli/lli.cpp

ExecutionEngine::create() can return NULL with an empty error message
(admittedly, it did so because of global variable initialization
problems). The code currently lets NULL go through if ErrorMsg is empty,
and segfaults later.

When EE is NULL but ErrorMsg is empty, simply do not try to
print it and exit.

Nice catch. Please send patches as attachments so that they don't word wrap or get mangled by your mailer. Since it is small, I manually applied this patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090706/080247.html

Thanks!

-Chris