diff options
author | Martin Storsjö <martin@martin.st> | 2019-12-19 10:01:40 +0200 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2019-12-28 23:12:41 +0200 |
commit | 7ca86ee6494d4307333b300bae80e42df4a5140f (patch) | |
tree | ae78935f7be326834c4afc8a7e0a083c7d7c3fcb /llvm/lib/MC/WinCOFFObjectWriter.cpp | |
parent | e7853a5ce21c466ae6261ec73933672610427a07 (diff) | |
download | bcm5719-llvm-7ca86ee6494d4307333b300bae80e42df4a5140f.tar.gz bcm5719-llvm-7ca86ee6494d4307333b300bae80e42df4a5140f.zip |
[COFF] Make the autogenerated .weak.<name>.default symbols static
If we have references to the same extern_weak in multiple objects,
all of them would generate external symbols with the same name. Make
them static to avoid duplicate definitions; nothing should need to
refer to this symbol outside of the current object.
GCC/binutils seems to handle the same by not using a fixed string
for the ".default" suffix, but instead using the name of some other
defined external symbol from the same object (which is supposed to
be unique among objects unless there's other duplicate definitions).
Differential Revision: https://reviews.llvm.org/D71711
Diffstat (limited to 'llvm/lib/MC/WinCOFFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/WinCOFFObjectWriter.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index 749ed8badfa..d314533a574 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -352,9 +352,10 @@ COFFSymbol *WinCOFFObjectWriter::getLinkedSymbol(const MCSymbol &Symbol) { /// This function takes a symbol data object from the assembler /// and creates the associated COFF symbol staging object. -void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym, +void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric, MCAssembler &Assembler, const MCAsmLayout &Layout) { + const auto &MCSym = cast<MCSymbolCOFF>(MCSymGeneric); COFFSymbol *Sym = GetOrCreateCOFFSymbol(&MCSym); const MCSymbol *Base = Layout.getBaseSymbol(MCSym); COFFSection *Sec = nullptr; @@ -365,7 +366,7 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym, } COFFSymbol *Local = nullptr; - if (cast<MCSymbolCOFF>(MCSym).isWeakExternal()) { + if (MCSym.isWeakExternal()) { Sym->Data.StorageClass = COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL; COFFSymbol *WeakDefault = getLinkedSymbol(MCSym); @@ -376,6 +377,9 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym, WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE; else WeakDefault->Section = Sec; + // Make the default symbol static, in order to not conflict with + // similar default symbols for the same weak in other objects. + WeakDefault->Data.StorageClass = COFF::IMAGE_SYM_CLASS_STATIC; Local = WeakDefault; } @@ -394,14 +398,8 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym, else Sym->Section = Sec; Local = Sym; - } - if (Local) { - Local->Data.Value = getSymbolValue(MCSym, Layout); - - const MCSymbolCOFF &SymbolCOFF = cast<MCSymbolCOFF>(MCSym); - Local->Data.Type = SymbolCOFF.getType(); - Local->Data.StorageClass = SymbolCOFF.getClass(); + Local->Data.StorageClass = MCSym.getClass(); // If no storage class was specified in the streamer, define it here. if (Local->Data.StorageClass == COFF::IMAGE_SYM_CLASS_NULL) { @@ -413,6 +411,12 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym, } } + if (Local) { + Local->Data.Value = getSymbolValue(MCSym, Layout); + + Local->Data.Type = MCSym.getType(); + } + Sym->MC = &MCSym; } |