llvm.org GIT mirror llvm / 5e721d7
Implement the "linker_private_weak" linkage type. This will be used for Objective-C metadata types which should be marked as "weak", but which the linker will remove upon final linkage. However, this linkage isn't specific to Objective-C. For example, the "objc_msgSend_fixup_alloc" symbol is defined like this: .globl l_objc_msgSend_fixup_alloc .weak_definition l_objc_msgSend_fixup_alloc .section __DATA, __objc_msgrefs, coalesced .align 3 l_objc_msgSend_fixup_alloc: .quad _objc_msgSend_fixup .quad L_OBJC_METH_VAR_NAME_1 This is different from the "linker_private" linkage type, because it can't have the metadata defined with ".weak_definition". Currently only supported on Darwin platforms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107433 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
21 changed file(s) with 90 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
315315 LLVMExternalWeakLinkage,
316316 LLVMGhostLinkage,
317317 LLVMCommonLinkage,
318 LLVMLinkerPrivateLinkage);
318 LLVMLinkerPrivateLinkage,
319 LLVMLinkerPrivateWeakLinkage);
319320
320321 for LLVMLinkage use
321322 (LLVMExternalLinkage => 0,
332333 LLVMExternalWeakLinkage => 11,
333334 LLVMGhostLinkage => 12,
334335 LLVMCommonLinkage => 13,
335 LLVMLinkerPrivateLinkage => 14);
336 LLVMLinkerPrivateLinkage => 14,
337 LLVMLinkerPrivateWeakLinkage => 15);
336338
337339 pragma Convention (C, LLVMLinkage);
338340
2323
2424
  • 'private' Linkage
  • 2525
  • 'linker_private' Linkage
  • 26
  • 'linker_private_weak' Linkage
  • 2627
  • 'internal' Linkage
  • 2728
  • 'available_externally' Linkage
  • 2829
  • 'linkonce' Linkage
  • 545546
    546547
    547548
    private
    548
    Global values with private linkage are only directly accessible by objects
    549 in the current module. In particular, linking code into a module with an
    550 private global value may cause the private to be renamed as necessary to
    551 avoid collisions. Because the symbol is private to the module, all
    552 references can be updated. This doesn't show up in any symbol table in the
    553 object file.
    549
    Global values with "private" linkage are only directly accessible
    550 by objects in the current module. In particular, linking code into a
    551 module with an private global value may cause the private to be renamed as
    552 necessary to avoid collisions. Because the symbol is private to the
    553 module, all references can be updated. This doesn't show up in any symbol
    554 table in the object file.
    554555
    555556
    linker_private
    556
    Similar to private, but the symbol is passed through the assembler and
    557 removed by the linker after evaluation. Note that (unlike private
    558 symbols) linker_private symbols are subject to coalescing by the linker:
    559 weak symbols get merged and redefinitions are rejected. However, unlike
    560 normal strong symbols, they are removed by the linker from the final
    561 linked image (executable or dynamic library).
    557
    Similar to private, but the symbol is passed through the
    558 assembler and evaluated by the linker. Unlike normal strong symbols, they
    559 are removed by the linker from the final linked image (executable or
    560 dynamic library).
    561
    562
    linker_private_weak
    563
    Similar to "linker_private", but the symbol is weak. Note that
    564 linker_private_weak symbols are subject to coalescing by the
    565 linker. The symbols are removed by the linker from the final linked image
    566 (executable or dynamic library).
    562567
    563568
    internal
    564569
    Similar to private, but the value shows as a local symbol
    622627
    weak_odr
    623628
    Some languages allow differing globals to be merged, such as two functions
    624629 with different semantics. Other languages, such as C++, ensure
    625 that only equivalent globals are ever merged (the "one definition rule" -
    626 "ODR"). Such languages can use the linkonce_odr
    630 that only equivalent globals are ever merged (the "one definition rule"
    631 — "ODR"). Such languages can use the linkonce_odr
    627632 and weak_odr linkage types to indicate that the global will only
    628633 be merged with equivalent globals. These linkage types are otherwise the
    629634 same as their non-odr versions.
    3939 InternalLinkage, ///< Rename collisions when linking (static functions).
    4040 PrivateLinkage, ///< Like Internal, but omit from symbol table.
    4141 LinkerPrivateLinkage, ///< Like Private, but linker removes.
    42 LinkerPrivateWeakLinkage, ///< Like LinkerPrivate, but weak.
    4243 DLLImportLinkage, ///< Function to be imported from DLL
    4344 DLLExportLinkage, ///< Function to be accessible from DLL.
    4445 ExternalWeakLinkage,///< ExternalWeak linkage description.
    131132 return Linkage == PrivateLinkage;
    132133 }
    133134 static bool isLinkerPrivateLinkage(LinkageTypes Linkage) {
    134 return Linkage==LinkerPrivateLinkage;
    135 return Linkage == LinkerPrivateLinkage;
    136 }
    137 static bool isLinkerPrivateWeakLinkage(LinkageTypes Linkage) {
    138 return Linkage == LinkerPrivateWeakLinkage;
    135139 }
    136140 static bool isLocalLinkage(LinkageTypes Linkage) {
    137141 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage) ||
    138 isLinkerPrivateLinkage(Linkage);
    142 isLinkerPrivateLinkage(Linkage) || isLinkerPrivateWeakLinkage(Linkage);
    139143 }
    140144 static bool isDLLImportLinkage(LinkageTypes Linkage) {
    141145 return Linkage == DLLImportLinkage;
    157161 return (Linkage == WeakAnyLinkage ||
    158162 Linkage == LinkOnceAnyLinkage ||
    159163 Linkage == CommonLinkage ||
    160 Linkage == ExternalWeakLinkage);
    164 Linkage == ExternalWeakLinkage ||
    165 Linkage == LinkerPrivateWeakLinkage);
    161166 }
    162167
    163168 /// isWeakForLinker - Whether the definition of this global may be replaced at
    169174 Linkage == LinkOnceAnyLinkage ||
    170175 Linkage == LinkOnceODRLinkage ||
    171176 Linkage == CommonLinkage ||
    172 Linkage == ExternalWeakLinkage);
    177 Linkage == ExternalWeakLinkage ||
    178 Linkage == LinkerPrivateWeakLinkage);
    173179 }
    174180
    175181 bool hasExternalLinkage() const { return isExternalLinkage(Linkage); }
    186192 bool hasInternalLinkage() const { return isInternalLinkage(Linkage); }
    187193 bool hasPrivateLinkage() const { return isPrivateLinkage(Linkage); }
    188194 bool hasLinkerPrivateLinkage() const { return isLinkerPrivateLinkage(Linkage); }
    195 bool hasLinkerPrivateWeakLinkage() const {
    196 return isLinkerPrivateWeakLinkage(Linkage);
    197 }
    189198 bool hasLocalLinkage() const { return isLocalLinkage(Linkage); }
    190199 bool hasDLLImportLinkage() const { return isDLLImportLinkage(Linkage); }
    191200 bool hasDLLExportLinkage() const { return isDLLExportLinkage(Linkage); }
    225225 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
    226226 LLVMGhostLinkage, /**< Obsolete */
    227227 LLVMCommonLinkage, /**< Tentative definitions */
    228 LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
    228 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
    229 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
    229230 } LLVMLinkage;
    230231
    231232 typedef enum {
    491491
    492492 KEYWORD(private);
    493493 KEYWORD(linker_private);
    494 KEYWORD(linker_private_weak);
    494495 KEYWORD(internal);
    495496 KEYWORD(available_externally);
    496497 KEYWORD(linkonce);
    195195 // optional leading prefixes, the production is:
    196196 // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
    197197 // OptionalAddrSpace ('constant'|'global') ...
    198 case lltok::kw_private : // OptionalLinkage
    199 case lltok::kw_linker_private: // OptionalLinkage
    200 case lltok::kw_internal: // OptionalLinkage
    201 case lltok::kw_weak: // OptionalLinkage
    202 case lltok::kw_weak_odr: // OptionalLinkage
    203 case lltok::kw_linkonce: // OptionalLinkage
    204 case lltok::kw_linkonce_odr: // OptionalLinkage
    205 case lltok::kw_appending: // OptionalLinkage
    206 case lltok::kw_dllexport: // OptionalLinkage
    207 case lltok::kw_common: // OptionalLinkage
    208 case lltok::kw_dllimport: // OptionalLinkage
    209 case lltok::kw_extern_weak: // OptionalLinkage
    210 case lltok::kw_external: { // OptionalLinkage
    198 case lltok::kw_private: // OptionalLinkage
    199 case lltok::kw_linker_private: // OptionalLinkage
    200 case lltok::kw_linker_private_weak: // OptionalLinkage
    201 case lltok::kw_internal: // OptionalLinkage
    202 case lltok::kw_weak: // OptionalLinkage
    203 case lltok::kw_weak_odr: // OptionalLinkage
    204 case lltok::kw_linkonce: // OptionalLinkage
    205 case lltok::kw_linkonce_odr: // OptionalLinkage
    206 case lltok::kw_appending: // OptionalLinkage
    207 case lltok::kw_dllexport: // OptionalLinkage
    208 case lltok::kw_common: // OptionalLinkage
    209 case lltok::kw_dllimport: // OptionalLinkage
    210 case lltok::kw_extern_weak: // OptionalLinkage
    211 case lltok::kw_external: { // OptionalLinkage
    211212 unsigned Linkage, Visibility;
    212213 if (ParseOptionalLinkage(Linkage) ||
    213214 ParseOptionalVisibility(Visibility) ||
    628629 Linkage != GlobalValue::WeakODRLinkage &&
    629630 Linkage != GlobalValue::InternalLinkage &&
    630631 Linkage != GlobalValue::PrivateLinkage &&
    631 Linkage != GlobalValue::LinkerPrivateLinkage)
    632 Linkage != GlobalValue::LinkerPrivateLinkage &&
    633 Linkage != GlobalValue::LinkerPrivateWeakLinkage)
    632634 return Error(LinkageLoc, "invalid linkage type for alias");
    633635
    634636 Constant *Aliasee;
    10121014 /// ::= /*empty*/
    10131015 /// ::= 'private'
    10141016 /// ::= 'linker_private'
    1017 /// ::= 'linker_private_weak'
    10151018 /// ::= 'internal'
    10161019 /// ::= 'weak'
    10171020 /// ::= 'weak_odr'
    10181021 /// ::= 'linkonce'
    10191022 /// ::= 'linkonce_odr'
    1023 /// ::= 'available_externally'
    10201024 /// ::= 'appending'
    10211025 /// ::= 'dllexport'
    10221026 /// ::= 'common'
    10291033 default: Res=GlobalValue::ExternalLinkage; return false;
    10301034 case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
    10311035 case lltok::kw_linker_private: Res = GlobalValue::LinkerPrivateLinkage; break;
    1036 case lltok::kw_linker_private_weak:
    1037 Res = GlobalValue::LinkerPrivateWeakLinkage;
    1038 break;
    10321039 case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
    10331040 case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break;
    10341041 case lltok::kw_weak_odr: Res = GlobalValue::WeakODRLinkage; break;
    27032710 break;
    27042711 case GlobalValue::PrivateLinkage:
    27052712 case GlobalValue::LinkerPrivateLinkage:
    2713 case GlobalValue::LinkerPrivateWeakLinkage:
    27062714 case GlobalValue::InternalLinkage:
    27072715 case GlobalValue::AvailableExternallyLinkage:
    27082716 case GlobalValue::LinkOnceAnyLinkage:
    3636 kw_declare, kw_define,
    3737 kw_global, kw_constant,
    3838
    39 kw_private, kw_linker_private, kw_internal, kw_linkonce, kw_linkonce_odr,
    40 kw_weak, kw_weak_odr, kw_appending, kw_dllimport, kw_dllexport, kw_common,
    41 kw_available_externally,
    39 kw_private, kw_linker_private, kw_linker_private_weak, kw_internal,
    40 kw_linkonce, kw_linkonce_odr, kw_weak, kw_weak_odr, kw_appending,
    41 kw_dllimport, kw_dllexport, kw_common, kw_available_externally,
    4242 kw_default, kw_hidden, kw_protected,
    4343 kw_extern_weak,
    4444 kw_external, kw_thread_local,
    7474 case 11: return GlobalValue::LinkOnceODRLinkage;
    7575 case 12: return GlobalValue::AvailableExternallyLinkage;
    7676 case 13: return GlobalValue::LinkerPrivateLinkage;
    77 case 14: return GlobalValue::LinkerPrivateWeakLinkage;
    7778 }
    7879 }
    7980
    312312 case GlobalValue::LinkOnceODRLinkage: return 11;
    313313 case GlobalValue::AvailableExternallyLinkage: return 12;
    314314 case GlobalValue::LinkerPrivateLinkage: return 13;
    315 case GlobalValue::LinkerPrivateWeakLinkage: return 14;
    315316 }
    316317 }
    317318
    199199 case GlobalValue::WeakAnyLinkage:
    200200 case GlobalValue::WeakODRLinkage:
    201201 case GlobalValue::LinkerPrivateLinkage:
    202 case GlobalValue::LinkerPrivateWeakLinkage:
    202203 if (MAI->getWeakDefDirective() != 0) {
    203204 // .globl _foo
    204205 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
    285285 Out << "GlobalValue::PrivateLinkage"; break;
    286286 case GlobalValue::LinkerPrivateLinkage:
    287287 Out << "GlobalValue::LinkerPrivateLinkage"; break;
    288 case GlobalValue::LinkerPrivateWeakLinkage:
    289 Out << "GlobalValue::LinkerPrivateWeakLinkage"; break;
    288290 case GlobalValue::AvailableExternallyLinkage:
    289291 Out << "GlobalValue::AvailableExternallyLinkage "; break;
    290292 case GlobalValue::LinkOnceAnyLinkage:
    179179 ManglerPrefixTy PrefixTy = Mangler::Default;
    180180 if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
    181181 PrefixTy = Mangler::Private;
    182 else if (GV->hasLinkerPrivateLinkage())
    182 else if (GV->hasLinkerPrivateLinkage() || GV->hasLinkerPrivateWeakLinkage())
    183183 PrefixTy = Mangler::LinkerPrivate;
    184184
    185185 // If this global has a name, handle it simply.
    137137 // FALL THROUGH
    138138 case GlobalValue::InternalLinkage:
    139139 case GlobalValue::PrivateLinkage:
    140 case GlobalValue::LinkerPrivateLinkage:
    141140 break;
    142141 case GlobalValue::DLLImportLinkage:
    143142 llvm_unreachable("DLLImport linkage is not supported by this target!");
    534534 case GlobalValue::WeakAnyLinkage:
    535535 case GlobalValue::WeakODRLinkage:
    536536 case GlobalValue::ExternalWeakLinkage:
    537 case GlobalValue::LinkerPrivateWeakLinkage:
    537538 return ExternalWeak;
    538539
    539540 case GlobalValue::ExternalLinkage:
    14181418 case GlobalValue::ExternalLinkage: break;
    14191419 case GlobalValue::PrivateLinkage: Out << "private "; break;
    14201420 case GlobalValue::LinkerPrivateLinkage: Out << "linker_private "; break;
    1421 case GlobalValue::LinkerPrivateWeakLinkage:
    1422 Out << "linker_private_weak ";
    1423 break;
    14211424 case GlobalValue::InternalLinkage: Out << "internal "; break;
    14221425 case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break;
    14231426 case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break;
    10571057 return LLVMPrivateLinkage;
    10581058 case GlobalValue::LinkerPrivateLinkage:
    10591059 return LLVMLinkerPrivateLinkage;
    1060 case GlobalValue::LinkerPrivateWeakLinkage:
    1061 return LLVMLinkerPrivateWeakLinkage;
    10601062 case GlobalValue::DLLImportLinkage:
    10611063 return LLVMDLLImportLinkage;
    10621064 case GlobalValue::DLLExportLinkage:
    11071109 case LLVMLinkerPrivateLinkage:
    11081110 GV->setLinkage(GlobalValue::LinkerPrivateLinkage);
    11091111 break;
    1112 case LLVMLinkerPrivateWeakLinkage:
    1113 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
    1114 break;
    11101115 case LLVMDLLImportLinkage:
    11111116 GV->setLinkage(GlobalValue::DLLImportLinkage);
    11121117 break;
    11
    22 ; ModuleID = '/Volumes/MacOS9/tests/WebKit/JavaScriptCore/profiler/ProfilerServer.mm'
    33
    4 @"\01l_objc_msgSend_fixup_alloc" = linker_private hidden global i32 0, section "__DATA, __objc_msgrefs, coalesced", align 16 ; [#uses=0]
    4 @"\01l_objc_msgSend_fixup_alloc" = linker_private_weak hidden global i32 0, section "__DATA, __objc_msgrefs, coalesced", align 16
    55
    66 ; CHECK: .globl l_objc_msgSend_fixup_alloc
    77 ; CHECK: .weak_definition l_objc_msgSend_fixup_alloc
    11
    22 ; ModuleID = '/Volumes/MacOS9/tests/WebKit/JavaScriptCore/profiler/ProfilerServer.mm'
    33
    4 @"\01l_objc_msgSend_fixup_alloc" = linker_private hidden global i32 0, section "__DATA, __objc_msgrefs, coalesced", align 16 ; [#uses=0]
    4 @"\01l_objc_msgSend_fixup_alloc" = linker_private_weak hidden global i32 0, section "__DATA, __objc_msgrefs, coalesced", align 16
    55
    66 ; CHECK: .globl l_objc_msgSend_fixup_alloc
    77 ; CHECK: .weak_definition l_objc_msgSend_fixup_alloc
    11
    22 ; ModuleID = '/Volumes/MacOS9/tests/WebKit/JavaScriptCore/profiler/ProfilerServer.mm'
    33
    4 @"\01l_objc_msgSend_fixup_alloc" = linker_private hidden global i32 0, section "__DATA, __objc_msgrefs, coalesced", align 16 ; [#uses=0]
    4 @"\01l_objc_msgSend_fixup_alloc" = linker_private_weak hidden global i32 0, section "__DATA, __objc_msgrefs, coalesced", align 16
    55
    66 ; CHECK: .globl l_objc_msgSend_fixup_alloc
    77 ; CHECK: .weak_definition l_objc_msgSend_fixup_alloc
    0 ; RUN: llvm-as < %s | llvm-dis > %t1.ll
    1 ; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
    2 ; RUN: diff %t1.ll %t2.ll
    3
    4 @foo = linker_private hidden global i32 0
    5 @bar = linker_private_weak hidden global i32 0
    8888 static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
    8989 // Private linkage and available_externally linkage don't exist in symtab.
    9090 if (GV.hasPrivateLinkage() || GV.hasLinkerPrivateLinkage() ||
    91 GV.hasAvailableExternallyLinkage()) return;
    91 GV.hasLinkerPrivateWeakLinkage() || GV.hasAvailableExternallyLinkage())
    92 return;
    9293
    9394 const std::string SymbolAddrStr = " "; // Not used yet...
    9495 char TypeChar = TypeCharForSymbol(GV);