Skip to content

Commit

Permalink
Revert "[COFF] Make the autogenerated .weak.<name>.default symbols st…
Browse files Browse the repository at this point in the history
…atic"

This reverts commit 7ca86ee.

Apparently this change causes MS link.exe to error out with
"LNK1235: corrupt or invalid COFF symbol table".
  • Loading branch information
mstorsjo authored and arichardson committed Jan 20, 2020
2 parents fe298e3 + bc5b721 commit 90b5566
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
22 changes: 9 additions & 13 deletions llvm/lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MCSymbolCOFF>(MCSymGeneric);
COFFSymbol *Sym = GetOrCreateCOFFSymbol(&MCSym);
const MCSymbol *Base = Layout.getBaseSymbol(MCSym);
COFFSection *Sec = nullptr;
Expand All @@ -366,7 +365,7 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric,
}

COFFSymbol *Local = nullptr;
if (MCSym.isWeakExternal()) {
if (cast<MCSymbolCOFF>(MCSym).isWeakExternal()) {
Sym->Data.StorageClass = COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL;

COFFSymbol *WeakDefault = getLinkedSymbol(MCSym);
Expand All @@ -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;
}

Expand All @@ -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<MCSymbolCOFF>(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) {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/COFF/weak-alias-local.s
Original file line number Diff line number Diff line change
Expand Up @@ -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: }
2 changes: 1 addition & 1 deletion llvm/test/MC/COFF/weak-val.s
Original file line number Diff line number Diff line change
Expand Up @@ -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: }
4 changes: 2 additions & 2 deletions llvm/test/MC/COFF/weak.s
Original file line number Diff line number Diff line change
Expand Up @@ -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: }

Expand All @@ -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: }

0 comments on commit 90b5566

Please sign in to comment.