# HG changeset patch # User Tomas Lindquist Olsen # Date 1233535491 -3600 # Node ID a4fcc13da3cd3658f751162c2e1e6ed916682b03 # Parent 7e272f2b4fc39a772be8e37c7e8b702b3018d7c9 Changed templates and typeinfo to use linkonce linkage instead of weak linkage, this should fix inlining problems, fixing bug #197 . If problems show up, it's easy to change it back by changing the define in mars.h . I'm 95% sure this is safe, given how we handle templates. diff -r 7e272f2b4fc3 -r a4fcc13da3cd dmd/mars.h --- a/dmd/mars.h Mon Feb 02 00:58:36 2009 +0100 +++ b/dmd/mars.h Mon Feb 02 01:44:51 2009 +0100 @@ -65,6 +65,10 @@ OSSolaris, }; +// make it easier to test new linkage types +#define TEMPLATE_LINKAGE_TYPE llvm::GlobalValue::LinkOnceLinkage +#define TYPEINFO_LINKAGE_TYPE llvm::GlobalValue::LinkOnceLinkage + // Put command line switches in here struct Param { diff -r 7e272f2b4fc3 -r a4fcc13da3cd dmd2/mars.h --- a/dmd2/mars.h Mon Feb 02 00:58:36 2009 +0100 +++ b/dmd2/mars.h Mon Feb 02 01:44:51 2009 +0100 @@ -65,6 +65,10 @@ OSSolaris, }; +// make it easier to test new linkage types +#define TEMPLATE_LINKAGE_TYPE llvm::GlobalValue::LinkOnceLinkage +#define TYPEINFO_LINKAGE_TYPE llvm::GlobalValue::LinkOnceLinkage + // Put command line switches in here struct Param { diff -r 7e272f2b4fc3 -r a4fcc13da3cd gen/llvmhelpers.cpp --- a/gen/llvmhelpers.cpp Mon Feb 02 00:58:36 2009 +0100 +++ b/gen/llvmhelpers.cpp Mon Feb 02 01:44:51 2009 +0100 @@ -844,7 +844,7 @@ void DtoLazyStaticInit(bool istempl, LLValue* gvar, Initializer* init, Type* t) { // create a flag to make sure initialization only happens once - llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage; + llvm::GlobalValue::LinkageTypes gflaglink = istempl ? TEMPLATE_LINKAGE_TYPE : llvm::GlobalValue::InternalLinkage; std::string gflagname(gvar->getName()); gflagname.append("__initflag"); llvm::GlobalVariable* gflag = new llvm::GlobalVariable(LLType::Int1Ty,false,gflaglink,DtoConstBool(false),gflagname,gIR->module); diff -r 7e272f2b4fc3 -r a4fcc13da3cd gen/toir.cpp --- a/gen/toir.cpp Mon Feb 02 00:58:36 2009 +0100 +++ b/gen/toir.cpp Mon Feb 02 01:44:51 2009 +0100 @@ -391,7 +391,7 @@ else assert(0); - llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; + llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage; if (Logger::enabled()) Logger::cout() << "type: " << *at << "\ninit: " << *_init << '\n'; llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,".str",gIR->module); @@ -467,7 +467,7 @@ return _init; } - llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; + llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage; llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_init->getType(),true,_linkage,_init,".str",gIR->module); llvm::ConstantInt* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false); diff -r 7e272f2b4fc3 -r a4fcc13da3cd gen/tollvm.cpp --- a/gen/tollvm.cpp Mon Feb 02 00:58:36 2009 +0100 +++ b/gen/tollvm.cpp Mon Feb 02 01:44:51 2009 +0100 @@ -276,7 +276,7 @@ { // template if (DtoIsTemplateInstance(sym)) - return llvm::GlobalValue::WeakLinkage; + return TEMPLATE_LINKAGE_TYPE; // local static else if (sym->parent && sym->parent->isFuncDeclaration()) return llvm::GlobalValue::InternalLinkage; @@ -296,7 +296,7 @@ // template instances should have weak linkage // but only if there's a body, otherwise we make it external else if (DtoIsTemplateInstance(fdecl) && fdecl->fbody) - return llvm::GlobalValue::WeakLinkage; + return TEMPLATE_LINKAGE_TYPE; // extern(C) functions are always external else if (ft->linkage == LINKc) return llvm::GlobalValue::ExternalLinkage; @@ -306,7 +306,7 @@ { // template if (DtoIsTemplateInstance(cd)) - return llvm::GlobalValue::WeakLinkage; + return TEMPLATE_LINKAGE_TYPE; } else { @@ -320,7 +320,7 @@ llvm::GlobalValue::LinkageTypes DtoInternalLinkage(Dsymbol* sym) { if (DtoIsTemplateInstance(sym)) - return llvm::GlobalValue::WeakLinkage; + return TEMPLATE_LINKAGE_TYPE; else return llvm::GlobalValue::InternalLinkage; } @@ -328,7 +328,7 @@ llvm::GlobalValue::LinkageTypes DtoExternalLinkage(Dsymbol* sym) { if (DtoIsTemplateInstance(sym)) - return llvm::GlobalValue::WeakLinkage; + return TEMPLATE_LINKAGE_TYPE; else return llvm::GlobalValue::ExternalLinkage; } diff -r 7e272f2b4fc3 -r a4fcc13da3cd gen/typinf.cpp --- a/gen/typinf.cpp Mon Feb 02 00:58:36 2009 +0100 +++ b/gen/typinf.cpp Mon Feb 02 01:44:51 2009 +0100 @@ -379,7 +379,7 @@ const LLStructType* stype = isaStruct(base->type->ir.type->get()); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoTypedefDeclaration::llvmDefine() @@ -453,7 +453,7 @@ DtoResolveClass(base); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoEnumDeclaration::llvmDefine() @@ -528,7 +528,7 @@ DtoResolveClass(base); // create the symbol - tid->ir.irGlobal->value = new llvm::GlobalVariable(tid->ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); + tid->ir.irGlobal->value = new llvm::GlobalVariable(tid->ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, tid->toChars(), gIR->module); } static void LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) @@ -627,7 +627,7 @@ DtoResolveClass(base); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoStaticArrayDeclaration::llvmDefine() @@ -687,7 +687,7 @@ DtoResolveClass(base); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoAssociativeArrayDeclaration::llvmDefine() @@ -808,7 +808,7 @@ DtoResolveClass(base); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoStructDeclaration::llvmDefine() @@ -1024,7 +1024,7 @@ DtoResolveClass(base); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, llvm::GlobalValue::WeakLinkage, NULL, toChars(), gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoClassDeclaration::llvmDefine() @@ -1080,7 +1080,7 @@ DtoResolveClass(base); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoInterfaceDeclaration::llvmDefine() @@ -1138,7 +1138,7 @@ DtoResolveClass(base); // create the symbol - ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + ir.irGlobal->value = new llvm::GlobalVariable(ir.irGlobal->type.get(), true, TYPEINFO_LINKAGE_TYPE, NULL, toChars(), gIR->module); } void TypeInfoTupleDeclaration::llvmDefine() @@ -1185,7 +1185,7 @@ LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits); // need the pointer to the first element of arrC, so create a global for it - llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; + llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage; llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrTy,true,_linkage,arrC,".tupleelements",gIR->module); // get pointer to first element