Skip to content
Snippets Groups Projects
Commit 9149ac72 authored by Nick Kledzik's avatar Nick Kledzik
Browse files

<rdar://problem/6941517> C++ static constructors not preserved for static executable using LTO

Move setRelocationModel() to be called before TargetMachine is instantiated.

llvm-svn: 72816
parent b48c6eb7
No related branches found
No related tags found
No related merge requests found
...@@ -304,6 +304,20 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) ...@@ -304,6 +304,20 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
if ( march == NULL ) if ( march == NULL )
return true; return true;
// The relocation model is actually a static member of TargetMachine
// and needs to be set before the TargetMachine is instantiated.
switch( _codeModel ) {
case LTO_CODEGEN_PIC_MODEL_STATIC:
TargetMachine::setRelocationModel(Reloc::Static);
break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
TargetMachine::setRelocationModel(Reloc::PIC_);
break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
TargetMachine::setRelocationModel(Reloc::DynamicNoPIC);
break;
}
// construct LTModule, hand over ownership of module and target // construct LTModule, hand over ownership of module and target
std::string FeatureStr = std::string FeatureStr =
getFeatureString(_linker.getModule()->getTargetTriple().c_str()); getFeatureString(_linker.getModule()->getTargetTriple().c_str());
...@@ -363,19 +377,6 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out, ...@@ -363,19 +377,6 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
if ( _target->getTargetAsmInfo()->doesSupportExceptionHandling() ) if ( _target->getTargetAsmInfo()->doesSupportExceptionHandling() )
llvm::ExceptionHandling = true; llvm::ExceptionHandling = true;
// set codegen model
switch( _codeModel ) {
case LTO_CODEGEN_PIC_MODEL_STATIC:
_target->setRelocationModel(Reloc::Static);
break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
_target->setRelocationModel(Reloc::PIC_);
break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
_target->setRelocationModel(Reloc::DynamicNoPIC);
break;
}
// if options were requested, set them // if options were requested, set them
if ( !_codegenOptions.empty() ) if ( !_codegenOptions.empty() )
cl::ParseCommandLineOptions(_codegenOptions.size(), cl::ParseCommandLineOptions(_codegenOptions.size(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment