llvm.org GIT mirror llvm / 207855c
Introducing the "linker_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. 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". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107205 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
26 changed file(s) with 94 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
315315 LLVMExternalWeakLinkage,
316316 LLVMGhostLinkage,
317317 LLVMCommonLinkage,
318 LLVMLinkerPrivateLinkage);
318 LLVMLinkerPrivateLinkage,
319 LLVMLinkerWeakLinkage);
319320
320321 for LLVMLinkage use
321322 (LLVMExternalLinkage => 0,
332333 LLVMExternalWeakLinkage => 11,
333334 LLVMGhostLinkage => 12,
334335 LLVMCommonLinkage => 13,
335 LLVMLinkerPrivateLinkage => 14);
336 LLVMLinkerPrivateLinkage => 14,
337 LLVMLinkerWeakLinkage => 15);
336338
337339 pragma Convention (C, LLVMLinkage);
338340
2323
2424
  • 'private' Linkage
  • 2525
  • 'linker_private' Linkage
  • 26
  • 'linker_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 removed by the linker after evaluation. Note that (unlike
    559 private symbols) linker_private symbols are subject to
    560 coalescing by the linker: weak symbols get merged and redefinitions are
    561 rejected. However, unlike normal strong symbols, they are removed by the
    562 linker from the final linked image (executable or dynamic library).
    563
    564
    linker_weak
    565
    Global values with "linker_weak" linkage are given weak linkage,
    566 but are removed by the linker after evaluation.
    562567
    563568
    internal
    564
    Similar to private, but the value shows as a local symbol
    569
    Similar to private, but the value shows as a local symbol
    565570 (STB_LOCAL in the case of ELF) in the object file. This
    566571 corresponds to the notion of the 'static' keyword in C.
    567572
    284284 MCSymbol *GetCPISymbol(unsigned CPID) const;
    285285
    286286 /// GetJTISymbol - Return the symbol for the specified jump table entry.
    287 MCSymbol *GetJTISymbol(unsigned JTID, bool isLinkerPrivate = false) const;
    287 MCSymbol *GetJTISymbol(unsigned JTID, bool PassToLinker = false) const;
    288288
    289289 /// GetJTSetSymbol - Return the symbol for the specified jump table .set
    290290 /// FIXME: privatize to AsmPrinter.
    401401 //
    402402
    403403 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
    404 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
    405 /// normal 'L' label is returned.
    406 MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
    407 bool isLinkerPrivate = false) const;
    404 /// If PassToLinker is specified, an 'l' label is returned, otherwise a normal
    405 /// 'L' label is returned.
    406 MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
    407 bool PassToLinker = false) const;
    408408 };
    409409
    410410 //===--------------------------------------------------------------------===//
    3838 AppendingLinkage, ///< Special purpose, only applies to global arrays
    3939 InternalLinkage, ///< Rename collisions when linking (static functions).
    4040 PrivateLinkage, ///< Like Internal, but omit from symbol table.
    41 LinkerPrivateLinkage, ///< Like Private, but linker removes.
    41 LinkerPrivateLinkage, ///< Like private, but linker removes.
    42 LinkerWeakLinkage, ///< Like linker private, 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 isLinkerWeakLinkage(LinkageTypes Linkage) {
    138 return Linkage == LinkerWeakLinkage;
    135139 }
    136140 static bool isLocalLinkage(LinkageTypes Linkage) {
    137141 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage) ||
    186190 bool hasInternalLinkage() const { return isInternalLinkage(Linkage); }
    187191 bool hasPrivateLinkage() const { return isPrivateLinkage(Linkage); }
    188192 bool hasLinkerPrivateLinkage() const { return isLinkerPrivateLinkage(Linkage); }
    193 bool hasLinkerWeakLinkage() const { return isLinkerWeakLinkage(Linkage); }
    189194 bool hasLocalLinkage() const { return isLocalLinkage(Linkage); }
    190195 bool hasDLLImportLinkage() const { return isDLLImportLinkage(Linkage); }
    191196 bool hasDLLExportLinkage() const { return isDLLExportLinkage(Linkage); }
    8484 /// be passed through the assembler but be removed by the linker. This
    8585 /// is "l" on Darwin, currently used for some ObjC metadata.
    8686 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
    87
    88 /// LinkerWeakGlobalPrefix - This prefix is used for symbols that are marked
    89 /// "weak" and should be passed through the assembler, but be removed by the
    90 /// linker. This is "l" on Darwin, currently used for some ObjC metadata.
    91 const char *LinkerWeakGlobalPrefix; // Defaults to ""
    8792
    8893 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
    8994 /// emit before and after an inline assembly statement.
    334339 const char *getLinkerPrivateGlobalPrefix() const {
    335340 return LinkerPrivateGlobalPrefix;
    336341 }
    342 const char *getLinkerWeakGlobalPrefix() const {
    343 return LinkerWeakGlobalPrefix;
    344 }
    337345 const char *getInlineAsmStart() const {
    338346 return InlineAsmStart;
    339347 }
    3131 enum ManglerPrefixTy {
    3232 Default, ///< Emit default string before each symbol.
    3333 Private, ///< Emit "private" prefix before each symbol.
    34 LinkerPrivate ///< Emit "linker private" prefix before each symbol.
    34 LinkerPrivate, ///< Emit "linker private" prefix before each symbol.
    35 LinkerWeak ///< Emit "linker weak" prefix before each symbol.
    3536 };
    3637
    3738 private:
    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 LLVMLinkerWeakLinkage /**< Like linker private, but weak. */
    229230 } LLVMLinkage;
    230231
    231232 typedef enum {
    491491
    492492 KEYWORD(private);
    493493 KEYWORD(linker_private);
    494 KEYWORD(linker_weak);
    494495 KEYWORD(internal);
    495496 KEYWORD(available_externally);
    496497 KEYWORD(linkonce);
    197197 // OptionalAddrSpace ('constant'|'global') ...
    198198 case lltok::kw_private : // OptionalLinkage
    199199 case lltok::kw_linker_private: // OptionalLinkage
    200 case lltok::kw_linker_weak: // OptionalLinkage
    200201 case lltok::kw_internal: // OptionalLinkage
    201202 case lltok::kw_weak: // OptionalLinkage
    202203 case lltok::kw_weak_odr: // OptionalLinkage
    628629 Linkage != GlobalValue::WeakODRLinkage &&
    629630 Linkage != GlobalValue::InternalLinkage &&
    630631 Linkage != GlobalValue::PrivateLinkage &&
    631 Linkage != GlobalValue::LinkerPrivateLinkage)
    632 Linkage != GlobalValue::LinkerPrivateLinkage &&
    633 Linkage != GlobalValue::LinkerWeakLinkage)
    632634 return Error(LinkageLoc, "invalid linkage type for alias");
    633635
    634636 Constant *Aliasee;
    10121014 /// ::= /*empty*/
    10131015 /// ::= 'private'
    10141016 /// ::= 'linker_private'
    1017 /// ::= 'linker_weak'
    10151018 /// ::= 'internal'
    10161019 /// ::= 'weak'
    10171020 /// ::= 'weak_odr'
    10291032 default: Res=GlobalValue::ExternalLinkage; return false;
    10301033 case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
    10311034 case lltok::kw_linker_private: Res = GlobalValue::LinkerPrivateLinkage; break;
    1035 case lltok::kw_linker_weak: Res = GlobalValue::LinkerWeakLinkage; break;
    10321036 case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
    10331037 case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break;
    10341038 case lltok::kw_weak_odr: Res = GlobalValue::WeakODRLinkage; break;
    27032707 break;
    27042708 case GlobalValue::PrivateLinkage:
    27052709 case GlobalValue::LinkerPrivateLinkage:
    2710 case GlobalValue::LinkerWeakLinkage:
    27062711 case GlobalValue::InternalLinkage:
    27072712 case GlobalValue::AvailableExternallyLinkage:
    27082713 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,
    39 kw_private, kw_linker_private, kw_linker_weak, kw_internal, kw_linkonce,
    40 kw_linkonce_odr, kw_weak, kw_weak_odr, kw_appending, kw_dllimport,
    41 kw_dllexport, kw_common,
    4142 kw_available_externally,
    4243 kw_default, kw_hidden, kw_protected,
    4344 kw_extern_weak,
    7474 case 11: return GlobalValue::LinkOnceODRLinkage;
    7575 case 12: return GlobalValue::AvailableExternallyLinkage;
    7676 case 13: return GlobalValue::LinkerPrivateLinkage;
    77 case 14: return GlobalValue::LinkerWeakLinkage;
    7778 }
    7879 }
    7980
    312312 case GlobalValue::LinkOnceODRLinkage: return 11;
    313313 case GlobalValue::AvailableExternallyLinkage: return 12;
    314314 case GlobalValue::LinkerPrivateLinkage: return 13;
    315 case GlobalValue::LinkerWeakLinkage: return 14;
    315316 }
    316317 }
    317318
    198198 case GlobalValue::LinkOnceODRLinkage:
    199199 case GlobalValue::WeakAnyLinkage:
    200200 case GlobalValue::WeakODRLinkage:
    201 case GlobalValue::LinkerWeakLinkage:
    201202 case GlobalValue::LinkerPrivateLinkage:
    202203 if (MAI->getWeakDefDirective() != 0) {
    203204 // .globl _foo
    16091610 }
    16101611
    16111612 /// GetJTISymbol - Return the symbol for the specified jump table entry.
    1612 MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool isLinkerPrivate) const {
    1613 return MF->getJTISymbol(JTID, OutContext, isLinkerPrivate);
    1613 MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool PassToLinker) const {
    1614 return MF->getJTISymbol(JTID, OutContext, PassToLinker);
    16141615 }
    16151616
    16161617 /// GetJTSetSymbol - Return the symbol for the specified jump table .set
    409409 }
    410410
    411411 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
    412 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
    413 /// normal 'L' label is returned.
    414 MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
    415 bool isLinkerPrivate) const {
    412 /// If isLinkerPrivate or isLinkerWeak is specified, an 'l' label is returned,
    413 /// otherwise a normal 'L' label is returned.
    414 MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
    415 bool PassToLinker) const {
    416416 assert(JumpTableInfo && "No jump tables");
    417417
    418418 assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
    419419 const MCAsmInfo &MAI = *getTarget().getMCAsmInfo();
    420420
    421 const char *Prefix = isLinkerPrivate ? MAI.getLinkerPrivateGlobalPrefix() :
    422 MAI.getPrivateGlobalPrefix();
    421 const char *Prefix = PassToLinker ?
    422 MAI.getLinkerPrivateGlobalPrefix() :
    423 MAI.getPrivateGlobalPrefix();
    423424 SmallString<60> Name;
    424425 raw_svector_ostream(Name)
    425426 << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
    754754 /// the directive emitted (this occurs in ObjC metadata).
    755755 if (!GV) return false;
    756756
    757 // Check whether the mangled name has the "Private" or "LinkerPrivate" prefix.
    757 // Check whether the mangled name has the "Private", "LinkerPrivate", or
    758 // "LinkerWeak" prefix.
    758759 if (GV->hasLocalLinkage() && !isa(GV)) {
    759760 // FIXME: ObjC metadata is currently emitted as internal symbols that have
    760 // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and
    761 // this horrible hack can go away.
    761 // \1L and \1l prefixes on them. Fix them to be Private / LinkerPrivate /
    762 // LinkerWeak and this horrible hack can go away.
    762763 MCSymbol *Sym = Mang->getSymbol(GV);
    763764 if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l')
    764765 return false;
    734734 else if (SL == GlobalValue::LinkerPrivateLinkage &&
    735735 DL == GlobalValue::LinkerPrivateLinkage)
    736736 return GlobalValue::LinkerPrivateLinkage;
    737 else if (SL == GlobalValue::LinkerWeakLinkage &&
    738 DL == GlobalValue::LinkerWeakLinkage)
    739 return GlobalValue::LinkerWeakLinkage;
    737740 else {
    738741 assert (SL == GlobalValue::PrivateLinkage &&
    739742 DL == GlobalValue::PrivateLinkage && "Unexpected linkage type");
    3030 GlobalPrefix = "";
    3131 PrivateGlobalPrefix = ".";
    3232 LinkerPrivateGlobalPrefix = "";
    33 LinkerWeakGlobalPrefix = "";
    3334 InlineAsmStart = "APP";
    3435 InlineAsmEnd = "NO_APP";
    3536 AssemblerDialect = 0;
    2020 GlobalPrefix = "_";
    2121 PrivateGlobalPrefix = "L";
    2222 LinkerPrivateGlobalPrefix = "l";
    23 LinkerWeakGlobalPrefix = "l";
    2324 AllowQuotesInName = true;
    2425 HasSingleParameterDotFile = false;
    2526 HasSubsectionsViaSymbols = true;
    285285 Out << "GlobalValue::PrivateLinkage"; break;
    286286 case GlobalValue::LinkerPrivateLinkage:
    287287 Out << "GlobalValue::LinkerPrivateLinkage"; break;
    288 case GlobalValue::LinkerWeakLinkage:
    289 Out << "GlobalValue::LinkerWeakLinkage"; break;
    288290 case GlobalValue::AvailableExternallyLinkage:
    289291 Out << "GlobalValue::AvailableExternallyLinkage "; break;
    290292 case GlobalValue::LinkOnceAnyLinkage:
    116116 OutName.append(Prefix, Prefix+strlen(Prefix));
    117117 } else if (PrefixTy == Mangler::LinkerPrivate) {
    118118 const char *Prefix = MAI.getLinkerPrivateGlobalPrefix();
    119 OutName.append(Prefix, Prefix+strlen(Prefix));
    120 } else if (PrefixTy == Mangler::LinkerWeak) {
    121 const char *Prefix = MAI.getLinkerWeakGlobalPrefix();
    119122 OutName.append(Prefix, Prefix+strlen(Prefix));
    120123 }
    121124
    181184 PrefixTy = Mangler::Private;
    182185 else if (GV->hasLinkerPrivateLinkage())
    183186 PrefixTy = Mangler::LinkerPrivate;
    187 else if (GV->hasLinkerWeakLinkage())
    188 PrefixTy = Mangler::LinkerWeak;
    184189
    185190 // If this global has a name, handle it simply.
    186191 if (GV->hasName()) {
    128128 case GlobalValue::WeakAnyLinkage:
    129129 case GlobalValue::WeakODRLinkage:
    130130 case GlobalValue::ExternalLinkage:
    131 case GlobalValue::LinkerWeakLinkage:
    131132 emitArrayBound(GVSym, GV);
    132133 OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
    133134
    534534 case GlobalValue::WeakAnyLinkage:
    535535 case GlobalValue::WeakODRLinkage:
    536536 case GlobalValue::ExternalWeakLinkage:
    537 case GlobalValue::LinkerWeakLinkage:
    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::LinkerWeakLinkage: Out << "linker_weak "; break;
    14211422 case GlobalValue::InternalLinkage: Out << "internal "; break;
    14221423 case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break;
    14231424 case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break;
    10571057 return LLVMPrivateLinkage;
    10581058 case GlobalValue::LinkerPrivateLinkage:
    10591059 return LLVMLinkerPrivateLinkage;
    1060 case GlobalValue::LinkerWeakLinkage:
    1061 return LLVMLinkerWeakLinkage;
    10601062 case GlobalValue::DLLImportLinkage:
    10611063 return LLVMDLLImportLinkage;
    10621064 case GlobalValue::DLLExportLinkage:
    11071109 case LLVMLinkerPrivateLinkage:
    11081110 GV->setLinkage(GlobalValue::LinkerPrivateLinkage);
    11091111 break;
    1112 case LLVMLinkerWeakLinkage:
    1113 GV->setLinkage(GlobalValue::LinkerWeakLinkage);
    1114 break;
    11101115 case LLVMDLLImportLinkage:
    11111116 GV->setLinkage(GlobalValue::DLLImportLinkage);
    11121117 break;
    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.hasLinkerWeakLinkage() || GV.hasAvailableExternallyLinkage())
    92 return;
    9293
    9394 const std::string SymbolAddrStr = " "; // Not used yet...
    9495 char TypeChar = TypeCharForSymbol(GV);