summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2019-12-19 10:01:40 +0200
committerMartin Storsjö <martin@martin.st>2019-12-28 23:12:41 +0200
commit7ca86ee6494d4307333b300bae80e42df4a5140f (patch)
treeae78935f7be326834c4afc8a7e0a083c7d7c3fcb
parente7853a5ce21c466ae6261ec73933672610427a07 (diff)
downloadbcm5719-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
-rw-r--r--llvm/lib/MC/WinCOFFObjectWriter.cpp22
-rw-r--r--llvm/test/MC/COFF/weak-alias-local.s2
-rw-r--r--llvm/test/MC/COFF/weak-val.s2
-rw-r--r--llvm/test/MC/COFF/weak.s4
4 files changed, 17 insertions, 13 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;
}
diff --git a/llvm/test/MC/COFF/weak-alias-local.s b/llvm/test/MC/COFF/weak-alias-local.s
index 93a3652428e..455f921e78b 100644
--- a/llvm/test/MC/COFF/weak-alias-local.s
+++ b/llvm/test/MC/COFF/weak-alias-local.s
@@ -38,6 +38,6 @@ a=b
// CHECK-NEXT: Section: .data (2)
// CHECK-NEXT: BaseType: Null (0x0)
// CHECK-NEXT: ComplexType: Null (0x0)
-// CHECK-NEXT: StorageClass: External (0x2)
+// CHECK-NEXT: StorageClass: Static (0x3)
// CHECK-NEXT: AuxSymbolCount: 0
// CHECK-NEXT: }
diff --git a/llvm/test/MC/COFF/weak-val.s b/llvm/test/MC/COFF/weak-val.s
index cb5872b057e..7c7b9dbbb83 100644
--- a/llvm/test/MC/COFF/weak-val.s
+++ b/llvm/test/MC/COFF/weak-val.s
@@ -28,6 +28,6 @@ b:
// CHECK-NEXT: Section: .data (2)
// CHECK-NEXT: BaseType: Null (0x0)
// CHECK-NEXT: ComplexType: Null (0x0)
-// CHECK-NEXT: StorageClass: External (0x2)
+// CHECK-NEXT: StorageClass: Static (0x3)
// CHECK-NEXT: AuxSymbolCount: 0
// CHECK-NEXT: }
diff --git a/llvm/test/MC/COFF/weak.s b/llvm/test/MC/COFF/weak.s
index 5e216cef2cb..87bf26d4d88 100644
--- a/llvm/test/MC/COFF/weak.s
+++ b/llvm/test/MC/COFF/weak.s
@@ -64,7 +64,7 @@ LBB0_2: # %return
// CHECK-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
// CHECK-NEXT: BaseType: Null
// CHECK-NEXT: ComplexType: Null
-// CHECK-NEXT: StorageClass: External
+// CHECK-NEXT: StorageClass: Static
// CHECK-NEXT: AuxSymbolCount: 0
// CHECK-NEXT: }
@@ -88,6 +88,6 @@ LBB0_2: # %return
// CHECK-NEXT: Section: .text
// CHECK-NEXT: BaseType: Null
// CHECK-NEXT: ComplexType: Null
-// CHECK-NEXT: StorageClass: External
+// CHECK-NEXT: StorageClass: Static
// CHECK-NEXT: AuxSymbolCount: 0
// CHECK-NEXT: }
OpenPOWER on IntegriCloud