Skip to content

Commit bc5b721

Browse files
committed
Revert "[COFF] Make the autogenerated .weak.<name>.default symbols static"
This reverts commit 7ca86ee. Apparently this change causes MS link.exe to error out with "LNK1235: corrupt or invalid COFF symbol table".
1 parent 36fb199 commit bc5b721

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

llvm/lib/MC/WinCOFFObjectWriter.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,9 @@ COFFSymbol *WinCOFFObjectWriter::getLinkedSymbol(const MCSymbol &Symbol) {
352352

353353
/// This function takes a symbol data object from the assembler
354354
/// and creates the associated COFF symbol staging object.
355-
void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric,
355+
void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSym,
356356
MCAssembler &Assembler,
357357
const MCAsmLayout &Layout) {
358-
const auto &MCSym = cast<MCSymbolCOFF>(MCSymGeneric);
359358
COFFSymbol *Sym = GetOrCreateCOFFSymbol(&MCSym);
360359
const MCSymbol *Base = Layout.getBaseSymbol(MCSym);
361360
COFFSection *Sec = nullptr;
@@ -366,7 +365,7 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric,
366365
}
367366

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

372371
COFFSymbol *WeakDefault = getLinkedSymbol(MCSym);
@@ -377,9 +376,6 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric,
377376
WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
378377
else
379378
WeakDefault->Section = Sec;
380-
// Make the default symbol static, in order to not conflict with
381-
// similar default symbols for the same weak in other objects.
382-
WeakDefault->Data.StorageClass = COFF::IMAGE_SYM_CLASS_STATIC;
383379
Local = WeakDefault;
384380
}
385381

@@ -398,8 +394,14 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric,
398394
else
399395
Sym->Section = Sec;
400396
Local = Sym;
397+
}
401398

402-
Local->Data.StorageClass = MCSym.getClass();
399+
if (Local) {
400+
Local->Data.Value = getSymbolValue(MCSym, Layout);
401+
402+
const MCSymbolCOFF &SymbolCOFF = cast<MCSymbolCOFF>(MCSym);
403+
Local->Data.Type = SymbolCOFF.getType();
404+
Local->Data.StorageClass = SymbolCOFF.getClass();
403405

404406
// If no storage class was specified in the streamer, define it here.
405407
if (Local->Data.StorageClass == COFF::IMAGE_SYM_CLASS_NULL) {
@@ -411,12 +413,6 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &MCSymGeneric,
411413
}
412414
}
413415

414-
if (Local) {
415-
Local->Data.Value = getSymbolValue(MCSym, Layout);
416-
417-
Local->Data.Type = MCSym.getType();
418-
}
419-
420416
Sym->MC = &MCSym;
421417
}
422418

llvm/test/MC/COFF/weak-alias-local.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ a=b
3838
// CHECK-NEXT: Section: .data (2)
3939
// CHECK-NEXT: BaseType: Null (0x0)
4040
// CHECK-NEXT: ComplexType: Null (0x0)
41-
// CHECK-NEXT: StorageClass: Static (0x3)
41+
// CHECK-NEXT: StorageClass: External (0x2)
4242
// CHECK-NEXT: AuxSymbolCount: 0
4343
// CHECK-NEXT: }

llvm/test/MC/COFF/weak-val.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ b:
2828
// CHECK-NEXT: Section: .data (2)
2929
// CHECK-NEXT: BaseType: Null (0x0)
3030
// CHECK-NEXT: ComplexType: Null (0x0)
31-
// CHECK-NEXT: StorageClass: Static (0x3)
31+
// CHECK-NEXT: StorageClass: External (0x2)
3232
// CHECK-NEXT: AuxSymbolCount: 0
3333
// CHECK-NEXT: }

llvm/test/MC/COFF/weak.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ LBB0_2: # %return
6464
// CHECK-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
6565
// CHECK-NEXT: BaseType: Null
6666
// CHECK-NEXT: ComplexType: Null
67-
// CHECK-NEXT: StorageClass: Static
67+
// CHECK-NEXT: StorageClass: External
6868
// CHECK-NEXT: AuxSymbolCount: 0
6969
// CHECK-NEXT: }
7070

@@ -88,6 +88,6 @@ LBB0_2: # %return
8888
// CHECK-NEXT: Section: .text
8989
// CHECK-NEXT: BaseType: Null
9090
// CHECK-NEXT: ComplexType: Null
91-
// CHECK-NEXT: StorageClass: Static
91+
// CHECK-NEXT: StorageClass: External
9292
// CHECK-NEXT: AuxSymbolCount: 0
9393
// CHECK-NEXT: }

0 commit comments

Comments
 (0)