diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index d314533a5744f1..749ed8badfaa11 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -352,10 +352,9 @@ 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 &MCSymGeneric, +void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym, MCAssembler &Assembler, const MCAsmLayout &Layout) { - const auto &MCSym = cast(MCSymGeneric); COFFSymbol *Sym = GetOrCreateCOFFSymbol(&MCSym); const MCSymbol *Base = Layout.getBaseSymbol(MCSym); COFFSection *Sec = nullptr; @@ -366,7 +365,7 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric, } COFFSymbol *Local = nullptr; - if (MCSym.isWeakExternal()) { + if (cast(MCSym).isWeakExternal()) { Sym->Data.StorageClass = COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL; COFFSymbol *WeakDefault = getLinkedSymbol(MCSym); @@ -377,9 +376,6 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric, 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; } @@ -398,8 +394,14 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric, else Sym->Section = Sec; Local = Sym; + } - Local->Data.StorageClass = MCSym.getClass(); + if (Local) { + Local->Data.Value = getSymbolValue(MCSym, Layout); + + const MCSymbolCOFF &SymbolCOFF = cast(MCSym); + Local->Data.Type = SymbolCOFF.getType(); + Local->Data.StorageClass = SymbolCOFF.getClass(); // If no storage class was specified in the streamer, define it here. if (Local->Data.StorageClass == COFF::IMAGE_SYM_CLASS_NULL) { @@ -411,12 +413,6 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric, } } - 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 455f921e78bc60..93a3652428ee39 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: Static (0x3) +// CHECK-NEXT: StorageClass: External (0x2) // 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 7c7b9dbbb83fd8..cb5872b057eb0f 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: Static (0x3) +// CHECK-NEXT: StorageClass: External (0x2) // CHECK-NEXT: AuxSymbolCount: 0 // CHECK-NEXT: } diff --git a/llvm/test/MC/COFF/weak.s b/llvm/test/MC/COFF/weak.s index 87bf26d4d88673..5e216cef2cbd0f 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: Static +// CHECK-NEXT: StorageClass: External // 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: Static +// CHECK-NEXT: StorageClass: External // CHECK-NEXT: AuxSymbolCount: 0 // CHECK-NEXT: }