[LLVMdev] Forcing the Interpreter segfaults

Salomon Brys salomon.brys at gmail.com
Tue Nov 2 11:51:19 PDT 2010


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 !

Salomon BRYS.

-- 
###########################################
# Salomon BRYS
# +33 (0) 6 83 54 55 96
#------------------------------------------
# > EPITECH "Koala" : C++ assistant : Sbire du C++
# > Zend Certified Engineer for PHP5
#------------------------------------------
# All data in this e-mail is confidential.
# If you are not, or if you don't believe you are, the recipient of this
e-mail, please delete it.
#------------------------------------------
# GPG : http://gpgkey-salomon.antesocial.fr/
###########################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101102/334e70a4/attachment.html>


More information about the llvm-dev mailing list