diff options
43 files changed, 370 insertions, 192 deletions
diff --git a/docs/LangRef.html b/docs/LangRef.html index 83ea026..0985cbd 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -545,11 +545,26 @@ All Global Variables and Functions have one of the following types of linkage: </dd> <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt> + <dd>The semantics of this linkage follow the ELF object file model: the symbol is weak until linked, if not linked, the symbol becomes null instead of being an undefined reference. </dd> + <dt><tt><b><a name="linkage_linkonce">linkonce_odr</a></b></tt>: </dt> + <dt><tt><b><a name="linkage_common">common_odr</a></b></tt>: </dt> + <dt><tt><b><a name="linkage_weak">weak_odr</a></b></tt>: </dt> + <dt><tt><b><a name="linkage_externweak">extern_weak_odr</a></b></tt>: </dt> + <dd>Some languages allow inequivalent globals to be merged, such as two + functions with different semantics. Other languages, such as <tt>C++</tt>, + ensure that only equivalent globals are ever merged (the "one definition + rule" - <tt>odr</tt>). Such languages can use the <tt>linkonce_odr</tt>, + <tt>common_odr</tt>, <tt>weak_odr</tt> and <tt>extern_weak_odr</tt> linkage + types to indicate that the global will only be merged with equivalent + globals. These linkage types are otherwise the same as their + non-<tt>odr</tt> versions. + </dd> + <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt> <dd>If none of the above identifiers are used, the global is externally @@ -592,9 +607,9 @@ external (i.e., lacking any linkage declarations), they are accessible outside of the current module.</p> <p>It is illegal for a function <i>declaration</i> to have any linkage type other than "externally visible", <tt>dllimport</tt>, -or <tt>extern_weak</tt>.</p> -<p>Aliases can have only <tt>external</tt>, <tt>internal</tt> and <tt>weak</tt> -linkages.</p> +<tt>extern_weak</tt> or <tt>extern_weak_odr</tt>.</p> +<p>Aliases can have only <tt>external</tt>, <tt>internal</tt>, <tt>weak</tt> +or <tt>weak_odr</tt> linkages.</p> </div> <!-- ======================================================================= --> diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 289a569..cf46a97 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -3322,11 +3322,12 @@ never change at runtime).</p> <p>Create a new global variable of the specified type. If <tt>isConstant</tt> is true then the global variable will be marked as unchanging for the program. The Linkage parameter specifies the type of - linkage (internal, external, weak, linkonce, appending) for the variable. If - the linkage is InternalLinkage, WeakLinkage, or LinkOnceLinkage, then - the resultant global variable will have internal linkage. AppendingLinkage - concatenates together all instances (in different translation units) of the - variable into a single variable but is only applicable to arrays. See + linkage (internal, external, weak, linkonce, appending) for the variable. + If the linkage is InternalLinkage, WeakAnyLinkage, WeakODRLinkage, + LinkOnceAnyLinkage or LinkOnceODRLinkage, then the resultant + global variable will have internal linkage. AppendingLinkage concatenates + together all instances (in different translation units) of the variable + into a single variable but is only applicable to arrays. See the <a href="LangRef.html#modulestructure">LLVM Language Reference</a> for further details on linkage types. Optionally an initializer, a name, and the module to put the variable into may be specified for the global variable as diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 6016ac6..5d8cff4 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -115,16 +115,26 @@ typedef enum { typedef enum { LLVMExternalLinkage, /**< Externally visible function */ - LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/ - LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */ + LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/ + LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something + equivalent. */ + LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */ + LLVMWeakODRLinkage, /**< Same, but only replaced by something + equivalent. */ LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */ LLVMInternalLinkage, /**< Rename collisions when linking (static functions) */ + LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */ LLVMDLLImportLinkage, /**< Function to be imported from DLL */ LLVMDLLExportLinkage, /**< Function to be accessible from DLL */ - LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */ - LLVMGhostLinkage /**< Stand-in functions for streaming fns from + LLVMExternalWeakAnyLinkage,/**< ExternalWeak linkage description */ + LLVMExternalWeakODRLinkage,/**< Same, but only replaced by something + equivalent. */ + LLVMGhostLinkage, /**< Stand-in functions for streaming fns from bitcode */ + LLVMCommonAnyLinkage, /**< Tentative definitions */ + LLVMCommonODRLinkage /**< Same, but only replaced by something + equivalent. */ } LLVMLinkage; typedef enum { diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index 8fb5580..33f50c9 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -31,16 +31,20 @@ public: /// @brief An enumeration for the kinds of linkage for global values. enum LinkageTypes { ExternalLinkage = 0,///< Externally visible function - LinkOnceLinkage, ///< Keep one copy of function when linking (inline) - WeakLinkage, ///< Keep one copy of named function when linking (weak) + LinkOnceAnyLinkage, ///< Keep one copy of function when linking (inline) + LinkOnceODRLinkage, ///< Same, but only replaced by something equivalent. + WeakAnyLinkage, ///< Keep one copy of named function when linking (weak) + WeakODRLinkage, ///< Same, but only replaced by something equivalent. AppendingLinkage, ///< Special purpose, only applies to global arrays InternalLinkage, ///< Rename collisions when linking (static functions) PrivateLinkage, ///< Like Internal, but omit from symbol table DLLImportLinkage, ///< Function to be imported from DLL DLLExportLinkage, ///< Function to be accessible from DLL - ExternalWeakLinkage,///< ExternalWeak linkage description + ExternalWeakAnyLinkage,///< ExternalWeak linkage description + ExternalWeakODRLinkage,///< Same, but only replaced by something equivalent. GhostLinkage, ///< Stand-in functions for streaming fns from BC files - CommonLinkage ///< Tentative definitions + CommonAnyLinkage, ///< Tentative definitions + CommonODRLinkage ///< Same, but only replaced by something equivalent. }; /// @brief An enumeration for the kinds of visibility of global values. @@ -99,31 +103,67 @@ public: return reinterpret_cast<const PointerType*>(User::getType()); } - bool hasExternalLinkage() const { return Linkage == ExternalLinkage; } - bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; } - bool hasWeakLinkage() const { return Linkage == WeakLinkage; } - bool hasCommonLinkage() const { return Linkage == CommonLinkage; } - bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; } - bool hasInternalLinkage() const { return Linkage == InternalLinkage; } - bool hasPrivateLinkage() const { return Linkage == PrivateLinkage; } - bool hasLocalLinkage() const { + static LinkageTypes getLinkOnceLinkage(bool ODR) { + return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage; + } + static LinkageTypes getWeakLinkage(bool ODR) { + return ODR ? WeakODRLinkage : WeakAnyLinkage; + } + static LinkageTypes getCommonLinkage(bool ODR) { + return ODR ? CommonODRLinkage : CommonAnyLinkage; + } + static LinkageTypes getExternalWeakLinkage(bool ODR) { + return ODR ? ExternalWeakODRLinkage : ExternalWeakAnyLinkage; + } + + bool hasExternalLinkage() const { return Linkage == ExternalLinkage; } + bool hasLinkOnceLinkage() const { + return Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage; + } + bool hasWeakLinkage() const { + return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage; + } + bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; } + bool hasInternalLinkage() const { return Linkage == InternalLinkage; } + bool hasPrivateLinkage() const { return Linkage == PrivateLinkage; } + bool hasLocalLinkage() const { return Linkage == InternalLinkage || Linkage == PrivateLinkage; } - bool hasDLLImportLinkage() const { return Linkage == DLLImportLinkage; } - bool hasDLLExportLinkage() const { return Linkage == DLLExportLinkage; } - bool hasExternalWeakLinkage() const { return Linkage == ExternalWeakLinkage; } - bool hasGhostLinkage() const { return Linkage == GhostLinkage; } + bool hasDLLImportLinkage() const { return Linkage == DLLImportLinkage; } + bool hasDLLExportLinkage() const { return Linkage == DLLExportLinkage; } + bool hasExternalWeakLinkage() const { + return Linkage == ExternalWeakAnyLinkage || + Linkage == ExternalWeakODRLinkage; + } + bool hasGhostLinkage() const { return Linkage == GhostLinkage; } + bool hasCommonLinkage() const { + return Linkage == CommonAnyLinkage || Linkage == CommonODRLinkage; + } + void setLinkage(LinkageTypes LT) { Linkage = LT; } LinkageTypes getLinkage() const { return Linkage; } /// mayBeOverridden - Whether the definition of this global may be replaced - /// at link time. For example, if a function has weak linkage then the code - /// defining it may be replaced by different code. + /// by something non-equivalent at link time. For example, if a function has + /// weak linkage then the code defining it may be replaced by different code. bool mayBeOverridden() const { - return (Linkage == WeakLinkage || - Linkage == LinkOnceLinkage || - Linkage == CommonLinkage || - Linkage == ExternalWeakLinkage); + return (Linkage == WeakAnyLinkage || + Linkage == LinkOnceAnyLinkage || + Linkage == CommonAnyLinkage || + Linkage == ExternalWeakAnyLinkage); + } + + /// isWeakForLinker - Whether the definition of this global may be replaced at + /// link time, whether the replacement is equivalent to the original or not. + bool isWeakForLinker() const { + return (Linkage == WeakAnyLinkage || + Linkage == WeakODRLinkage || + Linkage == LinkOnceAnyLinkage || + Linkage == LinkOnceODRLinkage || + Linkage == CommonAnyLinkage || + Linkage == CommonODRLinkage || + Linkage == ExternalWeakAnyLinkage || + Linkage == ExternalWeakODRLinkage); } /// copyAttributesFrom - copy all additional attributes (those not needed to diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index deb5c9b..a063aa5 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -344,7 +344,7 @@ DIAnchor DIFactory::GetOrCreateAnchor(unsigned TAG, const char *Name) { if (GV->hasInitializer()) return SubProgramAnchor = DIAnchor(GV); - GV->setLinkage(GlobalValue::LinkOnceLinkage); + GV->setLinkage(GlobalValue::LinkOnceAnyLinkage); GV->setSection("llvm.metadata"); GV->setConstant(true); M.addTypeName("llvm.dbg.anchor.type", EltTy); diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index fb491d3..6f1d5ee 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -456,15 +456,19 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(private); KEYWORD(internal); KEYWORD(linkonce); + KEYWORD(linkonce_odr); KEYWORD(weak); + KEYWORD(weak_odr); KEYWORD(appending); KEYWORD(dllimport); KEYWORD(dllexport); KEYWORD(common); + KEYWORD(common_odr); KEYWORD(default); KEYWORD(hidden); KEYWORD(protected); KEYWORD(extern_weak); + KEYWORD(extern_weak_odr); KEYWORD(external); KEYWORD(thread_local); KEYWORD(zeroinitializer); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 19f8415..90dd507 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -116,12 +116,16 @@ bool LLParser::ParseTopLevelEntities() { case lltok::kw_private: // OptionalLinkage case lltok::kw_internal: // OptionalLinkage case lltok::kw_weak: // OptionalLinkage + case lltok::kw_weak_odr: // OptionalLinkage case lltok::kw_linkonce: // OptionalLinkage + case lltok::kw_linkonce_odr: // OptionalLinkage case lltok::kw_appending: // OptionalLinkage case lltok::kw_dllexport: // OptionalLinkage case lltok::kw_common: // OptionalLinkage + case lltok::kw_common_odr: // OptionalLinkage case lltok::kw_dllimport: // OptionalLinkage case lltok::kw_extern_weak: // OptionalLinkage + case lltok::kw_extern_weak_odr: // OptionalLinkage case lltok::kw_external: { // OptionalLinkage unsigned Linkage, Visibility; if (ParseOptionalLinkage(Linkage) || @@ -377,7 +381,8 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc, return true; if (Linkage != GlobalValue::ExternalLinkage && - Linkage != GlobalValue::WeakLinkage && + Linkage != GlobalValue::WeakAnyLinkage && + Linkage != GlobalValue::WeakODRLinkage && Linkage != GlobalValue::InternalLinkage && Linkage != GlobalValue::PrivateLinkage) return Error(LinkageLoc, "invalid linkage type for alias"); @@ -461,7 +466,8 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, // present. Constant *Init = 0; if (!HasLinkage || (Linkage != GlobalValue::DLLImportLinkage && - Linkage != GlobalValue::ExternalWeakLinkage && + Linkage != GlobalValue::ExternalWeakAnyLinkage && + Linkage != GlobalValue::ExternalWeakODRLinkage && Linkage != GlobalValue::ExternalLinkage)) { if (ParseGlobalValue(Ty, Init)) return true; @@ -576,10 +582,10 @@ GlobalValue *LLParser::GetGlobalVal(const std::string &Name, const Type *Ty, return 0; } - FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M); + FwdVal = Function::Create(FT, GlobalValue::ExternalWeakAnyLinkage, Name, M); } else { FwdVal = new GlobalVariable(PTy->getElementType(), false, - GlobalValue::ExternalWeakLinkage, 0, Name, M); + GlobalValue::ExternalWeakAnyLinkage, 0, Name, M); } ForwardRefVals[Name] = std::make_pair(FwdVal, Loc); @@ -620,10 +626,10 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc) { Error(Loc, "function may not return opaque type"); return 0; } - FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M); + FwdVal = Function::Create(FT, GlobalValue::ExternalWeakAnyLinkage, "", M); } else { FwdVal = new GlobalVariable(PTy->getElementType(), false, - GlobalValue::ExternalWeakLinkage, 0, "", M); + GlobalValue::ExternalWeakAnyLinkage, 0, "", M); } ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc); @@ -746,27 +752,36 @@ bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) { /// ::= 'private' /// ::= 'internal' /// ::= 'weak' +/// ::= 'weak_odr' /// ::= 'linkonce' +/// ::= 'linkonce_odr' /// ::= 'appending' /// ::= 'dllexport' /// ::= 'common' +/// ::= 'common_odr' /// ::= 'dllimport' /// ::= 'extern_weak' +/// ::= 'extern_weak_odr' /// ::= 'external' bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) { HasLinkage = false; switch (Lex.getKind()) { - default: Res = GlobalValue::ExternalLinkage; return false; - case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break; - case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break; - case lltok::kw_weak: Res = GlobalValue::WeakLinkage; break; - case lltok::kw_linkonce: Res = GlobalValue::LinkOnceLinkage; break; - case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break; - case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break; - case lltok::kw_common: Res = GlobalValue::CommonLinkage; break; - case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break; - case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break; - case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break; + default: Res = GlobalValue::ExternalLinkage; return false; + case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break; + case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break; + case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break; + case lltok::kw_weak_odr: Res = GlobalValue::WeakODRLinkage; break; + case lltok::kw_linkonce: Res = GlobalValue::LinkOnceAnyLinkage; break; + case lltok::kw_linkonce_odr: Res = GlobalValue::LinkOnceODRLinkage; break; + case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break; + case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break; + case lltok::kw_common: Res = GlobalValue::CommonAnyLinkage; break; + case lltok::kw_common_odr: Res = GlobalValue::CommonODRLinkage; break; + case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break; + case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakAnyLinkage; break; + case lltok::kw_extern_weak_odr: + Res = GlobalValue::ExternalWeakODRLinkage; break; + case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break; } Lex.Lex(); HasLinkage = true; @@ -2074,21 +2089,25 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) { case GlobalValue::ExternalLinkage: break; // always ok. case GlobalValue::DLLImportLinkage: - case GlobalValue::ExternalWeakLinkage: + case GlobalValue::ExternalWeakAnyLinkage: + case GlobalValue::ExternalWeakODRLinkage: if (isDefine) return Error(LinkageLoc, "invalid linkage for function definition"); break; case GlobalValue::PrivateLinkage: case GlobalValue::InternalLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: case GlobalValue::DLLExportLinkage: if (!isDefine) return Error(LinkageLoc, "invalid linkage for function declaration"); break; case GlobalValue::AppendingLinkage: case GlobalValue::GhostLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: return Error(LinkageLoc, "invalid function linkage type"); } diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h index e3bc908..efdc77a 100644 --- a/lib/AsmParser/LLToken.h +++ b/lib/AsmParser/LLToken.h @@ -36,9 +36,10 @@ namespace lltok { kw_declare, kw_define, kw_global, kw_constant, - kw_private, kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport, - kw_dllexport, kw_common, kw_default, kw_hidden, kw_protected, - kw_extern_weak, + kw_private, kw_internal, kw_linkonce, kw_linkonce_odr, kw_weak, kw_weak_odr, + kw_appending, kw_dllimport, kw_dllexport, kw_common, kw_common_odr, + kw_default, kw_hidden, kw_protected, + kw_extern_weak, kw_extern_weak_odr, kw_external, kw_thread_local, kw_zeroinitializer, kw_undef, kw_null, diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 2ddfbe3..0fe6fc6 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -59,15 +59,19 @@ static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) { switch (Val) { default: // Map unknown/new linkages to external case 0: return GlobalValue::ExternalLinkage; - case 1: return GlobalValue::WeakLinkage; + case 1: return GlobalValue::WeakAnyLinkage; case 2: return GlobalValue::AppendingLinkage; case 3: return GlobalValue::InternalLinkage; - case 4: return GlobalValue::LinkOnceLinkage; + case 4: return GlobalValue::LinkOnceAnyLinkage; case 5: return GlobalValue::DLLImportLinkage; case 6: return GlobalValue::DLLExportLinkage; - case 7: return GlobalValue::ExternalWeakLinkage; - case 8: return GlobalValue::CommonLinkage; + case 7: return GlobalValue::ExternalWeakAnyLinkage; + case 8: return GlobalValue::CommonAnyLinkage; case 9: return GlobalValue::PrivateLinkage; + case 10: return GlobalValue::WeakODRLinkage; + case 11: return GlobalValue::LinkOnceODRLinkage; + case 12: return GlobalValue::ExternalWeakODRLinkage; + case 13: return GlobalValue::CommonODRLinkage; } } diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 5633f0f..fefffbe 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -276,15 +276,19 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) { default: assert(0 && "Invalid linkage!"); case GlobalValue::GhostLinkage: // Map ghost linkage onto external. case GlobalValue::ExternalLinkage: return 0; - case GlobalValue::WeakLinkage: return 1; + case GlobalValue::WeakAnyLinkage: return 1; case GlobalValue::AppendingLinkage: return 2; case GlobalValue::InternalLinkage: return 3; - case GlobalValue::LinkOnceLinkage: return 4; + case GlobalValue::LinkOnceAnyLinkage: return 4; case GlobalValue::DLLImportLinkage: return 5; case GlobalValue::DLLExportLinkage: return 6; - case GlobalValue::ExternalWeakLinkage: return 7; - case GlobalValue::CommonLinkage: return 8; + case GlobalValue::ExternalWeakAnyLinkage: return 7; + case GlobalValue::CommonAnyLinkage: return 8; case GlobalValue::PrivateLinkage: return 9; + case GlobalValue::WeakODRLinkage: return 10; + case GlobalValue::LinkOnceODRLinkage: return 11; + case GlobalValue::ExternalWeakODRLinkage: return 12; + case GlobalValue::CommonODRLinkage: return 13; } } diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 5c4957a..9181216 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -3135,9 +3135,8 @@ public: GlobalVariable *GV = getGlobalVariable(V); if (!GV) return false; - - if (GV->getLinkage() != GlobalValue::InternalLinkage - && GV->getLinkage() != GlobalValue::LinkOnceLinkage) + + if (!GV->hasInternalLinkage () && !GV->hasLinkOnceLinkage()) return false; DIDescriptor DI(GV); @@ -3449,8 +3448,10 @@ class DwarfException : public Dwarf { } // If corresponding function is weak definition, this should be too. - if ((linkage == Function::WeakLinkage || - linkage == Function::LinkOnceLinkage) && + if ((linkage == Function::WeakAnyLinkage || + linkage == Function::WeakODRLinkage || + linkage == Function::LinkOnceAnyLinkage || + linkage == Function::LinkOnceODRLinkage) && TAI->getWeakDefDirective()) O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n"; @@ -3461,8 +3462,10 @@ class DwarfException : public Dwarf { // unwind info is to be available for non-EH uses. if (!EHFrameInfo.hasCalls && !UnwindTablesMandatory && - ((linkage != Function::WeakLinkage && - linkage != Function::LinkOnceLinkage) || + ((linkage != Function::WeakAnyLinkage && + linkage != Function::WeakODRLinkage && + linkage != Function::LinkOnceAnyLinkage && + linkage != Function::LinkOnceODRLinkage) || !TAI->getWeakDefDirective() || TAI->getSupportsWeakOmittedEHFrame())) { diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 7cca74b..ddc4e35 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -174,8 +174,10 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &F) { case GlobalValue::ExternalLinkage: FnSym.SetBind(ELFWriter::ELFSym::STB_GLOBAL); break; - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: FnSym.SetBind(ELFWriter::ELFSym::STB_WEAK); break; case GlobalValue::PrivateLinkage: diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 5b4de27..56b1736 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -316,7 +316,7 @@ static Instruction *LowerPartSelect(CallInst *CI) { Name[i] = '_'; Module* M = F->getParent(); F = cast<Function>(M->getOrInsertFunction(Name, FT)); - F->setLinkage(GlobalValue::WeakLinkage); + F->setLinkage(GlobalValue::WeakAnyLinkage); // If we haven't defined the impl function yet, do so now if (F->isDeclaration()) { @@ -490,7 +490,7 @@ static Instruction *LowerPartSet(CallInst *CI) { Name[i] = '_'; Module* M = F->getParent(); F = cast<Function>(M->getOrInsertFunction(Name, FT)); - F->setLinkage(GlobalValue::WeakLinkage); + F->setLinkage(GlobalValue::WeakAnyLinkage); // If we haven't defined the impl function yet, do so now if (F->isDeclaration()) { diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp index 22c2157..5fe05a4 100644 --- a/lib/CodeGen/MachOWriter.cpp +++ b/lib/CodeGen/MachOWriter.cpp @@ -956,9 +956,12 @@ MachOSym::MachOSym(const GlobalValue *gv, std::string name, uint8_t sect, default: assert(0 && "Unexpected linkage type!"); break; - case GlobalValue::WeakLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: assert(!isa<Function>(gv) && "Unexpected linkage type for Function!"); case GlobalValue::ExternalLinkage: GVName = TAI->getGlobalPrefix() + name; diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 7913c01..a08dcb2 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -728,7 +728,7 @@ TargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { if (getTargetMachine().getRelocationModel() == Reloc::DynamicNoPIC && GA && !GA->getGlobal()->isDeclaration() && - !GA->getGlobal()->mayBeOverridden()) + !GA->getGlobal()->isWeakForLinker()) return true; // Otherwise assume nothing is safe. diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp index 5a55760..2402f81 100644 --- a/lib/CodeGen/ShadowStackGC.cpp +++ b/lib/CodeGen/ShadowStackGC.cpp @@ -293,12 +293,12 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) { // If the root chain does not exist, insert a new one with linkonce // linkage! Head = new GlobalVariable(StackEntryPtrTy, false, - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, Constant::getNullValue(StackEntryPtrTy), "llvm_gc_root_chain", &M); } else if (Head->hasExternalLinkage() && Head->isDeclaration()) { Head->setInitializer(Constant::getNullValue(StackEntryPtrTy)); - Head->setLinkage(GlobalValue::LinkOnceLinkage); + Head->setLinkage(GlobalValue::LinkOnceAnyLinkage); } return true; diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 386c3be..0490343 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -580,8 +580,8 @@ void *JIT::getPointerToFunction(Function *F) { } if (F->isDeclaration()) { - bool AbortOnFailure = !areDlsymStubsEnabled() && - F->getLinkage() != GlobalValue::ExternalWeakLinkage; + bool AbortOnFailure = + !areDlsymStubsEnabled() && !F->hasExternalWeakLinkage(); void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure); addGlobalMapping(F, Addr); return Addr; diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index c596812..6ea3005 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -460,7 +460,7 @@ static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src, LT = Src->getLinkage(); } } else if (Dest->hasExternalWeakLinkage()) { - //If the Dest is weak, use the source linkage + // If the Dest is weak, use the source linkage. LinkFromSrc = true; LT = Src->getLinkage(); } else { @@ -683,15 +683,22 @@ static bool LinkGlobals(Module *Dest, const Module *Src, static GlobalValue::LinkageTypes CalculateAliasLinkage(const GlobalValue *SGV, const GlobalValue *DGV) { - if (SGV->hasExternalLinkage() || DGV->hasExternalLinkage()) + GlobalValue::LinkageTypes SL = SGV->getLinkage(); + GlobalValue::LinkageTypes DL = DGV->getLinkage(); + if (SL == GlobalValue::ExternalLinkage || DL == GlobalValue::ExternalLinkage) return GlobalValue::ExternalLinkage; - else if (SGV->hasWeakLinkage() || DGV->hasWeakLinkage()) - return GlobalValue::WeakLinkage; - else if (SGV->hasInternalLinkage() && DGV->hasInternalLinkage()) + else if (SL == GlobalValue::WeakAnyLinkage || + DL == GlobalValue::WeakAnyLinkage) + return GlobalValue::WeakAnyLinkage; + else if (SL == GlobalValue::WeakODRLinkage || + DL == GlobalValue::WeakODRLinkage) + return GlobalValue::WeakODRLinkage; + else if (SL == GlobalValue::InternalLinkage && + DL == GlobalValue::InternalLinkage) return GlobalValue::InternalLinkage; else { - assert (SGV->hasPrivateLinkage() && DGV->hasPrivateLinkage() && - "Unexpected linkage type"); + assert (SL == GlobalValue::PrivateLinkage && + DL == GlobalValue::PrivateLinkage && "Unexpected linkage type"); return GlobalValue::PrivateLinkage; } } diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index 41852fa..cc38efb 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -854,7 +854,7 @@ static bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) { bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode(); if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage())) return false; - return RelocM != Reloc::Static && (isDecl || GV->mayBeOverridden()); + return RelocM != Reloc::Static && (isDecl || GV->isWeakForLinker()); } SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 969b8fa..ae968e7 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -208,8 +208,10 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) { SwitchToTextSection("\t.text", F); O << "\t.globl\t" << CurrentFnName << "\n"; break; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: if (Subtarget->isTargetDarwin()) { SwitchToTextSection( ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F); @@ -853,7 +855,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { } } - if (GVar->hasLocalLinkage() || GVar->mayBeOverridden()) { + if (GVar->hasLocalLinkage() || GVar->isWeakForLinker()) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (isDarwin) { @@ -899,9 +901,12 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { SwitchToSection(TAI->SectionForGlobal(GVar)); switch (GVar->getLinkage()) { - case GlobalValue::CommonLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: if (isDarwin) { O << "\t.globl " << name << "\n" << "\t.weak_definition " << name << "\n"; diff --git a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp index 536e592..5238b79 100644 --- a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp +++ b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp @@ -163,8 +163,10 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) { case Function::ExternalLinkage: O << "\t.globl " << CurrentFnName << "\n"; break; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: O << TAI->getWeakRefDirective() << CurrentFnName << "\n"; break; } @@ -231,9 +233,12 @@ void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { // 2: Kind switch (GVar->getLinkage()) { - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: O << TAI->getWeakRefDirective() << name << '\n'; break; case GlobalValue::AppendingLinkage: diff --git a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp index f784d70..7731a90 100644 --- a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp +++ b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp @@ -445,8 +445,10 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) O << "\t.global\t" << CurrentFnName << "\n" << "\t.type\t" << CurrentFnName << ", @function\n"; break; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: O << "\t.global\t" << CurrentFnName << "\n"; O << "\t.weak_definition\t" << CurrentFnName << "\n"; break; @@ -534,7 +536,7 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (C->isNullValue() && /* FIXME: Verify correct */ !GVar->hasSection() && (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() || - GVar->mayBeOverridden())) { + GVar->isWeakForLinker())) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasExternalLinkage()) { @@ -555,9 +557,12 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { switch (GVar->getLinkage()) { // Should never be seen for the CellSPU platform... - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: O << "\t.global " << name << '\n' << "\t.type " << name << ", @object\n" << "\t.weak " << name << '\n'; diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index dbe4f2d..48cf495 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -294,10 +294,14 @@ namespace { Out << "GlobalValue::InternalLinkage"; break; case GlobalValue::PrivateLinkage: Out << "GlobalValue::PrivateLinkage"; break; - case GlobalValue::LinkOnceLinkage: - Out << "GlobalValue::LinkOnceLinkage "; break; - case GlobalValue::WeakLinkage: - Out << "GlobalValue::WeakLinkage"; break; + case GlobalValue::LinkOnceAnyLinkage: + Out << "GlobalValue::LinkOnceAnyLinkage "; break; + case GlobalValue::LinkOnceODRLinkage: + Out << "GlobalValue::LinkOnceODRLinkage "; break; + case GlobalValue::WeakAnyLinkage: + Out << "GlobalValue::WeakAnyLinkage"; break; + case GlobalValue::WeakODRLinkage: + Out << "GlobalValue::WeakODRLinkage"; break; case GlobalValue::AppendingLinkage: Out << "GlobalValue::AppendingLinkage"; break; case GlobalValue::ExternalLinkage: @@ -306,12 +310,16 @@ namespace { Out << "GlobalValue::DLLImportLinkage"; break; case GlobalValue::DLLExportLinkage: Out << "GlobalValue::DLLExportLinkage"; break; - case GlobalValue::ExternalWeakLinkage: - Out << "GlobalValue::ExternalWeakLinkage"; break; + case GlobalValue::ExternalWeakAnyLinkage: + Out << "GlobalValue::ExternalWeakAnyLinkage"; break; + case GlobalValue::ExternalWeakODRLinkage: + Out << "GlobalValue::ExternalWeakODRLinkage"; break; case GlobalValue::GhostLinkage: Out << "GlobalValue::GhostLinkage"; break; - case GlobalValue::CommonLinkage: - Out << "GlobalValue::CommonLinkage"; break; + case GlobalValue::CommonAnyLinkage: + Out << "GlobalValue::CommonAnyLinkage"; break; + case GlobalValue::CommonODRLinkage: + Out << "GlobalValue::CommonODRLinkage"; break; } } diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index cc05c09..927fdd2 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -75,7 +75,7 @@ DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV, const Section* DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { SectionKind::Kind Kind = SectionKindForGlobal(GV); - bool isWeak = GV->mayBeOverridden(); + bool isWeak = GV->isWeakForLinker(); bool isNonStatic = TM.getRelocationModel() != Reloc::Static; switch (Kind) { diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 624b95c..3a2a00c 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -49,14 +49,16 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { case Function::DLLExportLinkage: case Function::ExternalLinkage: return TextSection; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: std::string Name = UniqueSectionForGlobal(GV, Kind); unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); return getNamedSection(Name.c_str(), Flags); } } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) { - if (GVar->mayBeOverridden()) { + if (GVar->isWeakForLinker()) { std::string Name = UniqueSectionForGlobal(GVar, Kind); unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str()); return getNamedSection(Name.c_str(), Flags); diff --git a/lib/Target/IA64/IA64AsmPrinter.cpp b/lib/Target/IA64/IA64AsmPrinter.cpp index 0047430..d8ec210 100644 --- a/lib/Target/IA64/IA64AsmPrinter.cpp +++ b/lib/Target/IA64/IA64AsmPrinter.cpp @@ -278,7 +278,7 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (C->isNullValue() && !GVar->hasSection()) { if (!GVar->isThreadLocal() && - (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) { + (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasLocalLinkage()) { @@ -296,9 +296,12 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { } switch (GVar->getLinkage()) { - case GlobalValue::LinkOnceLinkage: - case GlobalValue::CommonLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: // Nonnull linkonce -> weak O << "\t.weak " << name << '\n'; break; diff --git a/lib/Target/Mips/MipsAsmPrinter.cpp b/lib/Target/Mips/MipsAsmPrinter.cpp index 732c5d7..a22d7d6 100644 --- a/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/MipsAsmPrinter.cpp @@ -504,7 +504,7 @@ printModuleLevelGV(const GlobalVariable* GVar) { if (C->isNullValue() && !GVar->hasSection()) { if (!GVar->isThreadLocal() && - (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) { + (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasLocalLinkage()) @@ -519,9 +519,12 @@ printModuleLevelGV(const GlobalVariable* GVar) { } } switch (GVar->getLinkage()) { - case GlobalValue::LinkOnceLinkage: - case GlobalValue::CommonLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: // FIXME: Verify correct for weak. // Nonnull linkonce -> weak O << "\t.weak " << name << '\n'; diff --git a/lib/Target/Mips/MipsTargetAsmInfo.cpp b/lib/Target/Mips/MipsTargetAsmInfo.cpp index 7566f41..3eee3be 100644 --- a/lib/Target/Mips/MipsTargetAsmInfo.cpp +++ b/lib/Target/Mips/MipsTargetAsmInfo.cpp @@ -85,7 +85,7 @@ SelectSectionForGlobal(const GlobalValue *GV) const { SectionKind::Kind K = SectionKindForGlobal(GV); const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV); - if (GVA && (!GVA->mayBeOverridden())) + if (GVA && (!GVA->isWeakForLinker())) switch (K) { case SectionKind::SmallData: return getSmallDataSection(); diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 57a2697..4da5377 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -388,7 +388,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) { // External or weakly linked global variables need non-lazily-resolved stubs if (TM.getRelocationModel() != Reloc::Static) { - if (GV->isDeclaration() || GV->mayBeOverridden()) { + if (GV->isDeclaration() || GV->isWeakForLinker()) { if (GV->hasHiddenVisibility()) { if (!GV->isDeclaration() && !GV->hasCommonLinkage()) O << Name; @@ -592,8 +592,10 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << "\t.global\t" << CurrentFnName << '\n' << "\t.type\t" << CurrentFnName << ", @function\n"; break; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: O << "\t.global\t" << CurrentFnName << '\n'; O << "\t.weak\t" << CurrentFnName << '\n'; break; @@ -689,7 +691,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (C->isNullValue() && /* FIXME: Verify correct */ !GVar->hasSection() && (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() || - GVar->mayBeOverridden())) { + GVar->isWeakForLinker())) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasExternalLinkage()) { @@ -709,9 +711,12 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { } switch (GVar->getLinkage()) { - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: O << "\t.global " << name << '\n' << "\t.type " << name << ", @object\n" << "\t.weak " << name << '\n'; @@ -785,8 +790,10 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { case Function::ExternalLinkage: O << "\t.globl\t" << CurrentFnName << '\n'; break; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: O << "\t.globl\t" << CurrentFnName << '\n'; O << "\t.weak_definition\t" << CurrentFnName << '\n'; break; @@ -918,7 +925,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (C->isNullValue() && /* FIXME: Verify correct */ !GVar->hasSection() && (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() || - GVar->mayBeOverridden()) && + GVar->isWeakForLinker()) && TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. @@ -950,9 +957,12 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { } switch (GVar->getLinkage()) { - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: O << "\t.globl " << name << '\n' << "\t.weak_definition " << name << '\n'; break; diff --git a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp index 80976bb..e0785d5 100644 --- a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp @@ -260,7 +260,7 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (C->isNullValue() && !GVar->hasSection()) { if (!GVar->isThreadLocal() && - (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) { + (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasLocalLinkage()) @@ -276,9 +276,12 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { } switch (GVar->getLinkage()) { - case GlobalValue::CommonLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak. + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: // FIXME: Verify correct for weak. + case GlobalValue::WeakODRLinkage: // FIXME: Verify correct for weak. // Nonnull linkonce -> weak O << "\t.weak " << name << '\n'; break; diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index d687e2f..8f5941f 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -259,7 +259,7 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV, assert(0 && "Unexpected section kind!"); } - if (GV->mayBeOverridden()) + if (GV->isWeakForLinker()) Flags |= SectionFlags::Linkonce; } @@ -310,7 +310,7 @@ const Section* TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { SectionKind::Kind Kind = SectionKindForGlobal(GV); - if (GV->mayBeOverridden()) { + if (GV->isWeakForLinker()) { std::string Name = UniqueSectionForGlobal(GV, Kind); unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); return getNamedSection(Name.c_str(), Flags); diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 0595b6f..e3b6c27 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -168,8 +168,10 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) { EmitAlignment(FnAlign, F); O << "\t.globl\t" << CurrentFnName << '\n'; break; - case Function::LinkOnceLinkage: - case Function::WeakLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: EmitAlignment(FnAlign, F); if (Subtarget->isTargetDarwin()) { O << "\t.globl\t" << CurrentFnName << '\n'; @@ -198,8 +200,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) { O << CurrentFnName << ":\n"; // Add some workaround for linkonce linkage on Cygwin\MinGW if (Subtarget->isTargetCygMing() && - (F->getLinkage() == Function::LinkOnceLinkage || - F->getLinkage() == Function::WeakLinkage)) + (F->hasLinkOnceLinkage() || F->hasWeakLinkage())) O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n"; } @@ -386,7 +387,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, if (shouldPrintStub(TM, Subtarget)) { // Link-once, declaration, or Weakly-linked global variables need // non-lazily-resolved stubs - if (GV->isDeclaration() || GV->mayBeOverridden()) { + if (GV->isDeclaration() || GV->isWeakForLinker()) { // Dynamically-resolved functions need a stub for the function. if (isCallOp && isa<Function>(GV)) { // Function stubs are no longer needed for Mac OS X 10.5 and up. @@ -816,7 +817,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { } if (!GVar->isThreadLocal() && - (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) { + (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (TAI->getLCOMMDirective() != NULL) { @@ -855,9 +856,12 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { } switch (GVar->getLinkage()) { - case GlobalValue::CommonLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: if (Subtarget->isTargetDarwin()) { O << "\t.globl " << name << '\n' << TAI->getWeakDefDirective() << name << '\n'; diff --git a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp index c4389aa..12b9c2f 100644 --- a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp @@ -455,9 +455,12 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) { bool bCustomSegment = false; switch (I->getLinkage()) { - case GlobalValue::CommonLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: SwitchToDataSection(""); O << name << "?\tsegment common 'COMMON'\n"; bCustomSegment = true; diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp index 6d2602a..8c5176b 100644 --- a/lib/Target/X86/X86Subtarget.cpp +++ b/lib/Target/X86/X86Subtarget.cpp @@ -51,7 +51,7 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV, // target is x86-64 or the symbol is definitely defined in the current // translation unit. return false; - return !isDirectCall && (isDecl || GV->mayBeOverridden()); + return !isDirectCall && (isDecl || GV->isWeakForLinker()); } else if (isTargetELF()) { // Extra load is needed for all externally visible. if (isDirectCall) diff --git a/lib/Target/XCore/XCoreAsmPrinter.cpp b/lib/Target/XCore/XCoreAsmPrinter.cpp index 3a30f10..6026e12 100644 --- a/lib/Target/XCore/XCoreAsmPrinter.cpp +++ b/lib/Target/XCore/XCoreAsmPrinter.cpp @@ -188,8 +188,10 @@ emitGlobal(const GlobalVariable *GV) case GlobalValue::AppendingLinkage: cerr << "AppendingLinkage is not supported by this target!\n"; abort(); - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: case GlobalValue::ExternalLinkage: emitArrayBound(name, GV); emitGlobalDirective(name); @@ -266,8 +268,10 @@ emitFunctionStart(MachineFunction &MF) case Function::ExternalLinkage: emitGlobalDirective(CurrentFnName); break; - case Function::LinkOnceLinkage: - case Function::WeakLinkage: + case Function::LinkOnceAnyLinkage: + case Function::LinkOnceODRLinkage: + case Function::WeakAnyLinkage: + case Function::WeakODRLinkage: // TODO Use COMDAT groups for LinkOnceLinkage O << TAI->getGlobalDirective() << CurrentFnName << "\n"; O << TAI->getWeakDefDirective() << CurrentFnName << "\n"; @@ -434,7 +438,8 @@ bool XCoreAsmPrinter::doInitialization(Module &M) { switch (I->getLinkage()) { default: assert(0 && "Unexpected linkage"); - case Function::ExternalWeakLinkage: + case Function::ExternalWeakAnyLinkage: + case Function::ExternalWeakODRLinkage: ExtWeakSymbols.insert(I); // fallthrough case Function::ExternalLinkage: diff --git a/lib/Target/XCore/XCoreTargetAsmInfo.cpp b/lib/Target/XCore/XCoreTargetAsmInfo.cpp index 847224c..78eb90c 100644 --- a/lib/Target/XCore/XCoreTargetAsmInfo.cpp +++ b/lib/Target/XCore/XCoreTargetAsmInfo.cpp @@ -73,7 +73,7 @@ XCoreTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) { - if (!GVar->mayBeOverridden()) { + if (!GVar->isWeakForLinker()) { switch (Kind) { case SectionKind::RODataMergeStr: return MergeableStringSection(GVar); diff --git a/lib/Transforms/IPO/IndMemRemoval.cpp b/lib/Transforms/IPO/IndMemRemoval.cpp index 6b1f969..b55dea2 100644 --- a/lib/Transforms/IPO/IndMemRemoval.cpp +++ b/lib/Transforms/IPO/IndMemRemoval.cpp @@ -53,7 +53,7 @@ bool IndMemRemPass::runOnModule(Module &M) { if (Function* F = M.getFunction("free")) { if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) { Function* FN = Function::Create(F->getFunctionType(), - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, "free_llvm_bounce", &M); BasicBlock* bb = BasicBlock::Create("entry",FN); Instruction* R = ReturnInst::Create(bb); @@ -67,7 +67,7 @@ bool IndMemRemPass::runOnModule(Module &M) { if (Function* F = M.getFunction("malloc")) { if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) { Function* FN = Function::Create(F->getFunctionType(), - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, "malloc_llvm_bounce", &M); FN->setDoesNotAlias(0); BasicBlock* bb = BasicBlock::Create("entry",FN); diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index b9f13d9..209ba92 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/lib/Transforms/Utils/InlineCost.cpp @@ -182,12 +182,9 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, // Don't inline functions which can be redefined at link-time to mean // something else. - // FIXME: We allow link-once linkage since in practice all versions of - // the function have the same body (C++ ODR) - but the LLVM definition - // of LinkOnceLinkage doesn't require this. - if ((Callee->mayBeOverridden() && !Callee->hasLinkOnceLinkage()) || - // Don't inline functions marked noinline. - Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee)) + if (Callee->mayBeOverridden() || + // Don't inline functions marked noinline. + Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee)) return llvm::InlineCost::getNever(); // InlineCost - This value measures how good of an inline candidate this call diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index 20cff90..b0364ec 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/lib/Transforms/Utils/LowerInvoke.cpp @@ -139,7 +139,7 @@ bool LowerInvoke::doInitialization(Module &M) { // already exists. if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) { JBListHead = new GlobalVariable(PtrJBList, false, - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, Constant::getNullValue(PtrJBList), "llvm.sjljeh.jblist", &M); } diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 239760d..12a8ed6 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1183,22 +1183,26 @@ void AssemblyWriter::printModule(const Module *M) { static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) { switch (LT) { - case GlobalValue::PrivateLinkage: Out << "private "; break; - case GlobalValue::InternalLinkage: Out << "internal "; break; - case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break; - case GlobalValue::WeakLinkage: Out << "weak "; break; - case GlobalValue::CommonLinkage: Out << "common "; break; - case GlobalValue::AppendingLinkage: Out << "appending "; break; - case GlobalValue::DLLImportLinkage: Out << "dllimport "; break; - case GlobalValue::DLLExportLinkage: Out << "dllexport "; break; - case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break; + case GlobalValue::PrivateLinkage: Out << "private "; break; + case GlobalValue::InternalLinkage: Out << "internal "; break; + case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break; + case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break; + case GlobalValue::WeakAnyLinkage: Out << "weak "; break; + case GlobalValue::WeakODRLinkage: Out << "weak_odr "; break; + case GlobalValue::CommonAnyLinkage: Out << "common "; break; + case GlobalValue::CommonODRLinkage: Out << "common_odr "; break; + case GlobalValue::AppendingLinkage: Out << "appending "; break; + case GlobalValue::DLLImportLinkage: Out << "dllimport "; break; + case GlobalValue::DLLExportLinkage: Out << "dllexport "; break; + case GlobalValue::ExternalWeakAnyLinkage: Out << "extern_weak "; break; + case GlobalValue::ExternalWeakODRLinkage: Out << "extern_weak_odr "; break; case GlobalValue::ExternalLinkage: break; case GlobalValue::GhostLinkage: Out << "GhostLinkage not allowed in AsmWriter!\n"; abort(); } } - + static void PrintVisibility(GlobalValue::VisibilityTypes Vis, raw_ostream &Out) { diff --git a/utils/emacs/llvm-mode.el b/utils/emacs/llvm-mode.el index 0590099..55c56da 100644 --- a/utils/emacs/llvm-mode.el +++ b/utils/emacs/llvm-mode.el @@ -27,7 +27,7 @@ ;; Hex constants '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face) ;; Keywords - '("\\bbegin\\b\\|\\bend\\b\\|\\btrue\\b\\|\\bfalse\\b\\|\\bzeroinitializer\\b\\|\\bdeclare\\b\\|\\bdefine\\b\\|\\bglobal\\b\\|\\bconstant\\b\\|\\bconst\\b\\|\\binternal\\b\\|\\blinkonce\\b\\|\\bweak\\b\\|\\bappending\\b\\|\\buninitialized\\b\\|\\bimplementation\\b\\|\\b\\.\\.\\.\\b\\|\\bnull\\b\\|\\bundef\\b\\|\\bto\\b\\|\\bexcept\\b\\|\\bnot\\b\\|\\btarget\\b\\|\\bendian\\b\\|\\blittle\\b\\|\\bbig\\b\\|\\bpointersize\\b\\|\\bdeplibs\\b\\|\\bvolatile\\b\\|\\bfastcc\\b\\|\\bcoldcc\\b\\|\\bcc\\b" . font-lock-keyword-face) + '("\\bbegin\\b\\|\\bend\\b\\|\\btrue\\b\\|\\bfalse\\b\\|\\bzeroinitializer\\b\\|\\bdeclare\\b\\|\\bdefine\\b\\|\\bglobal\\b\\|\\bconstant\\b\\|\\bconst\\b\\|\\binternal\\b\\|\\blinkonce\\b\\|\\blinkonce_odr\\b\\|\\bweak\\b\\|\\bweak_odr\\b\\|\\bappending\\b\\|\\buninitialized\\b\\|\\bimplementation\\b\\|\\b\\.\\.\\.\\b\\|\\bnull\\b\\|\\bundef\\b\\|\\bto\\b\\|\\bexcept\\b\\|\\bnot\\b\\|\\btarget\\b\\|\\bendian\\b\\|\\blittle\\b\\|\\bbig\\b\\|\\bpointersize\\b\\|\\bdeplibs\\b\\|\\bvolatile\\b\\|\\bfastcc\\b\\|\\bcoldcc\\b\\|\\bcc\\b" . font-lock-keyword-face) ;; Arithmetic and Logical Operators '("\\badd\\b\\|\\bsub\\b\\|\\bmul\\b\\|\\bdiv\\b\\|\\brem\\b\\|\\band\\b\\|\\bor\\b\\|\\bxor\\b\\|\\bset\\(ne\\b\\|\\beq\\b\\|\\blt\\b\\|\\bgt\\b\\|\\ble\\b\\|\\bge\\b\\)" . font-lock-keyword-face) ;; Special instructions diff --git a/utils/llvm.grm b/utils/llvm.grm index 7025fbd..641ba01 100644 --- a/utils/llvm.grm +++ b/utils/llvm.grm @@ -82,15 +82,19 @@ GlobalAssign ::= GlobalName "=" ; GVInternalLinkage ::= + internal | weak + | "weak_odr" | linkonce + | "linkonce_odr" | appending | dllexport | common + | "common_odr" ; GVExternalLinkage ::= dllimport | "extern_weak" + | "extern_weak_odr" | + external ; @@ -105,17 +109,20 @@ FunctionDeclareLinkage ::= + _ | dllimport | "extern_weak" + | "extern_weak_odr" ; FunctionDefineLinkage ::= + _ | internal | linkonce + | "linkonce_odr" | weak + | "weak_odr" | dllexport ; -AliasLinkage ::= + _ | weak | internal ; +AliasLinkage ::= + _ | weak | "weak_odr" | internal ; OptCallingConv ::= + _ | ccc | diff --git a/utils/vim/llvm.vim b/utils/vim/llvm.vim index 2edba8e..89787f80 100644 --- a/utils/vim/llvm.vim +++ b/utils/vim/llvm.vim @@ -40,7 +40,8 @@ syn keyword llvmStatement extractvalue insertvalue " Keywords. syn keyword llvmKeyword define declare global constant syn keyword llvmKeyword internal external -syn keyword llvmKeyword linkonce weak appending common extern_weak +syn keyword llvmKeyword linkonce linkonce_odr weak weak_odr appending +syn keyword llvmKeyword common common_odr extern_weak extern_weak_odr syn keyword llvmKeyword thread_local dllimport dllexport syn keyword llvmKeyword hidden protected default syn keyword llvmKeyword except deplibs |