[llvm-dev] setDataLayout segfault
Jonathan Roelofs via llvm-dev
llvm-dev at lists.llvm.org
Wed Sep 14 10:02:36 PDT 2016
On 9/14/16 10:23 AM, Frank Winter via llvm-dev wrote:
> Ok. I can make a copy of the unique_ptr before moving it into the
> builder's constructor and use the copy later on. It is confusing to
> require a unique_ptr.
It's (almost?) always a bad idea to make a copy of a std::unique_ptr.
>
> Frank
>
> On 09/14/2016 12:11 PM, Frank Winter via llvm-dev wrote:
>> I am constructing the engine builder in the following way:
>>
>> llvm::SMDiagnostic Err;
>> unique_ptr<Module> Mod = getLazyIRFileModule("f.ll", Err, TheContext);
>> llvm::EngineBuilder engineBuilder(std::move(Mod));
>>
>> However, after moving the pointer to the constructor it is no longer
>> retrievable from the unique_ptr object.
Moving re-assigns ownership of the pointed-to memory to the EngineBuilder.
>>
>> Mod.get()->dump(); // this segfaults after the move, but not before
That is expected.
>>
>> So I conclude that any type of operation on the module is no longer
>> valid.
Correction: any operation via the *moved* unique_ptr is no longer valid.
>>
>> Am I constructing the engine builder as it is supposed to?
>>
>> Frank
>>
>>
>> On 09/14/2016 10:59 AM, Frank Winter via llvm-dev wrote:
>>> I get a segfault with this code when setting the data layout:
>>>
>>>
>>>
>>> int main(int argc, char** argv)
>>> {
>>> llvm::InitializeNativeTarget();
>>>
>>> llvm::LLVMContext TheContext;
>>> unique_ptr<Module> Mod(new Module("A",TheContext));
>>>
>>> llvm::EngineBuilder engineBuilder(std::move(Mod));
>>> std::string mcjit_error;
>>>
>>> engineBuilder.setMCPU(llvm::sys::getHostCPUName());
>>>
>>> engineBuilder.setEngineKind(llvm::EngineKind::JIT);
>>> engineBuilder.setOptLevel(llvm::CodeGenOpt::Aggressive);
>>> engineBuilder.setErrorStr(&mcjit_error);
>>>
>>> llvm::TargetOptions targetOptions;
>>> targetOptions.AllowFPOpFusion = llvm::FPOpFusion::Fast;
>>> engineBuilder.setTargetOptions( targetOptions );
>>>
>>> TargetMachine *targetMachine = engineBuilder.selectTarget();
>>>
>>> assert(targetMachine && "failed to create target machine");
>>>
>>> std::cout <<
>>> targetMachine->createDataLayout().getStringRepresentation() << "\n";
>>>
>>> Mod.get()->setDataLayout(
>>> targetMachine->createDataLayout().getStringRepresentation() ); //
>>> this segfaults
>>> Mod.get()->setDataLayout( targetMachine->createDataLayout() ); //
>>> as well as this
>>> }
>>>
>>>
>>> Backtrace:
>>>
>>>
>>> Using host libthread_db library
>>> "/lib/x86_64-linux-gnu/libthread_db.so.1".
>>> e-m:e-i64:64-f80:128-n8:16:32:64-S128
>>>
>>> Program received signal SIGSEGV, Segmentation fault.
>>> 0x00007ffff5f65832 in llvm::SmallVectorTemplateCommon<unsigned char,
>>> void>::end (this=0x148) at
>>> /home/fwinter/svn/llvm-3.9/include/llvm/ADT/SmallVector.h:117
>>> 117 iterator end() { return (iterator)this->EndX; }
>>> (gdb) bt
>>> #0 0x00007ffff5f65832 in llvm::SmallVectorTemplateCommon<unsigned
>>> char, void>::end (this=0x148) at
>>> /home/fwinter/svn/llvm-3.9/include/llvm/ADT/SmallVector.h:117
>>> #1 llvm::SmallVectorImpl<unsigned char>::clear (this=0x148) at
>>> /home/fwinter/svn/llvm-3.9/include/llvm/ADT/SmallVector.h:345
>>> #2 0x00007ffff5fa13b5 in llvm::DataLayout::clear (this=0x138) at
>>> /home/fwinter/svn/llvm-3.9/lib/IR/DataLayout.cpp:545
>>> #3 0x00007ffff5f9f561 in llvm::DataLayout::reset (this=0x138,
>>> Desc=...) at /home/fwinter/svn/llvm-3.9/lib/IR/DataLayout.cpp:179
>>> #4 0x00007ffff60b25ca in llvm::Module::setDataLayout (this=0x0,
>>> Desc=...) at /home/fwinter/svn/llvm-3.9/lib/IR/Module.cpp:377
>>> #5 0x0000000000406c46 in main (argc=1, argv=0x7fffffffde68) at
>>> main.cc:95
>>>
>>>
>>> Any idea?
>>>
>>> Frank
>>>
>>>
>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded
More information about the llvm-dev
mailing list