[llvm] r270889 - coff: fix the section of weak symbols.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu May 26 11:48:23 PDT 2016
Author: rafael
Date: Thu May 26 13:48:23 2016
New Revision: 270889
URL: http://llvm.org/viewvc/llvm-project?rev=270889&view=rev
Log:
coff: fix the section of weak symbols.
Modified:
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/test/MC/COFF/weak-val.s
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=270889&r1=270888&r2=270889&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Thu May 26 13:48:23 2016
@@ -359,6 +359,13 @@ void WinCOFFObjectWriter::DefineSymbol(c
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(c
} 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(c
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(c
: 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;
}
Modified: llvm/trunk/test/MC/COFF/weak-val.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/weak-val.s?rev=270889&r1=270888&r2=270889&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/weak-val.s (original)
+++ llvm/trunk/test/MC/COFF/weak-val.s Thu May 26 13:48:23 2016
@@ -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)
More information about the llvm-commits
mailing list