llvm.org GIT mirror llvm / 667d4b8
Introduce new linkage types linkonce_odr, weak_odr, common_odr and extern_weak_odr. These are the same as the non-odr versions, except that they indicate that the global will only be overridden by an *equivalent* global. In C, a function with weak linkage can be overridden by a function which behaves completely differently. This means that IP passes have to skip weak functions, since any deductions made from the function definition might be wrong, since the definition could be replaced by something completely different at link time. This is not allowed in C++, thanks to the ODR (One-Definition-Rule): if a function is replaced by another at link-time, then the new function must be the same as the original function. If a language knows that a function or other global can only be overridden by an equivalent global, it can give it the weak_odr linkage type, and the optimizers will understand that it is alright to make deductions based on the function body. The code generators on the other hand map weak and weak_odr linkage to the same thing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 10 years ago
43 changed file(s) with 370 addition(s) and 192 deletion(s). Raw diff Collapse all Expand all
544544
545545
546546
extern_weak:
547
547548
The semantics of this linkage follow the ELF object file model: the
548549 symbol is weak until linked, if not linked, the symbol becomes null instead
549550 of being an undefined reference.
551
552
553
linkonce_odr:
554
common_odr:
555
weak_odr:
556
extern_weak_odr:
557
Some languages allow inequivalent globals to be merged, such as two
558 functions with different semantics. Other languages, such as C++,
559 ensure that only equivalent globals are ever merged (the "one definition
560 rule" - odr). Such languages can use the linkonce_odr,
561 common_odr, weak_odr and extern_weak_odr linkage
562 types to indicate that the global will only be merged with equivalent
563 globals. These linkage types are otherwise the same as their
564 non-odr versions.
550565
551566
552567
externally visible:
591606 outside of the current module.

592607

It is illegal for a function declaration

593608 to have any linkage type other than "externally visible", dllimport,
594 or extern_weak.

595

Aliases can have only external, internal and weak

596 linkages.

609 extern_weak or extern_weak_odr.

610

Aliases can have only external, internal, weak

611 or weak_odr linkages.

597612
598613
599614
33213321

Create a new global variable of the specified type. If

33223322 isConstant is true then the global variable will be marked as
33233323 unchanging for the program. The Linkage parameter specifies the type of
3324 linkage (internal, external, weak, linkonce, appending) for the variable. If
3325 the linkage is InternalLinkage, WeakLinkage, or LinkOnceLinkage,  then
3326 the resultant global variable will have internal linkage. AppendingLinkage
3327 concatenates together all instances (in different translation units) of the
3328 variable into a single variable but is only applicable to arrays.  See
3324 linkage (internal, external, weak, linkonce, appending) for the variable.
3325 If the linkage is InternalLinkage, WeakAnyLinkage, WeakODRLinkage,
3326 LinkOnceAnyLinkage or LinkOnceODRLinkage,  then the resultant
3327 global variable will have internal linkage. AppendingLinkage concatenates
3328 together all instances (in different translation units) of the variable
3329 into a single variable but is only applicable to arrays.  See
33293330 the LLVM Language Reference for
33303331 further details on linkage types. Optionally an initializer, a name, and the
33313332 module to put the variable into may be specified for the global variable as
3030 /// @brief An enumeration for the kinds of linkage for global values.
3131 enum LinkageTypes {
3232 ExternalLinkage = 0,///< Externally visible function
33 LinkOnceLinkage, ///< Keep one copy of function when linking (inline)
34 WeakLinkage, ///< Keep one copy of named function when linking (weak)
33 LinkOnceAnyLinkage, ///< Keep one copy of function when linking (inline)
34 LinkOnceODRLinkage, ///< Same, but only replaced by something equivalent.
35 WeakAnyLinkage, ///< Keep one copy of named function when linking (weak)
36 WeakODRLinkage, ///< Same, but only replaced by something equivalent.
3537 AppendingLinkage, ///< Special purpose, only applies to global arrays
3638 InternalLinkage, ///< Rename collisions when linking (static functions)
3739 PrivateLinkage, ///< Like Internal, but omit from symbol table
3840 DLLImportLinkage, ///< Function to be imported from DLL
3941 DLLExportLinkage, ///< Function to be accessible from DLL
40 ExternalWeakLinkage,///< ExternalWeak linkage description
42 ExternalWeakAnyLinkage,///< ExternalWeak linkage description
43 ExternalWeakODRLinkage,///< Same, but only replaced by something equivalent.
4144 GhostLinkage, ///< Stand-in functions for streaming fns from BC files
42 CommonLinkage ///< Tentative definitions
45 CommonAnyLinkage, ///< Tentative definitions
46 CommonODRLinkage ///< Same, but only replaced by something equivalent.
4347 };
4448
4549 /// @brief An enumeration for the kinds of visibility of global values.
98102 return reinterpret_cast(User::getType());
99103 }
100104
101 bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
102 bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; }
103 bool hasWeakLinkage() const { return Linkage == WeakLinkage; }
104 bool hasCommonLinkage() const { return Linkage == CommonLinkage; }
105 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
106 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
107 bool hasPrivateLinkage() const { return Linkage == PrivateLinkage; }
108 bool hasLocalLinkage() const {
105 static LinkageTypes getLinkOnceLinkage(bool ODR) {
106 return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage;
107 }
108 static LinkageTypes getWeakLinkage(bool ODR) {
109 return ODR ? WeakODRLinkage : WeakAnyLinkage;
110 }
111 static LinkageTypes getCommonLinkage(bool ODR) {
112 return ODR ? CommonODRLinkage : CommonAnyLinkage;
113 }
114 static LinkageTypes getExternalWeakLinkage(bool ODR) {
115 return ODR ? ExternalWeakODRLinkage : ExternalWeakAnyLinkage;
116 }
117
118 bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
119 bool hasLinkOnceLinkage() const {
120 return Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage;
121 }
122 bool hasWeakLinkage() const {
123 return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage;
124 }
125 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
126 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
127 bool hasPrivateLinkage() const { return Linkage == PrivateLinkage; }
128 bool hasLocalLinkage() const {
109129 return Linkage == InternalLinkage || Linkage == PrivateLinkage;
110130 }
111 bool hasDLLImportLinkage() const { return Linkage == DLLImportLinkage; }
112 bool hasDLLExportLinkage() const { return Linkage == DLLExportLinkage; }
113 bool hasExternalWeakLinkage() const { return Linkage == ExternalWeakLinkage; }
114 bool hasGhostLinkage() const { return Linkage == GhostLinkage; }
131 bool hasDLLImportLinkage() const { return Linkage == DLLImportLinkage; }
132 bool hasDLLExportLinkage() const { return Linkage == DLLExportLinkage; }
133 bool hasExternalWeakLinkage() const {
134 return Linkage == ExternalWeakAnyLinkage ||
135 Linkage == ExternalWeakODRLinkage;
136 }
137 bool hasGhostLinkage() const { return Linkage == GhostLinkage; }
138 bool hasCommonLinkage() const {
139 return Linkage == CommonAnyLinkage || Linkage == CommonODRLinkage;
140 }
141
115142 void setLinkage(LinkageTypes LT) { Linkage = LT; }
116143 LinkageTypes getLinkage() const { return Linkage; }
117144
118145 /// mayBeOverridden - Whether the definition of this global may be replaced
119 /// at link time. For example, if a function has weak linkage then the code
120 /// defining it may be replaced by different code.
146 /// by something non-equivalent at link time. For example, if a function has
147 /// weak linkage then the code defining it may be replaced by different code.
121148 bool mayBeOverridden() const {
122 return (Linkage == WeakLinkage ||
123 Linkage == LinkOnceLinkage ||
124 Linkage == CommonLinkage ||
125 Linkage == ExternalWeakLinkage);
149 return (Linkage == WeakAnyLinkage ||
150 Linkage == LinkOnceAnyLinkage ||
151 Linkage == CommonAnyLinkage ||
152 Linkage == ExternalWeakAnyLinkage);
153 }
154
155 /// isWeakForLinker - Whether the definition of this global may be replaced at
156 /// link time, whether the replacement is equivalent to the original or not.
157 bool isWeakForLinker() const {
158 return (Linkage == WeakAnyLinkage ||
159 Linkage == WeakODRLinkage ||
160 Linkage == LinkOnceAnyLinkage ||
161 Linkage == LinkOnceODRLinkage ||
162 Linkage == CommonAnyLinkage ||
163 Linkage == CommonODRLinkage ||
164 Linkage == ExternalWeakAnyLinkage ||
165 Linkage == ExternalWeakODRLinkage);
126166 }
127167
128168 /// copyAttributesFrom - copy all additional attributes (those not needed to
114114
115115 typedef enum {
116116 LLVMExternalLinkage, /**< Externally visible function */
117 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/
118 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */
117 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
118 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
119 equivalent. */
120 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
121 LLVMWeakODRLinkage, /**< Same, but only replaced by something
122 equivalent. */
119123 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
120124 LLVMInternalLinkage, /**< Rename collisions when linking (static
121125 functions) */
126 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
122127 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
123128 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
124 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
125 LLVMGhostLinkage /**< Stand-in functions for streaming fns from
129 LLVMExternalWeakAnyLinkage,/**< ExternalWeak linkage description */
130 LLVMExternalWeakODRLinkage,/**< Same, but only replaced by something
131 equivalent. */
132 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
126133 bitcode */
134 LLVMCommonAnyLinkage, /**< Tentative definitions */
135 LLVMCommonODRLinkage /**< Same, but only replaced by something
136 equivalent. */
127137 } LLVMLinkage;
128138
129139 typedef enum {
343343 if (GV->hasInitializer())
344344 return SubProgramAnchor = DIAnchor(GV);
345345
346 GV->setLinkage(GlobalValue::LinkOnceLinkage);
346 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
347347 GV->setSection("llvm.metadata");
348348 GV->setConstant(true);
349349 M.addTypeName("llvm.dbg.anchor.type", EltTy);
455455 KEYWORD(private);
456456 KEYWORD(internal);
457457 KEYWORD(linkonce);
458 KEYWORD(linkonce_odr);
458459 KEYWORD(weak);
460 KEYWORD(weak_odr);
459461 KEYWORD(appending);
460462 KEYWORD(dllimport);
461463 KEYWORD(dllexport);
462464 KEYWORD(common);
465 KEYWORD(common_odr);
463466 KEYWORD(default);
464467 KEYWORD(hidden);
465468 KEYWORD(protected);
466469 KEYWORD(extern_weak);
470 KEYWORD(extern_weak_odr);
467471 KEYWORD(external);
468472 KEYWORD(thread_local);
469473 KEYWORD(zeroinitializer);
115115 case lltok::kw_private: // OptionalLinkage
116116 case lltok::kw_internal: // OptionalLinkage
117117 case lltok::kw_weak: // OptionalLinkage
118 case lltok::kw_weak_odr: // OptionalLinkage
118119 case lltok::kw_linkonce: // OptionalLinkage
120 case lltok::kw_linkonce_odr: // OptionalLinkage
119121 case lltok::kw_appending: // OptionalLinkage
120122 case lltok::kw_dllexport: // OptionalLinkage
121123 case lltok::kw_common: // OptionalLinkage
124 case lltok::kw_common_odr: // OptionalLinkage
122125 case lltok::kw_dllimport: // OptionalLinkage
123126 case lltok::kw_extern_weak: // OptionalLinkage
127 case lltok::kw_extern_weak_odr: // OptionalLinkage
124128 case lltok::kw_external: { // OptionalLinkage
125129 unsigned Linkage, Visibility;
126130 if (ParseOptionalLinkage(Linkage) ||
376380 return true;
377381
378382 if (Linkage != GlobalValue::ExternalLinkage &&
379 Linkage != GlobalValue::WeakLinkage &&
383 Linkage != GlobalValue::WeakAnyLinkage &&
384 Linkage != GlobalValue::WeakODRLinkage &&
380385 Linkage != GlobalValue::InternalLinkage &&
381386 Linkage != GlobalValue::PrivateLinkage)
382387 return Error(LinkageLoc, "invalid linkage type for alias");
460465 // present.
461466 Constant *Init = 0;
462467 if (!HasLinkage || (Linkage != GlobalValue::DLLImportLinkage &&
463 Linkage != GlobalValue::ExternalWeakLinkage &&
468 Linkage != GlobalValue::ExternalWeakAnyLinkage &&
469 Linkage != GlobalValue::ExternalWeakODRLinkage &&
464470 Linkage != GlobalValue::ExternalLinkage)) {
465471 if (ParseGlobalValue(Ty, Init))
466472 return true;
575581 return 0;
576582 }
577583
578 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
584 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakAnyLinkage, Name, M);
579585 } else {
580586 FwdVal = new GlobalVariable(PTy->getElementType(), false,
581 GlobalValue::ExternalWeakLinkage, 0, Name, M);
587 GlobalValue::ExternalWeakAnyLinkage, 0, Name, M);
582588 }
583589
584590 ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
619625 Error(Loc, "function may not return opaque type");
620626 return 0;
621627 }
622 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
628 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakAnyLinkage, "", M);
623629 } else {
624630 FwdVal = new GlobalVariable(PTy->getElementType(), false,
625 GlobalValue::ExternalWeakLinkage, 0, "", M);
631 GlobalValue::ExternalWeakAnyLinkage, 0, "", M);
626632 }
627633
628634 ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
745751 /// ::= 'private'
746752 /// ::= 'internal'
747753 /// ::= 'weak'
754 /// ::= 'weak_odr'
748755 /// ::= 'linkonce'
756 /// ::= 'linkonce_odr'
749757 /// ::= 'appending'
750758 /// ::= 'dllexport'
751759 /// ::= 'common'
760 /// ::= 'common_odr'
752761 /// ::= 'dllimport'
753762 /// ::= 'extern_weak'
763 /// ::= 'extern_weak_odr'
754764 /// ::= 'external'
755765 bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
756766 HasLinkage = false;
757767 switch (Lex.getKind()) {
758 default: Res = GlobalValue::ExternalLinkage; return false;
759 case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
760 case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
761 case lltok::kw_weak: Res = GlobalValue::WeakLinkage; break;
762 case lltok::kw_linkonce: Res = GlobalValue::LinkOnceLinkage; break;
763 case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break;
764 case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break;
765 case lltok::kw_common: Res = GlobalValue::CommonLinkage; break;
766 case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break;
767 case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break;
768 case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break;
768 default: Res = GlobalValue::ExternalLinkage; return false;
769 case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
770 case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
771 case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break;
772 case lltok::kw_weak_odr: Res = GlobalValue::WeakODRLinkage; break;
773 case lltok::kw_linkonce: Res = GlobalValue::LinkOnceAnyLinkage; break;
774 case lltok::kw_linkonce_odr: Res = GlobalValue::LinkOnceODRLinkage; break;
775 case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break;
776 case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break;
777 case lltok::kw_common: Res = GlobalValue::CommonAnyLinkage; break;
778 case lltok::kw_common_odr: Res = GlobalValue::CommonODRLinkage; break;
779 case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break;
780 case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakAnyLinkage; break;
781 case lltok::kw_extern_weak_odr:
782 Res = GlobalValue::ExternalWeakODRLinkage; break;
783 case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break;
769784 }
770785 Lex.Lex();
771786 HasLinkage = true;
20732088 case GlobalValue::ExternalLinkage:
20742089 break; // always ok.
20752090 case GlobalValue::DLLImportLinkage:
2076 case GlobalValue::ExternalWeakLinkage:
2091 case GlobalValue::ExternalWeakAnyLinkage:
2092 case GlobalValue::ExternalWeakODRLinkage:
20772093 if (isDefine)
20782094 return Error(LinkageLoc, "invalid linkage for function definition");
20792095 break;
20802096 case GlobalValue::PrivateLinkage:
20812097 case GlobalValue::InternalLinkage:
2082 case GlobalValue::LinkOnceLinkage:
2083 case GlobalValue::WeakLinkage:
2098 case GlobalValue::LinkOnceAnyLinkage:
2099 case GlobalValue::LinkOnceODRLinkage:
2100 case GlobalValue::WeakAnyLinkage:
2101 case GlobalValue::WeakODRLinkage:
20842102 case GlobalValue::DLLExportLinkage:
20852103 if (!isDefine)
20862104 return Error(LinkageLoc, "invalid linkage for function declaration");
20872105 break;
20882106 case GlobalValue::AppendingLinkage:
20892107 case GlobalValue::GhostLinkage:
2090 case GlobalValue::CommonLinkage:
2108 case GlobalValue::CommonAnyLinkage:
2109 case GlobalValue::CommonODRLinkage:
20912110 return Error(LinkageLoc, "invalid function linkage type");
20922111 }
20932112
3535 kw_declare, kw_define,
3636 kw_global, kw_constant,
3737
38 kw_private, kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport,
39 kw_dllexport, kw_common, kw_default, kw_hidden, kw_protected,
40 kw_extern_weak,
38 kw_private, kw_internal, kw_linkonce, kw_linkonce_odr, kw_weak, kw_weak_odr,
39 kw_appending, kw_dllimport, kw_dllexport, kw_common, kw_common_odr,
40 kw_default, kw_hidden, kw_protected,
41 kw_extern_weak, kw_extern_weak_odr,
4142 kw_external, kw_thread_local,
4243 kw_zeroinitializer,
4344 kw_undef, kw_null,
5858 switch (Val) {
5959 default: // Map unknown/new linkages to external
6060 case 0: return GlobalValue::ExternalLinkage;
61 case 1: return GlobalValue::WeakLinkage;
61 case 1: return GlobalValue::WeakAnyLinkage;
6262 case 2: return GlobalValue::AppendingLinkage;
6363 case 3: return GlobalValue::InternalLinkage;
64 case 4: return GlobalValue::LinkOnceLinkage;
64 case 4: return GlobalValue::LinkOnceAnyLinkage;
6565 case 5: return GlobalValue::DLLImportLinkage;
6666 case 6: return GlobalValue::DLLExportLinkage;
67 case 7: return GlobalValue::ExternalWeakLinkage;
68 case 8: return GlobalValue::CommonLinkage;
67 case 7: return GlobalValue::ExternalWeakAnyLinkage;
68 case 8: return GlobalValue::CommonAnyLinkage;
6969 case 9: return GlobalValue::PrivateLinkage;
70 case 10: return GlobalValue::WeakODRLinkage;
71 case 11: return GlobalValue::LinkOnceODRLinkage;
72 case 12: return GlobalValue::ExternalWeakODRLinkage;
73 case 13: return GlobalValue::CommonODRLinkage;
7074 }
7175 }
7276
275275 default: assert(0 && "Invalid linkage!");
276276 case GlobalValue::GhostLinkage: // Map ghost linkage onto external.
277277 case GlobalValue::ExternalLinkage: return 0;
278 case GlobalValue::WeakLinkage: return 1;
278 case GlobalValue::WeakAnyLinkage: return 1;
279279 case GlobalValue::AppendingLinkage: return 2;
280280 case GlobalValue::InternalLinkage: return 3;
281 case GlobalValue::LinkOnceLinkage: return 4;
281 case GlobalValue::LinkOnceAnyLinkage: return 4;
282282 case GlobalValue::DLLImportLinkage: return 5;
283283 case GlobalValue::DLLExportLinkage: return 6;
284 case GlobalValue::ExternalWeakLinkage: return 7;
285 case GlobalValue::CommonLinkage: return 8;
284 case GlobalValue::ExternalWeakAnyLinkage: return 7;
285 case GlobalValue::CommonAnyLinkage: return 8;
286286 case GlobalValue::PrivateLinkage: return 9;
287 case GlobalValue::WeakODRLinkage: return 10;
288 case GlobalValue::LinkOnceODRLinkage: return 11;
289 case GlobalValue::ExternalWeakODRLinkage: return 12;
290 case GlobalValue::CommonODRLinkage: return 13;
287291 }
288292 }
289293
31343134 GlobalVariable *GV = getGlobalVariable(V);
31353135 if (!GV)
31363136 return false;
3137
3138 if (GV->getLinkage() != GlobalValue::InternalLinkage
3139 && GV->getLinkage() != GlobalValue::LinkOnceLinkage)
3137
3138 if (!GV->hasInternalLinkage () && !GV->hasLinkOnceLinkage())
31403139 return false;
31413140
31423141 DIDescriptor DI(GV);
34483447 }
34493448
34503449 // If corresponding function is weak definition, this should be too.
3451 if ((linkage == Function::WeakLinkage ||
3452 linkage == Function::LinkOnceLinkage) &&
3450 if ((linkage == Function::WeakAnyLinkage ||
3451 linkage == Function::WeakODRLinkage ||
3452 linkage == Function::LinkOnceAnyLinkage ||
3453 linkage == Function::LinkOnceODRLinkage) &&
34533454 TAI->getWeakDefDirective())
34543455 O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
34553456
34603461 // unwind info is to be available for non-EH uses.
34613462 if (!EHFrameInfo.hasCalls &&
34623463 !UnwindTablesMandatory &&
3463 ((linkage != Function::WeakLinkage &&
3464 linkage != Function::LinkOnceLinkage) ||
3464 ((linkage != Function::WeakAnyLinkage &&
3465 linkage != Function::WeakODRLinkage &&
3466 linkage != Function::LinkOnceAnyLinkage &&
3467 linkage != Function::LinkOnceODRLinkage) ||
34653468 !TAI->getWeakDefDirective() ||
34663469 TAI->getSupportsWeakOmittedEHFrame()))
34673470 {
173173 case GlobalValue::ExternalLinkage:
174174 FnSym.SetBind(ELFWriter::ELFSym::STB_GLOBAL);
175175 break;
176 case GlobalValue::LinkOnceLinkage:
177 case GlobalValue::WeakLinkage:
176 case GlobalValue::LinkOnceAnyLinkage:
177 case GlobalValue::LinkOnceODRLinkage:
178 case GlobalValue::WeakAnyLinkage:
179 case GlobalValue::WeakODRLinkage:
178180 FnSym.SetBind(ELFWriter::ELFSym::STB_WEAK);
179181 break;
180182 case GlobalValue::PrivateLinkage:
315315 Name[i] = '_';
316316 Module* M = F->getParent();
317317 F = cast(M->getOrInsertFunction(Name, FT));
318 F->setLinkage(GlobalValue::WeakLinkage);
318 F->setLinkage(GlobalValue::WeakAnyLinkage);
319319
320320 // If we haven't defined the impl function yet, do so now
321321 if (F->isDeclaration()) {
489489 Name[i] = '_';
490490 Module* M = F->getParent();
491491 F = cast(M->getOrInsertFunction(Name, FT));
492 F->setLinkage(GlobalValue::WeakLinkage);
492 F->setLinkage(GlobalValue::WeakAnyLinkage);
493493
494494 // If we haven't defined the impl function yet, do so now
495495 if (F->isDeclaration()) {
955955 default:
956956 assert(0 && "Unexpected linkage type!");
957957 break;
958 case GlobalValue::WeakLinkage:
959 case GlobalValue::LinkOnceLinkage:
960 case GlobalValue::CommonLinkage:
958 case GlobalValue::WeakAnyLinkage:
959 case GlobalValue::WeakODRLinkage:
960 case GlobalValue::LinkOnceAnyLinkage:
961 case GlobalValue::LinkOnceODRLinkage:
962 case GlobalValue::CommonAnyLinkage:
963 case GlobalValue::CommonODRLinkage:
961964 assert(!isa(gv) && "Unexpected linkage type for Function!");
962965 case GlobalValue::ExternalLinkage:
963966 GVName = TAI->getGlobalPrefix() + name;
727727 if (getTargetMachine().getRelocationModel() == Reloc::DynamicNoPIC &&
728728 GA &&
729729 !GA->getGlobal()->isDeclaration() &&
730 !GA->getGlobal()->mayBeOverridden())
730 !GA->getGlobal()->isWeakForLinker())
731731 return true;
732732
733733 // Otherwise assume nothing is safe.
292292 // If the root chain does not exist, insert a new one with linkonce
293293 // linkage!
294294 Head = new GlobalVariable(StackEntryPtrTy, false,
295 GlobalValue::LinkOnceLinkage,
295 GlobalValue::LinkOnceAnyLinkage,
296296 Constant::getNullValue(StackEntryPtrTy),
297297 "llvm_gc_root_chain", &M);
298298 } else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
299299 Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
300 Head->setLinkage(GlobalValue::LinkOnceLinkage);
300 Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);
301301 }
302302
303303 return true;
579579 }
580580
581581 if (F->isDeclaration()) {
582 bool AbortOnFailure = !areDlsymStubsEnabled() &&
583 F->getLinkage() != GlobalValue::ExternalWeakLinkage;
582 bool AbortOnFailure =
583 !areDlsymStubsEnabled() && !F->hasExternalWeakLinkage();
584584 void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure);
585585 addGlobalMapping(F, Addr);
586586 return Addr;
459459 LT = Src->getLinkage();
460460 }
461461 } else if (Dest->hasExternalWeakLinkage()) {
462 //If the Dest is weak, use the source linkage
462 // If the Dest is weak, use the source linkage.
463463 LinkFromSrc = true;
464464 LT = Src->getLinkage();
465465 } else {
682682
683683 static GlobalValue::LinkageTypes
684684 CalculateAliasLinkage(const GlobalValue *SGV, const GlobalValue *DGV) {
685 if (SGV->hasExternalLinkage() || DGV->hasExternalLinkage())
685 GlobalValue::LinkageTypes SL = SGV->getLinkage();
686 GlobalValue::LinkageTypes DL = DGV->getLinkage();
687 if (SL == GlobalValue::ExternalLinkage || DL == GlobalValue::ExternalLinkage)
686688 return GlobalValue::ExternalLinkage;
687 else if (SGV->hasWeakLinkage() || DGV->hasWeakLinkage())
688 return GlobalValue::WeakLinkage;
689 else if (SGV->hasInternalLinkage() && DGV->hasInternalLinkage())
689 else if (SL == GlobalValue::WeakAnyLinkage ||
690 DL == GlobalValue::WeakAnyLinkage)
691 return GlobalValue::WeakAnyLinkage;
692 else if (SL == GlobalValue::WeakODRLinkage ||
693 DL == GlobalValue::WeakODRLinkage)
694 return GlobalValue::WeakODRLinkage;
695 else if (SL == GlobalValue::InternalLinkage &&
696 DL == GlobalValue::InternalLinkage)
690697 return GlobalValue::InternalLinkage;
691698 else {
692 assert (SGV->hasPrivateLinkage() && DGV->hasPrivateLinkage() &&
693 "Unexpected linkage type");
699 assert (SL == GlobalValue::PrivateLinkage &&
700 DL == GlobalValue::PrivateLinkage && "Unexpected linkage type");
694701 return GlobalValue::PrivateLinkage;
695702 }
696703 }
853853 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
854854 if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage()))
855855 return false;
856 return RelocM != Reloc::Static && (isDecl || GV->mayBeOverridden());
856 return RelocM != Reloc::Static && (isDecl || GV->isWeakForLinker());
857857 }
858858
859859 SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op,
207207 SwitchToTextSection("\t.text", F);
208208 O << "\t.globl\t" << CurrentFnName << "\n";
209209 break;
210 case Function::WeakLinkage:
211 case Function::LinkOnceLinkage:
210 case Function::WeakAnyLinkage:
211 case Function::WeakODRLinkage:
212 case Function::LinkOnceAnyLinkage:
213 case Function::LinkOnceODRLinkage:
212214 if (Subtarget->isTargetDarwin()) {
213215 SwitchToTextSection(
214216 ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
852854 }
853855 }
854856
855 if (GVar->hasLocalLinkage() || GVar->mayBeOverridden()) {
857 if (GVar->hasLocalLinkage() || GVar->isWeakForLinker()) {
856858 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
857859
858860 if (isDarwin) {
898900
899901 SwitchToSection(TAI->SectionForGlobal(GVar));
900902 switch (GVar->getLinkage()) {
901 case GlobalValue::CommonLinkage:
902 case GlobalValue::LinkOnceLinkage:
903 case GlobalValue::WeakLinkage:
903 case GlobalValue::CommonAnyLinkage:
904 case GlobalValue::CommonODRLinkage:
905 case GlobalValue::LinkOnceAnyLinkage:
906 case GlobalValue::LinkOnceODRLinkage:
907 case GlobalValue::WeakAnyLinkage:
908 case GlobalValue::WeakODRLinkage:
904909 if (isDarwin) {
905910 O << "\t.globl " << name << "\n"
906911 << "\t.weak_definition " << name << "\n";
162162 case Function::ExternalLinkage:
163163 O << "\t.globl " << CurrentFnName << "\n";
164164 break;
165 case Function::WeakLinkage:
166 case Function::LinkOnceLinkage:
165 case Function::WeakAnyLinkage:
166 case Function::WeakODRLinkage:
167 case Function::LinkOnceAnyLinkage:
168 case Function::LinkOnceODRLinkage:
167169 O << TAI->getWeakRefDirective() << CurrentFnName << "\n";
168170 break;
169171 }
230232
231233 // 2: Kind
232234 switch (GVar->getLinkage()) {
233 case GlobalValue::LinkOnceLinkage:
234 case GlobalValue::WeakLinkage:
235 case GlobalValue::CommonLinkage:
235 case GlobalValue::LinkOnceAnyLinkage:
236 case GlobalValue::LinkOnceODRLinkage:
237 case GlobalValue::WeakAnyLinkage:
238 case GlobalValue::WeakODRLinkage:
239 case GlobalValue::CommonAnyLinkage:
240 case GlobalValue::CommonODRLinkage:
236241 O << TAI->getWeakRefDirective() << name << '\n';
237242 break;
238243 case GlobalValue::AppendingLinkage:
444444 O << "\t.global\t" << CurrentFnName << "\n"
445445 << "\t.type\t" << CurrentFnName << ", @function\n";
446446 break;
447 case Function::WeakLinkage:
448 case Function::LinkOnceLinkage:
447 case Function::WeakAnyLinkage:
448 case Function::WeakODRLinkage:
449 case Function::LinkOnceAnyLinkage:
450 case Function::LinkOnceODRLinkage:
449451 O << "\t.global\t" << CurrentFnName << "\n";
450452 O << "\t.weak_definition\t" << CurrentFnName << "\n";
451453 break;
533535 if (C->isNullValue() && /* FIXME: Verify correct */
534536 !GVar->hasSection() &&
535537 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
536 GVar->mayBeOverridden())) {
538 GVar->isWeakForLinker())) {
537539 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
538540
539541 if (GVar->hasExternalLinkage()) {
554556
555557 switch (GVar->getLinkage()) {
556558 // Should never be seen for the CellSPU platform...
557 case GlobalValue::LinkOnceLinkage:
558 case GlobalValue::WeakLinkage:
559 case GlobalValue::CommonLinkage:
559 case GlobalValue::LinkOnceAnyLinkage:
560 case GlobalValue::LinkOnceODRLinkage:
561 case GlobalValue::WeakAnyLinkage:
562 case GlobalValue::WeakODRLinkage:
563 case GlobalValue::CommonAnyLinkage:
564 case GlobalValue::CommonODRLinkage:
560565 O << "\t.global " << name << '\n'
561566 << "\t.type " << name << ", @object\n"
562567 << "\t.weak " << name << '\n';
293293 Out << "GlobalValue::InternalLinkage"; break;
294294 case GlobalValue::PrivateLinkage:
295295 Out << "GlobalValue::PrivateLinkage"; break;
296 case GlobalValue::LinkOnceLinkage:
297 Out << "GlobalValue::LinkOnceLinkage "; break;
298 case GlobalValue::WeakLinkage:
299 Out << "GlobalValue::WeakLinkage"; break;
296 case GlobalValue::LinkOnceAnyLinkage:
297 Out << "GlobalValue::LinkOnceAnyLinkage "; break;
298 case GlobalValue::LinkOnceODRLinkage:
299 Out << "GlobalValue::LinkOnceODRLinkage "; break;
300 case GlobalValue::WeakAnyLinkage:
301 Out << "GlobalValue::WeakAnyLinkage"; break;
302 case GlobalValue::WeakODRLinkage:
303 Out << "GlobalValue::WeakODRLinkage"; break;
300304 case GlobalValue::AppendingLinkage:
301305 Out << "GlobalValue::AppendingLinkage"; break;
302306 case GlobalValue::ExternalLinkage:
305309 Out << "GlobalValue::DLLImportLinkage"; break;
306310 case GlobalValue::DLLExportLinkage:
307311 Out << "GlobalValue::DLLExportLinkage"; break;
308 case GlobalValue::ExternalWeakLinkage:
309 Out << "GlobalValue::ExternalWeakLinkage"; break;
312 case GlobalValue::ExternalWeakAnyLinkage:
313 Out << "GlobalValue::ExternalWeakAnyLinkage"; break;
314 case GlobalValue::ExternalWeakODRLinkage:
315 Out << "GlobalValue::ExternalWeakODRLinkage"; break;
310316 case GlobalValue::GhostLinkage:
311317 Out << "GlobalValue::GhostLinkage"; break;
312 case GlobalValue::CommonLinkage:
313 Out << "GlobalValue::CommonLinkage"; break;
318 case GlobalValue::CommonAnyLinkage:
319 Out << "GlobalValue::CommonAnyLinkage"; break;
320 case GlobalValue::CommonODRLinkage:
321 Out << "GlobalValue::CommonODRLinkage"; break;
314322 }
315323 }
316324
7474 const Section*
7575 DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
7676 SectionKind::Kind Kind = SectionKindForGlobal(GV);
77 bool isWeak = GV->mayBeOverridden();
77 bool isWeak = GV->isWeakForLinker();
7878 bool isNonStatic = TM.getRelocationModel() != Reloc::Static;
7979
8080 switch (Kind) {
4848 case Function::DLLExportLinkage:
4949 case Function::ExternalLinkage:
5050 return TextSection;
51 case Function::WeakLinkage:
52 case Function::LinkOnceLinkage:
51 case Function::WeakAnyLinkage:
52 case Function::WeakODRLinkage:
53 case Function::LinkOnceAnyLinkage:
54 case Function::LinkOnceODRLinkage:
5355 std::string Name = UniqueSectionForGlobal(GV, Kind);
5456 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
5557 return getNamedSection(Name.c_str(), Flags);
5658 }
5759 } else if (const GlobalVariable *GVar = dyn_cast(GV)) {
58 if (GVar->mayBeOverridden()) {
60 if (GVar->isWeakForLinker()) {
5961 std::string Name = UniqueSectionForGlobal(GVar, Kind);
6062 unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str());
6163 return getNamedSection(Name.c_str(), Flags);
277277
278278 if (C->isNullValue() && !GVar->hasSection()) {
279279 if (!GVar->isThreadLocal() &&
280 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
280 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
281281 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
282282
283283 if (GVar->hasLocalLinkage()) {
295295 }
296296
297297 switch (GVar->getLinkage()) {
298 case GlobalValue::LinkOnceLinkage:
299 case GlobalValue::CommonLinkage:
300 case GlobalValue::WeakLinkage:
298 case GlobalValue::LinkOnceAnyLinkage:
299 case GlobalValue::LinkOnceODRLinkage:
300 case GlobalValue::CommonAnyLinkage:
301 case GlobalValue::CommonODRLinkage:
302 case GlobalValue::WeakAnyLinkage:
303 case GlobalValue::WeakODRLinkage:
301304 // Nonnull linkonce -> weak
302305 O << "\t.weak " << name << '\n';
303306 break;
503503
504504 if (C->isNullValue() && !GVar->hasSection()) {
505505 if (!GVar->isThreadLocal() &&
506 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
506 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
507507 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
508508
509509 if (GVar->hasLocalLinkage())
518518 }
519519 }
520520 switch (GVar->getLinkage()) {
521 case GlobalValue::LinkOnceLinkage:
522 case GlobalValue::CommonLinkage:
523 case GlobalValue::WeakLinkage:
521 case GlobalValue::LinkOnceAnyLinkage:
522 case GlobalValue::LinkOnceODRLinkage:
523 case GlobalValue::CommonAnyLinkage:
524 case GlobalValue::CommonODRLinkage:
525 case GlobalValue::WeakAnyLinkage:
526 case GlobalValue::WeakODRLinkage:
524527 // FIXME: Verify correct for weak.
525528 // Nonnull linkonce -> weak
526529 O << "\t.weak " << name << '\n';
8484 SectionKind::Kind K = SectionKindForGlobal(GV);
8585 const GlobalVariable *GVA = dyn_cast(GV);
8686
87 if (GVA && (!GVA->mayBeOverridden()))
87 if (GVA && (!GVA->isWeakForLinker()))
8888 switch (K) {
8989 case SectionKind::SmallData:
9090 return getSmallDataSection();
387387
388388 // External or weakly linked global variables need non-lazily-resolved stubs
389389 if (TM.getRelocationModel() != Reloc::Static) {
390 if (GV->isDeclaration() || GV->mayBeOverridden()) {
390 if (GV->isDeclaration() || GV->isWeakForLinker()) {
391391 if (GV->hasHiddenVisibility()) {
392392 if (!GV->isDeclaration() && !GV->hasCommonLinkage())
393393 O << Name;
591591 O << "\t.global\t" << CurrentFnName << '\n'
592592 << "\t.type\t" << CurrentFnName << ", @function\n";
593593 break;
594 case Function::WeakLinkage:
595 case Function::LinkOnceLinkage:
594 case Function::WeakAnyLinkage:
595 case Function::WeakODRLinkage:
596 case Function::LinkOnceAnyLinkage:
597 case Function::LinkOnceODRLinkage:
596598 O << "\t.global\t" << CurrentFnName << '\n';
597599 O << "\t.weak\t" << CurrentFnName << '\n';
598600 break;
688690 if (C->isNullValue() && /* FIXME: Verify correct */
689691 !GVar->hasSection() &&
690692 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
691 GVar->mayBeOverridden())) {
693 GVar->isWeakForLinker())) {
692694 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
693695
694696 if (GVar->hasExternalLinkage()) {
708710 }
709711
710712 switch (GVar->getLinkage()) {
711 case GlobalValue::LinkOnceLinkage:
712 case GlobalValue::WeakLinkage:
713 case GlobalValue::CommonLinkage:
713 case GlobalValue::LinkOnceAnyLinkage:
714 case GlobalValue::LinkOnceODRLinkage:
715 case GlobalValue::WeakAnyLinkage:
716 case GlobalValue::WeakODRLinkage:
717 case GlobalValue::CommonAnyLinkage:
718 case GlobalValue::CommonODRLinkage:
714719 O << "\t.global " << name << '\n'
715720 << "\t.type " << name << ", @object\n"
716721 << "\t.weak " << name << '\n';
784789 case Function::ExternalLinkage:
785790 O << "\t.globl\t" << CurrentFnName << '\n';
786791 break;
787 case Function::WeakLinkage:
788 case Function::LinkOnceLinkage:
792 case Function::WeakAnyLinkage:
793 case Function::WeakODRLinkage:
794 case Function::LinkOnceAnyLinkage:
795 case Function::LinkOnceODRLinkage:
789796 O << "\t.globl\t" << CurrentFnName << '\n';
790797 O << "\t.weak_definition\t" << CurrentFnName << '\n';
791798 break;
917924 if (C->isNullValue() && /* FIXME: Verify correct */
918925 !GVar->hasSection() &&
919926 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
920 GVar->mayBeOverridden()) &&
927 GVar->isWeakForLinker()) &&
921928 TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) {
922929 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
923930
949956 }
950957
951958 switch (GVar->getLinkage()) {
952 case GlobalValue::LinkOnceLinkage:
953 case GlobalValue::WeakLinkage:
954 case GlobalValue::CommonLinkage:
959 case GlobalValue::LinkOnceAnyLinkage:
960 case GlobalValue::LinkOnceODRLinkage:
961 case GlobalValue::WeakAnyLinkage:
962 case GlobalValue::WeakODRLinkage:
963 case GlobalValue::CommonAnyLinkage:
964 case GlobalValue::CommonODRLinkage:
955965 O << "\t.globl " << name << '\n'
956966 << "\t.weak_definition " << name << '\n';
957967 break;
259259
260260 if (C->isNullValue() && !GVar->hasSection()) {
261261 if (!GVar->isThreadLocal() &&
262 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
262 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
263263 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
264264
265265 if (GVar->hasLocalLinkage())
275275 }
276276
277277 switch (GVar->getLinkage()) {
278 case GlobalValue::CommonLinkage:
279 case GlobalValue::LinkOnceLinkage:
280 case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
278 case GlobalValue::CommonAnyLinkage:
279 case GlobalValue::CommonODRLinkage:
280 case GlobalValue::LinkOnceAnyLinkage:
281 case GlobalValue::LinkOnceODRLinkage:
282 case GlobalValue::WeakAnyLinkage: // FIXME: Verify correct for weak.
283 case GlobalValue::WeakODRLinkage: // FIXME: Verify correct for weak.
281284 // Nonnull linkonce -> weak
282285 O << "\t.weak " << name << '\n';
283286 break;
258258 assert(0 && "Unexpected section kind!");
259259 }
260260
261 if (GV->mayBeOverridden())
261 if (GV->isWeakForLinker())
262262 Flags |= SectionFlags::Linkonce;
263263 }
264264
309309 TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
310310 SectionKind::Kind Kind = SectionKindForGlobal(GV);
311311
312 if (GV->mayBeOverridden()) {
312 if (GV->isWeakForLinker()) {
313313 std::string Name = UniqueSectionForGlobal(GV, Kind);
314314 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
315315 return getNamedSection(Name.c_str(), Flags);
167167 EmitAlignment(FnAlign, F);
168168 O << "\t.globl\t" << CurrentFnName << '\n';
169169 break;
170 case Function::LinkOnceLinkage:
171 case Function::WeakLinkage:
170 case Function::LinkOnceAnyLinkage:
171 case Function::LinkOnceODRLinkage:
172 case Function::WeakAnyLinkage:
173 case Function::WeakODRLinkage:
172174 EmitAlignment(FnAlign, F);
173175 if (Subtarget->isTargetDarwin()) {
174176 O << "\t.globl\t" << CurrentFnName << '\n';
197199 O << CurrentFnName << ":\n";
198200 // Add some workaround for linkonce linkage on Cygwin\MinGW
199201 if (Subtarget->isTargetCygMing() &&
200 (F->getLinkage() == Function::LinkOnceLinkage ||
201 F->getLinkage() == Function::WeakLinkage))
202 (F->hasLinkOnceLinkage() || F->hasWeakLinkage()))
202203 O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n";
203204 }
204205
385386 if (shouldPrintStub(TM, Subtarget)) {
386387 // Link-once, declaration, or Weakly-linked global variables need
387388 // non-lazily-resolved stubs
388 if (GV->isDeclaration() || GV->mayBeOverridden()) {
389 if (GV->isDeclaration() || GV->isWeakForLinker()) {
389390 // Dynamically-resolved functions need a stub for the function.
390391 if (isCallOp && isa(GV)) {
391392 // Function stubs are no longer needed for Mac OS X 10.5 and up.
815816 }
816817
817818 if (!GVar->isThreadLocal() &&
818 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
819 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
819820 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
820821
821822 if (TAI->getLCOMMDirective() != NULL) {
854855 }
855856
856857 switch (GVar->getLinkage()) {
857 case GlobalValue::CommonLinkage:
858 case GlobalValue::LinkOnceLinkage:
859 case GlobalValue::WeakLinkage:
858 case GlobalValue::CommonAnyLinkage:
859 case GlobalValue::CommonODRLinkage:
860 case GlobalValue::LinkOnceAnyLinkage:
861 case GlobalValue::LinkOnceODRLinkage:
862 case GlobalValue::WeakAnyLinkage:
863 case GlobalValue::WeakODRLinkage:
860864 if (Subtarget->isTargetDarwin()) {
861865 O << "\t.globl " << name << '\n'
862866 << TAI->getWeakDefDirective() << name << '\n';
454454 bool bCustomSegment = false;
455455
456456 switch (I->getLinkage()) {
457 case GlobalValue::CommonLinkage:
458 case GlobalValue::LinkOnceLinkage:
459 case GlobalValue::WeakLinkage:
457 case GlobalValue::CommonAnyLinkage:
458 case GlobalValue::CommonODRLinkage:
459 case GlobalValue::LinkOnceAnyLinkage:
460 case GlobalValue::LinkOnceODRLinkage:
461 case GlobalValue::WeakAnyLinkage:
462 case GlobalValue::WeakODRLinkage:
460463 SwitchToDataSection("");
461464 O << name << "?\tsegment common 'COMMON'\n";
462465 bCustomSegment = true;
5050 // target is x86-64 or the symbol is definitely defined in the current
5151 // translation unit.
5252 return false;
53 return !isDirectCall && (isDecl || GV->mayBeOverridden());
53 return !isDirectCall && (isDecl || GV->isWeakForLinker());
5454 } else if (isTargetELF()) {
5555 // Extra load is needed for all externally visible.
5656 if (isDirectCall)
187187 case GlobalValue::AppendingLinkage:
188188 cerr << "AppendingLinkage is not supported by this target!\n";
189189 abort();
190 case GlobalValue::LinkOnceLinkage:
191 case GlobalValue::WeakLinkage:
190 case GlobalValue::LinkOnceAnyLinkage:
191 case GlobalValue::LinkOnceODRLinkage:
192 case GlobalValue::WeakAnyLinkage:
193 case GlobalValue::WeakODRLinkage:
192194 case GlobalValue::ExternalLinkage:
193195 emitArrayBound(name, GV);
194196 emitGlobalDirective(name);
265267 case Function::ExternalLinkage:
266268 emitGlobalDirective(CurrentFnName);
267269 break;
268 case Function::LinkOnceLinkage:
269 case Function::WeakLinkage:
270 case Function::LinkOnceAnyLinkage:
271 case Function::LinkOnceODRLinkage:
272 case Function::WeakAnyLinkage:
273 case Function::WeakODRLinkage:
270274 // TODO Use COMDAT groups for LinkOnceLinkage
271275 O << TAI->getGlobalDirective() << CurrentFnName << "\n";
272276 O << TAI->getWeakDefDirective() << CurrentFnName << "\n";
433437 switch (I->getLinkage()) {
434438 default:
435439 assert(0 && "Unexpected linkage");
436 case Function::ExternalWeakLinkage:
440 case Function::ExternalWeakAnyLinkage:
441 case Function::ExternalWeakODRLinkage:
437442 ExtWeakSymbols.insert(I);
438443 // fallthrough
439444 case Function::ExternalLinkage:
7272
7373 if (const GlobalVariable *GVar = dyn_cast(GV))
7474 {
75 if (!GVar->mayBeOverridden()) {
75 if (!GVar->isWeakForLinker()) {
7676 switch (Kind) {
7777 case SectionKind::RODataMergeStr:
7878 return MergeableStringSection(GVar);
5252 if (Function* F = M.getFunction("free")) {
5353 if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) {
5454 Function* FN = Function::Create(F->getFunctionType(),
55 GlobalValue::LinkOnceLinkage,
55 GlobalValue::LinkOnceAnyLinkage,
5656 "free_llvm_bounce", &M);
5757 BasicBlock* bb = BasicBlock::Create("entry",FN);
5858 Instruction* R = ReturnInst::Create(bb);
6666 if (Function* F = M.getFunction("malloc")) {
6767 if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) {
6868 Function* FN = Function::Create(F->getFunctionType(),
69 GlobalValue::LinkOnceLinkage,
69 GlobalValue::LinkOnceAnyLinkage,
7070 "malloc_llvm_bounce", &M);
7171 FN->setDoesNotAlias(0);
7272 BasicBlock* bb = BasicBlock::Create("entry",FN);
181181
182182 // Don't inline functions which can be redefined at link-time to mean
183183 // something else.
184 // FIXME: We allow link-once linkage since in practice all versions of
185 // the function have the same body (C++ ODR) - but the LLVM definition
186 // of LinkOnceLinkage doesn't require this.
187 if ((Callee->mayBeOverridden() && !Callee->hasLinkOnceLinkage()) ||
188 // Don't inline functions marked noinline.
189 Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee))
184 if (Callee->mayBeOverridden() ||
185 // Don't inline functions marked noinline.
186 Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee))
190187 return llvm::InlineCost::getNever();
191188
192189 // InlineCost - This value measures how good of an inline candidate this call
138138 // already exists.
139139 if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
140140 JBListHead = new GlobalVariable(PtrJBList, false,
141 GlobalValue::LinkOnceLinkage,
141 GlobalValue::LinkOnceAnyLinkage,
142142 Constant::getNullValue(PtrJBList),
143143 "llvm.sjljeh.jblist", &M);
144144 }
11821182
11831183 static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) {
11841184 switch (LT) {
1185 case GlobalValue::PrivateLinkage: Out << "private "; break;
1186 case GlobalValue::InternalLinkage: Out << "internal "; break;
1187 case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
1188 case GlobalValue::WeakLinkage: Out << "weak "; break;
1189 case GlobalValue::CommonLinkage: Out << "common "; break;
1190 case GlobalValue::AppendingLinkage: Out << "appending "; break;
1191 case GlobalValue::DLLImportLinkage: Out << "dllimport "; break;
1192 case GlobalValue::DLLExportLinkage: Out << "dllexport "; break;
1193 case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break;
1185 case GlobalValue::PrivateLinkage: Out << "private "; break;
1186 case GlobalValue::InternalLinkage: Out << "internal "; break;
1187 case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break;
1188 case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break;
1189 case GlobalValue::WeakAnyLinkage: Out << "weak "; break;
1190 case GlobalValue::WeakODRLinkage: Out << "weak_odr "; break;
1191 case GlobalValue::CommonAnyLinkage: Out << "common "; break;
1192 case GlobalValue::CommonODRLinkage: Out << "common_odr "; break;
1193 case GlobalValue::AppendingLinkage: Out << "appending "; break;
1194 case GlobalValue::DLLImportLinkage: Out << "dllimport "; break;
1195 case GlobalValue::DLLExportLinkage: Out << "dllexport "; break;
1196 case GlobalValue::ExternalWeakAnyLinkage: Out << "extern_weak "; break;
1197 case GlobalValue::ExternalWeakODRLinkage: Out << "extern_weak_odr "; break;
11941198 case GlobalValue::ExternalLinkage: break;
11951199 case GlobalValue::GhostLinkage:
11961200 Out << "GhostLinkage not allowed in AsmWriter!\n";
11971201 abort();
11981202 }
11991203 }
1200
1204
12011205
12021206 static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
12031207 raw_ostream &Out) {
2626 ;; Hex constants
2727 '("\\b0x[0-9A-Fa-f]+\\b" . font-lock-preprocessor-face)
2828 ;; Keywords
29 '("\\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)
29 '("\\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)
3030 ;; Arithmetic and Logical Operators
3131 '("\\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)
3232 ;; Special instructions
8181 GVInternalLinkage
8282 ::= + internal
8383 | weak
84 | "weak_odr"
8485 | linkonce
86 | "linkonce_odr"
8587 | appending
8688 | dllexport
8789 | common
90 | "common_odr"
8891 ;
8992
9093 GVExternalLinkage
9194 ::= dllimport
9295 | "extern_weak"
96 | "extern_weak_odr"
9397 | + external
9498 ;
9599
104108 ::= + _
105109 | dllimport
106110 | "extern_weak"
111 | "extern_weak_odr"
107112 ;
108113
109114 FunctionDefineLinkage
110115 ::= + _
111116 | internal
112117 | linkonce
118 | "linkonce_odr"
113119 | weak
120 | "weak_odr"
114121 | dllexport
115122 ;
116123
117 AliasLinkage ::= + _ | weak | internal ;
124 AliasLinkage ::= + _ | weak | "weak_odr" | internal ;
118125
119126 OptCallingConv ::= + _ |
120127 ccc |
3939 " Keywords.
4040 syn keyword llvmKeyword define declare global constant
4141 syn keyword llvmKeyword internal external
42 syn keyword llvmKeyword linkonce weak appending common extern_weak
42 syn keyword llvmKeyword linkonce linkonce_odr weak weak_odr appending
43 syn keyword llvmKeyword common common_odr extern_weak extern_weak_odr
4344 syn keyword llvmKeyword thread_local dllimport dllexport
4445 syn keyword llvmKeyword hidden protected default
4546 syn keyword llvmKeyword except deplibs