[LLVMdev] Forcing the Interpreter segfaults

OvermindDL1 overminddl1 at gmail.com
Tue Nov 2 12:00:43 PDT 2010


Helps to send to list:

On Tue, Nov 2, 2010 at 1:00 PM, OvermindDL1 <overminddl1 at gmail.com> wrote:
> On Tue, Nov 2, 2010 at 12:51 PM, Salomon Brys <salomon.brys at gmail.com> wrote:
>> Hi everyone !
>> I am very new to LLVM and intent to use it in a research project.
>> I have a problem with the interpreter: I have a simple compiler that
>> generates LLVM bitcode, JIT it and execute it, and it works very well.
>> Now I would like to execute it using the interpreter. And I get a segfault.
>> Here is the code :
>> // This code JIT the function and executes it
>> llvm::InitializeNativeTarget();
>> llvm::ExecutionEngine * EJ  = llvm::ExecutionEngine::create(&nM);
>> typedef int (*REFunc)(const char *);
>> union { void * obj; REFunc func; } u;
>> u.obj = EJ->getPointerToFunction(func);
>> REFunc jit = u.func;
>> int ret = jit("aaa");
>> std::cout << std::endl << ret << std::endl;
>> // This code interprets the function
>> llvm::initializeCore();
>> llvm::ExecutionEngine * EI  =
>> llvm::EngineBuilder(&M).setEngineKind(llvm::EngineKind::Interpreter).create();
>> EI->runStaticConstructorsDestructors(false);
>> std::vector<llvm::GenericValue> args;
>> llvm::GenericValue arg1((void*)"aaabc");
>> args.push_back(arg1);
>> llvm::APInt res = EI->runFunction(func, args).IntVal;
>> llvm::outs() << res << "\n";
>> The first block of code works very well and write the expected result.
>> The second block segfaults on the EI->runFunction(func, args) call.
>> I can't find my mistake. Would somebody help me on this ???
>> Thank you very much !
>
> The interpreter is probably broken.  Since the JIT became stable the
> interpreter is falling to bitrot, so it is better not to use it, just
> use the JIT.  Why do you need the interpreter anyway if the JIT is
> working for you?
>




More information about the llvm-dev mailing list