Correctly set the comdat symbol on COFF.

We extended the .section syntax to allow multiple sections with the
same name but different comdats, but currently we don't make sure that
the output section has that comdat symbol.

That happens to work with the code llc produces currently because it looks like

.section secName, "dr", one_only, "COMDATSym"
.globl COMDATSym
COMDATSym:
....

but that is not very friendly to anyone coding in assembly or even to
llc once we get comdat support in the IR.

This patch changes the coff object writer to make sure the comdat symbol is
output just after the section symbol, as required by the coff spec.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210298 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-06-05 23:09:25 +00:00
parent 5f81752533
commit d605148d07
4 changed files with 71 additions and 26 deletions

View File

@ -76,6 +76,7 @@ class MCSymbol;
return SectionName.str() + "_end";
}
unsigned getCharacteristics() const { return Characteristics; }
const MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
int getSelection() const { return Selection; }
const MCSectionCOFF *getAssocSection() const { return Assoc; }

View File

@ -347,6 +347,11 @@ void WinCOFFObjectWriter::DefineSection(MCSectionData const &SectionData) {
COFFSection *coff_section = createSection(Sec.getSectionName());
COFFSymbol *coff_symbol = createSymbol(Sec.getSectionName());
if (const MCSymbol *S = Sec.getCOMDATSymbol()) {
COFFSymbol *COMDATSymbol = GetOrCreateCOFFSymbol(S);
assert(!COMDATSymbol->Section);
COMDATSymbol->Section = coff_section;
}
coff_section->Symbol = coff_symbol;
coff_symbol->Section = coff_section;
@ -458,9 +463,15 @@ void WinCOFFObjectWriter::DefineSymbol(MCSymbolData const &SymbolData,
coff_symbol->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
} else {
const MCSymbolData &BaseData = Assembler.getSymbolData(*Base);
if (BaseData.Fragment)
coff_symbol->Section =
if (BaseData.Fragment) {
COFFSection *Sec =
SectionMap[&BaseData.Fragment->getParent()->getSection()];
if (coff_symbol->Section && coff_symbol->Section != Sec)
report_fatal_error("conflicting sections for symbol");
coff_symbol->Section = Sec;
}
}
coff_symbol->MCData = &ResSymData;

View File

@ -0,0 +1,13 @@
// RUN: not llvm-mc -triple i386-pc-win32 -filetype=obj < %s 2>&1 | FileCheck %s
// CHECK: conflicting sections for symbol
.section .xyz
.global bar
bar:
.long 42
.section .abcd,"xr",discard,bar
.global foo
foo:
.long 42

View File

@ -40,6 +40,11 @@ Symbol6:
Symbol7:
.long 1
.section SecName, "dr", newest, "Symbol8"
.globl AnotherSymbol
AnotherSymbol:
.long 1
// CHECK: Sections [
// CHECK: Section {
// CHECK: Number: 1
@ -114,6 +119,10 @@ Symbol7:
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol1
// CHECK: Section: secName (2)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: secName
// CHECK: Section: secName (3)
// CHECK: AuxSectionDef {
@ -121,6 +130,10 @@ Symbol7:
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol2
// CHECK: Section: secName (3)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
// CHECK: Section: SecName (4)
// CHECK: AuxSectionDef {
@ -128,6 +141,10 @@ Symbol7:
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol3
// CHECK: Section: SecName (4)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
// CHECK: Section: SecName (5)
// CHECK: AuxSymbolCount: 1
@ -136,6 +153,10 @@ Symbol7:
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol4
// CHECK: Section: SecName (5)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
// CHECK: Section: SecName (6)
// CHECK: AuxSectionDef {
@ -144,6 +165,10 @@ Symbol7:
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol5
// CHECK: Section: SecName (6)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
// CHECK: Section: SecName (7)
// CHECK: AuxSectionDef {
@ -151,6 +176,10 @@ Symbol7:
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol6
// CHECK: Section: SecName (7)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
// CHECK: Section: SecName (8)
// CHECK: AuxSectionDef {
@ -158,31 +187,22 @@ Symbol7:
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol1
// CHECK: Section: secName (2)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol2
// CHECK: Section: secName (3)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol3
// CHECK: Section: SecName (4)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol4
// CHECK: Section: SecName (5)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol5
// CHECK: Section: SecName (6)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol6
// CHECK: Section: SecName (7)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol7
// CHECK: Section: SecName (8)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
// CHECK: Section: SecName (9)
// CHECK: AuxSectionDef {
// CHECK: Selection: Newest (0x7)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol8
// CHECK: Section: SecName (9)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: AnotherSymbol
// CHECK: Section: SecName (9)
// CHECK: }
// CHECK: ]