ExecutionEngine::create returns 0

What does it mean when ExecutionEngine::create returns 0?

Here's a simplified example:

#include "llvm/Module.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"

main()
{
  llvm::Module * module = new llvm::Module("the module");
  llvm::ExecutionEngine *ee = llvm::ExecutionEngine::create(module);
  fprintf(stdout, "pointer is %x.\n", ee);
}

I discovered this with a more complicated example in which I got
a segmentation fault the moment I tried to use the created execution
engine for anything.

In case they are relevant, here are the commands I used to comile the thing

g++ -o broken.o -c -I/farhome/hendrik/dv/llvm/llvm/include -I/farhome/hendrik/dv/llvm/obj/include -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -g -Woverloaded-virtual broken.cpp
g++ -o broken broken.o /farhome/hendrik/dv/llvm/obj/Debug/lib/LLVMExecutionEngine.o /farhome/hendrik/dv/llvm/obj/Debug/lib/LLVMJIT.o -L/farhome/hendrik/dv/llvm/obj/Debug/lib -lpthread -ldl -lm -lLLVMCore -lLLVMSupport -lLLVMSystem -lLLVMAnalysis -lLLVMTarget -lLLVMSystem -lLLVMAsmParser -lLLVMCodeGen -lLLVMCore -lLLVMSupport

-- hendrik

I got the toy.cpp program from Chapter 4 of the tutorial to compile, after
one change to line 359 from
   return ConstantFP::get(Type::DoubleTy, APFloat(Val));
to
   return ConstantFP::get(APFloat(Val));

Now to compare it in detail with the much smaller program I've got and
maybe I'll figure out what's wrong with my call to
ExecutionEngine::create.

-- hendrik

Now to compare it in detail with the much smaller program I've got and
maybe I'll figure out what's wrong with my call to
ExecutionEngine::create.

That call is perfectly valid, actually. It works for me when linked with:

g++ -o b b.o `llvm-config --ldflags` `llvm-config --libs engine jit`

Cheers,
-Mahadevan.

Thanks. It's compiling and executing now.

The story appears to be this:

  llvm::ExecutionEngine::create requires particular libraries (presumably
those that involve execution, JIT code generation, or interpretation) to
be linked into the executable (the executable that contains the call to
llvm::ExecutionEngine::create), or else it returns NULL. However,
llvm::ExecutionEngine::create does not itself contains references to
entry-points that would cause the necessary libraries to be sought by the
linker, so no linker failure results.

Would it be possible to include this information in the documentation for
llvm::ExecutionEngine::create?

-- hendrik

Hendrik Boom-2 wrote:

Now to compare it in detail with the much smaller program I've got and
maybe I'll figure out what's wrong with my call to
ExecutionEngine::create.

That call is perfectly valid, actually. It works for me when linked
with:

g++ -o b b.o `llvm-config --ldflags` `llvm-config --libs engine jit`

Cheers,
-Mahadevan.

Thanks. It's compiling and executing now.

The story appears to be this:

  llvm::ExecutionEngine::create requires particular libraries (presumably
those that involve execution, JIT code generation, or interpretation) to
be linked into the executable (the executable that contains the call to
llvm::ExecutionEngine::create), or else it returns NULL. However,
llvm::ExecutionEngine::create does not itself contains references to
entry-points that would cause the necessary libraries to be sought by the
linker, so no linker failure results.

Would it be possible to include this information in the documentation for
llvm::ExecutionEngine::create?

-- hendrik

_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

I am using llvm 2.6 and I am getting the same error. I tried using
llvm-config with flags '--libs core engine jit native'. But ExecutionEngine
returns NULL. I even tried including the JIT.h. No luck there too.

Here is my code listing:
        llvm::ExecutionEngine* ee = llvm::ExecutionEngine::create(mModule);
  llvm::Function* func = ee->FindFunctionNamed("main");
  typedef void (*PFN)();
  PFN pfn = reinterpret_cast<PFN> (ee->getPointerToFunction(func));
  pfn();
  delete ee;

thanks,
subramanyam

I am using llvm 2.6 and I am getting the same error. I tried using
llvm-config with flags '--libs core engine jit native'. But ExecutionEngine
returns NULL. I even tried including the JIT.h. No luck there too.

Here is my code listing:
       llvm::ExecutionEngine* ee = llvm::ExecutionEngine::create(mModule);
  llvm::Function* func = ee->FindFunctionNamed("main");
  typedef void (*PFN)();
  PFN pfn = reinterpret_cast<PFN> (ee->getPointerToFunction(func));
  pfn();
  delete ee;

More information would be helpful, if you have a program that someone else can compile or take a look at we might be able to help.

That said, 2.6 is pretty old at this point and I'm really only willing to look at failures with ToT. The HowToUseJIT example compiles and links just fine on ToT for me.

-eric

I am using Fedora 10 and I installed LLVM2.6 from binaries. I use gcc front-end(not Clang). Do I need to install something else, to be able to add JIT support?

I don't know, I don't package it.

I am able to compile HowToUseJIT example. The compilation command is
g++ -g -rdynamic toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 -o toy

But I am getting segmentation fault because of the NULL returned by ExecutionEngine::create(Module*) method.

Not surprising since you're dereferencing a NULL pointer.

Here is the error I get when I run HowToUseJIT example

Program received signal SIGSEGV, Segmentation fault.
0x080b02f6 in llvm::ExecutionEngine::getTargetData () at /home/subbu/llvm/install/include/llvm/ExecutionEngine/ExecutionEngine.h:167
167 const TargetData *getTargetData() const { return TD; }

Is that using 2.6 or something newer? My guess is that, of course, you don't have a target data. You'll need to debug why you can't seem to create one for your host. That said, if you can't get it to work with the 2.8 branch let me know.

-eric