llvm.org GIT mirror llvm / 55ae515
Create the new linker type "linker_private_weak_def_auto". It's similar to "linker_private_weak", but it's known that the address of the object is not taken. For instance, functions that had an inline definition, but the compiler decided not to inline it. Note, unlike linker_private and linker_private_weak, linker_private_weak_def_auto may have only default visibility. The symbols are removed by the linker from the final linked image (executable or dynamic library). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111684 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
15 changed file(s) with 91 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
2424
  • 'private' Linkage
  • 2525
  • 'linker_private' Linkage
  • 2626
  • 'linker_private_weak' Linkage
  • 27
  • 'linker_private_weak_def_auto' Linkage
  • 2728
  • 'internal' Linkage
  • 2829
  • 'available_externally' Linkage
  • 2930
  • 'linkonce' Linkage
  • 556557 linker. The symbols are removed by the linker from the final linked image
    557558 (executable or dynamic library).
    558559
    560
    linker_private_weak_def_auto
    561
    Similar to "linker_private_weak", but it's known that the address
    562 of the object is not taken. For instance, functions that had an inline
    563 definition, but the compiler decided not to inline it. Note,
    564 unlike linker_private and linker_private_weak,
    565 linker_private_weak_def_auto may have only default
    566 visibility. The symbols are removed by the linker from the final linked
    567 image (executable or dynamic library).
    568
    559569
    internal
    560570
    Similar to private, but the value shows as a local symbol
    561571 (STB_LOCAL in the case of ELF) in the object file. This
    4040 PrivateLinkage, ///< Like Internal, but omit from symbol table.
    4141 LinkerPrivateLinkage, ///< Like Private, but linker removes.
    4242 LinkerPrivateWeakLinkage, ///< Like LinkerPrivate, but weak.
    43 LinkerPrivateWeakDefAutoLinkage, ///< Like LinkerPrivateWeak, but possibly
    44 /// hidden.
    4345 DLLImportLinkage, ///< Function to be imported from DLL
    4446 DLLExportLinkage, ///< Function to be accessible from DLL.
    4547 ExternalWeakLinkage,///< ExternalWeak linkage description.
    136138 static bool isLinkerPrivateWeakLinkage(LinkageTypes Linkage) {
    137139 return Linkage == LinkerPrivateWeakLinkage;
    138140 }
    141 static bool isLinkerPrivateWeakDefAutoLinkage(LinkageTypes Linkage) {
    142 return Linkage == LinkerPrivateWeakDefAutoLinkage;
    143 }
    139144 static bool isLocalLinkage(LinkageTypes Linkage) {
    140145 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage) ||
    141 isLinkerPrivateLinkage(Linkage) || isLinkerPrivateWeakLinkage(Linkage);
    146 isLinkerPrivateLinkage(Linkage) || isLinkerPrivateWeakLinkage(Linkage) ||
    147 isLinkerPrivateWeakDefAutoLinkage(Linkage);
    142148 }
    143149 static bool isDLLImportLinkage(LinkageTypes Linkage) {
    144150 return Linkage == DLLImportLinkage;
    157163 /// by something non-equivalent at link time. For example, if a function has
    158164 /// weak linkage then the code defining it may be replaced by different code.
    159165 static bool mayBeOverridden(LinkageTypes Linkage) {
    160 return (Linkage == WeakAnyLinkage ||
    161 Linkage == LinkOnceAnyLinkage ||
    162 Linkage == CommonLinkage ||
    163 Linkage == ExternalWeakLinkage ||
    164 Linkage == LinkerPrivateWeakLinkage);
    166 return Linkage == WeakAnyLinkage ||
    167 Linkage == LinkOnceAnyLinkage ||
    168 Linkage == CommonLinkage ||
    169 Linkage == ExternalWeakLinkage ||
    170 Linkage == LinkerPrivateWeakLinkage ||
    171 Linkage == LinkerPrivateWeakDefAutoLinkage;
    165172 }
    166173
    167174 /// isWeakForLinker - Whether the definition of this global may be replaced at
    168175 /// link time.
    169176 static bool isWeakForLinker(LinkageTypes Linkage) {
    170 return (Linkage == AvailableExternallyLinkage ||
    171 Linkage == WeakAnyLinkage ||
    172 Linkage == WeakODRLinkage ||
    173 Linkage == LinkOnceAnyLinkage ||
    174 Linkage == LinkOnceODRLinkage ||
    175 Linkage == CommonLinkage ||
    176 Linkage == ExternalWeakLinkage ||
    177 Linkage == LinkerPrivateWeakLinkage);
    177 return Linkage == AvailableExternallyLinkage ||
    178 Linkage == WeakAnyLinkage ||
    179 Linkage == WeakODRLinkage ||
    180 Linkage == LinkOnceAnyLinkage ||
    181 Linkage == LinkOnceODRLinkage ||
    182 Linkage == CommonLinkage ||
    183 Linkage == ExternalWeakLinkage ||
    184 Linkage == LinkerPrivateWeakLinkage ||
    185 Linkage == LinkerPrivateWeakDefAutoLinkage;
    178186 }
    179187
    180188 bool hasExternalLinkage() const { return isExternalLinkage(Linkage); }
    194202 bool hasLinkerPrivateWeakLinkage() const {
    195203 return isLinkerPrivateWeakLinkage(Linkage);
    196204 }
    205 bool hasLinkerPrivateWeakDefAutoLinkage() const {
    206 return isLinkerPrivateWeakDefAutoLinkage(Linkage);
    207 }
    197208 bool hasLocalLinkage() const { return isLocalLinkage(Linkage); }
    198209 bool hasDLLImportLinkage() const { return isDLLImportLinkage(Linkage); }
    199210 bool hasDLLExportLinkage() const { return isDLLExportLinkage(Linkage); }
    226226 LLVMGhostLinkage, /**< Obsolete */
    227227 LLVMCommonLinkage, /**< Tentative definitions */
    228228 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
    229 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
    229 LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
    230 LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
    231 hidden. */
    230232 } LLVMLinkage;
    231233
    232234 typedef enum {
    492492 KEYWORD(private);
    493493 KEYWORD(linker_private);
    494494 KEYWORD(linker_private_weak);
    495 KEYWORD(linker_private_weak_def_auto);
    495496 KEYWORD(internal);
    496497 KEYWORD(available_externally);
    497498 KEYWORD(linkonce);
    198198 case lltok::kw_private: // OptionalLinkage
    199199 case lltok::kw_linker_private: // OptionalLinkage
    200200 case lltok::kw_linker_private_weak: // OptionalLinkage
    201 case lltok::kw_linker_private_weak_def_auto: // OptionalLinkage
    201202 case lltok::kw_internal: // OptionalLinkage
    202203 case lltok::kw_weak: // OptionalLinkage
    203204 case lltok::kw_weak_odr: // OptionalLinkage
    622623 Linkage != GlobalValue::InternalLinkage &&
    623624 Linkage != GlobalValue::PrivateLinkage &&
    624625 Linkage != GlobalValue::LinkerPrivateLinkage &&
    625 Linkage != GlobalValue::LinkerPrivateWeakLinkage)
    626 Linkage != GlobalValue::LinkerPrivateWeakLinkage &&
    627 Linkage != GlobalValue::LinkerPrivateWeakDefAutoLinkage)
    626628 return Error(LinkageLoc, "invalid linkage type for alias");
    627629
    628630 Constant *Aliasee;
    10071009 /// ::= 'private'
    10081010 /// ::= 'linker_private'
    10091011 /// ::= 'linker_private_weak'
    1012 /// ::= 'linker_private_weak_def_auto'
    10101013 /// ::= 'internal'
    10111014 /// ::= 'weak'
    10121015 /// ::= 'weak_odr'
    10271030 case lltok::kw_linker_private: Res = GlobalValue::LinkerPrivateLinkage; break;
    10281031 case lltok::kw_linker_private_weak:
    10291032 Res = GlobalValue::LinkerPrivateWeakLinkage;
    1033 break;
    1034 case lltok::kw_linker_private_weak_def_auto:
    1035 Res = GlobalValue::LinkerPrivateWeakDefAutoLinkage;
    10301036 break;
    10311037 case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
    10321038 case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break;
    27172723 case GlobalValue::PrivateLinkage:
    27182724 case GlobalValue::LinkerPrivateLinkage:
    27192725 case GlobalValue::LinkerPrivateWeakLinkage:
    2726 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
    27202727 case GlobalValue::InternalLinkage:
    27212728 case GlobalValue::AvailableExternallyLinkage:
    27222729 case GlobalValue::LinkOnceAnyLinkage:
    3636 kw_declare, kw_define,
    3737 kw_global, kw_constant,
    3838
    39 kw_private, kw_linker_private, kw_linker_private_weak, kw_internal,
    39 kw_private, kw_linker_private, kw_linker_private_weak,
    40 kw_linker_private_weak_def_auto, kw_internal,
    4041 kw_linkonce, kw_linkonce_odr, kw_weak, kw_weak_odr, kw_appending,
    4142 kw_dllimport, kw_dllexport, kw_common, kw_available_externally,
    4243 kw_default, kw_hidden, kw_protected,
    7676 case 12: return GlobalValue::AvailableExternallyLinkage;
    7777 case 13: return GlobalValue::LinkerPrivateLinkage;
    7878 case 14: return GlobalValue::LinkerPrivateWeakLinkage;
    79 case 15: return GlobalValue::LinkerPrivateWeakDefAutoLinkage;
    7980 }
    8081 }
    8182
    298298 static unsigned getEncodedLinkage(const GlobalValue *GV) {
    299299 switch (GV->getLinkage()) {
    300300 default: llvm_unreachable("Invalid linkage!");
    301 case GlobalValue::ExternalLinkage: return 0;
    302 case GlobalValue::WeakAnyLinkage: return 1;
    303 case GlobalValue::AppendingLinkage: return 2;
    304 case GlobalValue::InternalLinkage: return 3;
    305 case GlobalValue::LinkOnceAnyLinkage: return 4;
    306 case GlobalValue::DLLImportLinkage: return 5;
    307 case GlobalValue::DLLExportLinkage: return 6;
    308 case GlobalValue::ExternalWeakLinkage: return 7;
    309 case GlobalValue::CommonLinkage: return 8;
    310 case GlobalValue::PrivateLinkage: return 9;
    311 case GlobalValue::WeakODRLinkage: return 10;
    312 case GlobalValue::LinkOnceODRLinkage: return 11;
    313 case GlobalValue::AvailableExternallyLinkage: return 12;
    314 case GlobalValue::LinkerPrivateLinkage: return 13;
    315 case GlobalValue::LinkerPrivateWeakLinkage: return 14;
    301 case GlobalValue::ExternalLinkage: return 0;
    302 case GlobalValue::WeakAnyLinkage: return 1;
    303 case GlobalValue::AppendingLinkage: return 2;
    304 case GlobalValue::InternalLinkage: return 3;
    305 case GlobalValue::LinkOnceAnyLinkage: return 4;
    306 case GlobalValue::DLLImportLinkage: return 5;
    307 case GlobalValue::DLLExportLinkage: return 6;
    308 case GlobalValue::ExternalWeakLinkage: return 7;
    309 case GlobalValue::CommonLinkage: return 8;
    310 case GlobalValue::PrivateLinkage: return 9;
    311 case GlobalValue::WeakODRLinkage: return 10;
    312 case GlobalValue::LinkOnceODRLinkage: return 11;
    313 case GlobalValue::AvailableExternallyLinkage: return 12;
    314 case GlobalValue::LinkerPrivateLinkage: return 13;
    315 case GlobalValue::LinkerPrivateWeakLinkage: return 14;
    316 case GlobalValue::LinkerPrivateWeakDefAutoLinkage: return 15;
    316317 }
    317318 }
    318319
    199199 case GlobalValue::WeakAnyLinkage:
    200200 case GlobalValue::WeakODRLinkage:
    201201 case GlobalValue::LinkerPrivateWeakLinkage:
    202 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
    202203 if (MAI->getWeakDefDirective() != 0) {
    203204 // .globl _foo
    204205 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
    205 // .weak_definition _foo
    206 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_WeakDefinition);
    206
    207 if ((GlobalValue::LinkageTypes)Linkage !=
    208 GlobalValue::LinkerPrivateWeakDefAutoLinkage)
    209 // .weak_definition _foo
    210 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_WeakDefinition);
    211 else
    212 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_WeakDefAutoPrivate);
    207213 } else if (MAI->getLinkOnceDirective() != 0) {
    208214 // .globl _foo
    209215 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
    287287 Out << "GlobalValue::LinkerPrivateLinkage"; break;
    288288 case GlobalValue::LinkerPrivateWeakLinkage:
    289289 Out << "GlobalValue::LinkerPrivateWeakLinkage"; break;
    290 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
    291 Out << "GlobalValue::LinkerPrivateWeakDefAutoLinkage"; break;
    290292 case GlobalValue::AvailableExternallyLinkage:
    291293 Out << "GlobalValue::AvailableExternallyLinkage "; break;
    292294 case GlobalValue::LinkOnceAnyLinkage:
    179179 ManglerPrefixTy PrefixTy = Mangler::Default;
    180180 if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
    181181 PrefixTy = Mangler::Private;
    182 else if (GV->hasLinkerPrivateLinkage() || GV->hasLinkerPrivateWeakLinkage())
    182 else if (GV->hasLinkerPrivateLinkage() || GV->hasLinkerPrivateWeakLinkage() ||
    183 GV->hasLinkerPrivateWeakDefAutoLinkage())
    183184 PrefixTy = Mangler::LinkerPrivate;
    184185
    185186 // If this global has a name, handle it simply.
    14341434 case GlobalValue::LinkerPrivateWeakLinkage:
    14351435 Out << "linker_private_weak ";
    14361436 break;
    1437 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
    1438 Out << "linker_private_weak_def_auto ";
    1439 break;
    14371440 case GlobalValue::InternalLinkage: Out << "internal "; break;
    14381441 case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break;
    14391442 case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break;
    10681068 return LLVMLinkerPrivateLinkage;
    10691069 case GlobalValue::LinkerPrivateWeakLinkage:
    10701070 return LLVMLinkerPrivateWeakLinkage;
    1071 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
    1072 return LLVMLinkerPrivateWeakDefAutoLinkage;
    10711073 case GlobalValue::DLLImportLinkage:
    10721074 return LLVMDLLImportLinkage;
    10731075 case GlobalValue::DLLExportLinkage:
    11211123 case LLVMLinkerPrivateWeakLinkage:
    11221124 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
    11231125 break;
    1126 case LLVMLinkerPrivateWeakDefAutoLinkage:
    1127 GV->setLinkage(GlobalValue::LinkerPrivateWeakDefAutoLinkage);
    1128 break;
    11241129 case LLVMDLLImportLinkage:
    11251130 GV->setLinkage(GlobalValue::DLLImportLinkage);
    11261131 break;
    445445 Assert1(GVar && GVar->getType()->getElementType()->isArrayTy(),
    446446 "Only global arrays can have appending linkage!", GVar);
    447447 }
    448
    449 Assert1(!GV.hasLinkerPrivateWeakDefAutoLinkage() || GV.hasDefaultVisibility(),
    450 "linker_private_weak_def_auto can only have default visibility!",
    451 &GV);
    448452 }
    449453
    450454 void Verifier::visitGlobalVariable(GlobalVariable &GV) {
    33
    44 @foo = linker_private hidden global i32 0
    55 @bar = linker_private_weak hidden global i32 0
    6 @qux = linker_private_weak_def_auto global i32 0