diff --git a/driver/main.cpp b/driver/main.cpp index 3ed1d247..9f3d6ab5 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -547,7 +547,7 @@ int main(int argc, char** argv) VersionCondition::addPredefinedGlobalIdent("D_LP64"); } - if (mRelocModel == llvm::Reloc::PIC_) { + if (gTargetMachine->getRelocationModel() == llvm::Reloc::PIC_) { VersionCondition::addPredefinedGlobalIdent("D_PIC"); } diff --git a/driver/target.cpp b/driver/target.cpp index 416e7230..5c85bea0 100644 --- a/driver/target.cpp +++ b/driver/target.cpp @@ -175,6 +175,13 @@ llvm::TargetMachine* createTargetMachine( FeaturesStr = Features.getString(); } + if (triple.isMacOSX() && relocModel == llvm::Reloc::Default) + { + // OS X defaults to PIC (and as of 10.7.5/LLVM 3.1-3.3, TLS use leads + // to crashes for non-PIC code). LLVM doesn't handle this. + relocModel = llvm::Reloc::PIC_; + } + #if LDC_LLVM_VER == 300 llvm::NoFramePointerElim = genDebugInfo;