coff: fix the section of weak symbols.

llvm-svn: 270889
This commit is contained in:
Rafael Espindola 2016-05-26 18:48:23 +00:00
parent 9d7ba27b1f
commit 6f9336d4d1
2 changed files with 17 additions and 14 deletions

View File

@ -359,6 +359,13 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol,
MCAssembler &Assembler,
const MCAsmLayout &Layout) {
COFFSymbol *coff_symbol = GetOrCreateCOFFSymbol(&Symbol);
const MCSymbol *Base = Layout.getBaseSymbol(Symbol);
COFFSection *Sec = nullptr;
if (Base && Base->getFragment()) {
Sec = SectionMap[Base->getFragment()->getParent()];
if (coff_symbol->Section && coff_symbol->Section != Sec)
report_fatal_error("conflicting sections for symbol");
}
if (cast<MCSymbolCOFF>(Symbol).isWeakExternal()) {
coff_symbol->Data.StorageClass = COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL;
@ -374,7 +381,12 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol,
} else {
std::string WeakName = (".weak." + Symbol.getName() + ".default").str();
COFFSymbol *WeakDefault = createSymbol(WeakName);
WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
if (!Sec)
WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
else
WeakDefault->Section = Sec;
WeakDefault->Data.StorageClass = COFF::IMAGE_SYM_CLASS_EXTERNAL;
WeakDefault->Data.Type = 0;
WeakDefault->Data.Value = getSymbolValue(Symbol, Layout);
@ -391,7 +403,6 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol,
coff_symbol->MC = &Symbol;
} else {
const MCSymbol *Base = Layout.getBaseSymbol(Symbol);
coff_symbol->Data.Value = getSymbolValue(Symbol, Layout);
const MCSymbolCOFF &SymbolCOFF = cast<MCSymbolCOFF>(Symbol);
@ -408,18 +419,10 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol,
: COFF::IMAGE_SYM_CLASS_STATIC;
}
if (!Base) {
if (!Base)
coff_symbol->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
} else {
if (Base->getFragment()) {
COFFSection *Sec = SectionMap[Base->getFragment()->getParent()];
if (coff_symbol->Section && coff_symbol->Section != Sec)
report_fatal_error("conflicting sections for symbol");
coff_symbol->Section = Sec;
}
}
else
coff_symbol->Section = Sec;
coff_symbol->MC = &Symbol;
}

View File

@ -25,7 +25,7 @@ b:
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: .weak.b.default
// CHECK-NEXT: Value: 4
// CHECK-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
// CHECK-NEXT: Section: .data (2)
// CHECK-NEXT: BaseType: Null (0x0)
// CHECK-NEXT: ComplexType: Null (0x0)
// CHECK-NEXT: StorageClass: External (0x2)