edA-qa mort-ora-y via llvm-dev
2016-Jun-11 09:29 UTC
[llvm-dev] SegFault creating a ExecutionEngine
My code to create an ExecutionEngine is segfaulting: std::string errStr; llvm::ExecutionEngine * ee = llvm::EngineBuilder( unique_ptr<llvm::Module>(module) ) .setErrorStr( &errStr ) //line 1618 .setEngineKind( llvm::EngineKind::JIT ) Where module is a `llvm::Module*`. This is code I'm migrating from 3.3 to 3.8. Since the deletion error is happening during constructor I'm at a bit of a loss as to what I'm doing wrong. The stack trace from gdb is: #0 0x00007ffff1195a02 in llvm::SmallPtrSetImplBase::isSmall (this=0x0) at /opt/llvm/include/llvm/ADT/SmallPtrSet.h:128 #1 0x00007ffff11e37d3 in llvm::SmallPtrSetImplBase::erase_imp (this=0x0, Ptr=0x68c200) at /opt/llvm/lib/Support/SmallPtrSet.cpp:78 #2 0x00007ffff14c9174 in llvm::SmallPtrSetImpl<llvm::Module*>::erase (this=0x0, Ptr=0x68c200) at /opt/llvm/include/llvm/ADT/SmallPtrSet.h:275 #3 0x00007ffff14c81cb in llvm::LLVMContext::removeModule (this=0x691910, M=0x68c200) at /opt/llvm/lib/IR/LLVMContext.cpp:148 #4 0x00007ffff1527b7b in llvm::Module::~Module (this=0x68c200, __in_chrg=<optimised out>) at /opt/llvm/lib/IR/Module.cpp:57 #5 0x00007ffff70f9511 in std::default_delete<llvm::Module>::operator() (this=<optimised out>, __ptr=0x68c200) at /usr/include/c++/5/bits/unique_ptr.h:76 #6 std::unique_ptr<llvm::Module, std::default_delete<llvm::Module>>::~unique_ptr (this=<optimised out>, __in_chrg=<optimised out>) at/usr/include/c++/5/bits/unique_ptr.h:236 #7 0x00007ffff26318ba in llvm::EngineBuilder::~EngineBuilder (this=0x7fffffffced0, __in_chrg=<optimised out>) at /opt/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h:512 #8 0x00007ffff70f75a1 in ir_llvm::gen::create_engine (this=this at entry=0x7fffffffd1d0) at src/ir/llvm/gen.cpp:1618 #9 0x00007ffff70f7757 in ir_llvm::gen::execute (this=this at entry=0x7fffffffd1d0, m=..., sc="") at src/ir/llvm/gen.cpp:252 #10 0x000000000041736b in runner::execute (this=this at entry=0x7fffffffdbc0, m=std::shared_ptr (count 2, weak 0) 0x682200) at src/bin/leaf.cpp:544 #11 0x0000000000415ac8 in main (argc=3, argv=0x7fffffffdde8) at src/bin/leaf.cpp:265 -- edA-qa mort-ora-y http://mortoray.com/ Leaf - the language we always wanted http://leaflang.org/
edA-qa mort-ora-y via llvm-dev
2016-Jun-11 09:35 UTC
[llvm-dev] SegFault creating a ExecutionEngine
A small correction, the code to create looks like this: llvm::ExecutionEngine * ee = llvm::EngineBuilder( unique_ptr<llvm::Module>(module) ) .setErrorStr( &errStr ) //line 1618 .setEngineKind( llvm::EngineKind::JIT ) .setTargetOptions( topts ) .create(); I presume the exception actually happens on the `create` line, but GDB is reporting the line marked 1618. On 11/06/16 11:29, edA-qa mort-ora-y wrote:> My code to create an ExecutionEngine is segfaulting: > > std::string errStr; > llvm::ExecutionEngine * ee = llvm::EngineBuilder( > unique_ptr<llvm::Module>(module) ) > .setErrorStr( &errStr ) //line 1618 > .setEngineKind( llvm::EngineKind::JIT ) > > Where module is a `llvm::Module*`. This is code I'm migrating from 3.3 > to 3.8. Since the deletion error is happening during constructor I'm at > a bit of a loss as to what I'm doing wrong. > > The stack trace from gdb is: > > #0 0x00007ffff1195a02 in llvm::SmallPtrSetImplBase::isSmall (this=0x0) > at /opt/llvm/include/llvm/ADT/SmallPtrSet.h:128 > #1 0x00007ffff11e37d3 in llvm::SmallPtrSetImplBase::erase_imp > (this=0x0, Ptr=0x68c200) at /opt/llvm/lib/Support/SmallPtrSet.cpp:78 > #2 0x00007ffff14c9174 in llvm::SmallPtrSetImpl<llvm::Module*>::erase > (this=0x0, Ptr=0x68c200) at /opt/llvm/include/llvm/ADT/SmallPtrSet.h:275 > #3 0x00007ffff14c81cb in llvm::LLVMContext::removeModule > (this=0x691910, M=0x68c200) at /opt/llvm/lib/IR/LLVMContext.cpp:148 > #4 0x00007ffff1527b7b in llvm::Module::~Module (this=0x68c200, > __in_chrg=<optimised out>) at /opt/llvm/lib/IR/Module.cpp:57 > #5 0x00007ffff70f9511 in std::default_delete<llvm::Module>::operator() > (this=<optimised out>, __ptr=0x68c200) at > /usr/include/c++/5/bits/unique_ptr.h:76 > #6 std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >> ::~unique_ptr (this=<optimised out>, __in_chrg=<optimised out>) at > /usr/include/c++/5/bits/unique_ptr.h:236 > #7 0x00007ffff26318ba in llvm::EngineBuilder::~EngineBuilder > (this=0x7fffffffced0, __in_chrg=<optimised out>) at > /opt/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h:512 > #8 0x00007ffff70f75a1 in ir_llvm::gen::create_engine > (this=this at entry=0x7fffffffd1d0) at src/ir/llvm/gen.cpp:1618 > #9 0x00007ffff70f7757 in ir_llvm::gen::execute > (this=this at entry=0x7fffffffd1d0, m=..., sc="") at src/ir/llvm/gen.cpp:252 > #10 0x000000000041736b in runner::execute > (this=this at entry=0x7fffffffdbc0, m=std::shared_ptr (count 2, weak 0) > 0x682200) at src/bin/leaf.cpp:544 > #11 0x0000000000415ac8 in main (argc=3, argv=0x7fffffffdde8) at > src/bin/leaf.cpp:265 >-- edA-qa mort-ora-y http://mortoray.com/ Leaf - the language we always wanted http://leaflang.org/
Tim Northover via llvm-dev
2016-Jun-11 14:54 UTC
[llvm-dev] SegFault creating a ExecutionEngine
On 11 June 2016 at 02:29, edA-qa mort-ora-y via llvm-dev <llvm-dev at lists.llvm.org> wrote:> #4 0x00007ffff1527b7b in llvm::Module::~Module (this=0x68c200, > __in_chrg=<optimised out>) at /opt/llvm/lib/IR/Module.cpp:57The EngineBuilder shouldn't be trying to destroy the module. Looking at EngineBuilder::create's control flow, the most plausible problem is that the TargetMachine is null, so EngineBuilder::selectTarget has gone wrong. If so, maybe the Module's triple is wrong or your LLVM is compiled strangely so no targets can be found? Either way, it's probably time to pull out the debugger. Tim.
edA-qa mort-ora-y via llvm-dev
2016-Jun-11 15:59 UTC
[llvm-dev] SegFault creating a ExecutionEngine
On 11/06/16 16:54, Tim Northover wrote:> The EngineBuilder shouldn't be trying to destroy the module. Looking > at EngineBuilder::create's control flow, the most plausible problem is > that the TargetMachine is null, so EngineBuilder::selectTarget has > gone wrong. If so, maybe the Module's triple is wrong or your LLVM is > compiled strangely so no targets can be found? Either way, it's > probably time to pull out the debugger. Tim.I'm not sure I've passed an invalid value; I've changed my code to not delete the engine builder and it works: auto ebuild = new llvm::EngineBuilder( unique_ptr<llvm::Module>(module) ); llvm::ExecutionEngine * ee = ebuild-> setErrorStr( &errStr ). setEngineKind( llvm::EngineKind::JIT ). setTargetOptions( topts ). create(); My code then runs fine. This is pointing towards destruction of the `EngineBuilder` itself causing the problem (like it's deleting the module although it shouldn't, since it's been given to the created `ExecutionEngine`). -- edA-qa mort-ora-y http://mortoray.com/ Leaf - the language we always wanted http://leaflang.org/