Merge pull request #361 from klickverbot/osx

PIC by default on OS X; cleanups.
This commit is contained in:
David Nadlinger
2013-05-19 15:33:11 -07:00
4 changed files with 42 additions and 14 deletions

View File

@@ -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

View File

@@ -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");
}

View File

@@ -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;

View File

@@ -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);