diff --git a/dmd2/mtype.c b/dmd2/mtype.c index 45e596da..4fb13713 100644 --- a/dmd2/mtype.c +++ b/dmd2/mtype.c @@ -82,28 +82,24 @@ int REALSIZE = 16; int REALPAD = 6; int REALALIGNSIZE = 16; #elif TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS -int REALSIZE = 12; // LDC_FIXME: We differ from DMD here, yet target defines are never set?! +int REALSIZE = 12; int REALPAD = 2; int REALALIGNSIZE = 4; -#elif defined(IN_GCC) +#elif TARGET_WINDOS +int REALSIZE = 10; +int REALPAD = 0; +int REALALIGNSIZE = 2; +#elif defined(IN_GCC) || defined(IN_LLVM) int REALSIZE = 0; int REALPAD = 0; int REALALIGNSIZE = 0; #else -int REALSIZE = 10; -int REALPAD = 0; -int REALALIGNSIZE = 2; +#error "fix this" #endif int Tsize_t = Tuns32; int Tptrdiff_t = Tint32; -#if _WIN32 && !(defined __MINGW32__ || defined _MSC_VER) -static double zero = 0; -double Port::nan = NAN; -double Port::infinity = 1/zero; -#endif - /***************************** Type *****************************/ ClassDeclaration *Type::typeinfo; @@ -2901,9 +2897,22 @@ d_uns64 TypeBasic::size(Loc loc) unsigned TypeBasic::alignsize() { +#if IN_LLVM if (ty == Tvoid) return 1; return GetTypeAlignment(sir, this); +#endif + + unsigned sz; + + switch (ty) + { + case Tfloat80: + case Timaginary80: + case Tcomplex80: + sz = REALALIGNSIZE; + break; + #if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS case Tint64: case Tuns64: @@ -2923,13 +2932,12 @@ unsigned TypeBasic::alignsize() sz = global.params.is64bit ? 8 : 4; break; #endif -#if IN_DMD + default: sz = size(0); break; } return sz; -#endif } #if IN_LLVM 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; diff --git a/gen/functions.cpp b/gen/functions.cpp index bee0c17f..bfca527f 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -968,6 +968,19 @@ void DtoDefineFunction(FuncDeclaration* fd) if (fd->isMain()) gIR->emitMain = true; + // On x86_64, always set 'uwtable' for System V ABI compatibility. + // TODO: Find a better place for this. + if (global.params.targetTriple.getArch() == llvm::Triple::x86_64) + { +#if LDC_LLVM_VER >= 303 + func->addFnAttr(llvm::Attribute::UWTable); +#elif LDC_LLVM_VER == 302 + func->addFnAttr(llvm::Attributes::UWTable); +#else + func->addFnAttr(UWTable); +#endif + } + std::string entryname("entry"); llvm::BasicBlock* beginbb = llvm::BasicBlock::Create(gIR->context(), entryname,func);