From ad4eb1b6bdf976a4f26946b6d45333d78954646c Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 12 May 2013 21:09:16 +0200 Subject: [PATCH 1/5] Align unused real alignment code to upstream source. We set the target-specific values at runtime in Type::init(). --- dmd2/mtype.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dmd2/mtype.c b/dmd2/mtype.c index 45e596da..79e484a6 100644 --- a/dmd2/mtype.c +++ b/dmd2/mtype.c @@ -82,17 +82,19 @@ 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; From 4ad1b94f11b8c82a853ddf0bfdad7208cb986b55 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 12 May 2013 21:12:36 +0200 Subject: [PATCH 2/5] Remove piece of dead code gone from upstream as well. We do not support building with DMC anyway, so no functionality change implied. --- dmd2/mtype.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dmd2/mtype.c b/dmd2/mtype.c index 79e484a6..8d788ede 100644 --- a/dmd2/mtype.c +++ b/dmd2/mtype.c @@ -100,12 +100,6 @@ int REALALIGNSIZE = 0; 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; From 4597423dc50d6ac458d5cbeefa2a8eec993cf72b Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 19 May 2013 20:33:46 +0200 Subject: [PATCH 3/5] More IN_LLVM. --- dmd2/mtype.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dmd2/mtype.c b/dmd2/mtype.c index 8d788ede..4fb13713 100644 --- a/dmd2/mtype.c +++ b/dmd2/mtype.c @@ -2897,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: @@ -2919,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 From edbace8ae8bf33c13d18eea3dacfebf40a4c2f14 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 19 May 2013 21:04:26 +0200 Subject: [PATCH 4/5] Default to PIC on OS X. driver/target.h is due for a refactoring after the next release is branched off. --- driver/main.cpp | 2 +- driver/target.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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; From d402cd382e3679d669fec5ad0950397a6a886176 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 19 May 2013 21:47:15 +0200 Subject: [PATCH 5/5] Always add 'uwtable' attribute on x86_64. This is what Clang does, and omitting it could lead to problems w.r.t. the System V ABI. Doesn't seem to have caused any issues so far, though. --- gen/functions.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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);