From d7d427732e3e7f571bc915c15974e184733bbd01 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 27 Jun 2014 17:19:44 +0000 Subject: [PATCH] MC: Fix associative sections on COFF COFF sections in MC were represented by a tuple of section-name and COMDAT-name. This is not sufficient to represent a .text section associated with another .text section; we need a way to distinguish between the key section and the one marked associative. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211913 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCContext.h | 4 +++- lib/MC/MCContext.cpp | 10 +++++----- lib/MC/MCParser/COFFAsmParser.cpp | 6 +++--- test/MC/COFF/section-comdat.s | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index ce3a99bb3fe..eb0340f7421 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -22,6 +22,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/raw_ostream.h" #include +#include #include // FIXME: Shouldn't be needed. namespace llvm { @@ -160,10 +161,11 @@ namespace llvm { unsigned DwarfCompileUnitID; typedef std::pair SectionGroupPair; + typedef std::tuple SectionGroupTriple; StringMap MachOUniquingMap; std::map ELFUniquingMap; - std::map COFFUniquingMap; + std::map COFFUniquingMap; /// Do automatic reset in destructor bool AutoReset; diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index bd2c4e960ac..cfdab0cba8b 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -284,8 +284,8 @@ const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, int Selection) { // Do the lookup, if we have a hit, return it. - SectionGroupPair P(Section, COMDATSymName); - auto IterBool = COFFUniquingMap.insert(std::make_pair(P, nullptr)); + SectionGroupTriple T(Section, COMDATSymName, Selection); + auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr)); auto Iter = IterBool.first; if (!IterBool.second) return Iter->second; @@ -294,7 +294,7 @@ const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, if (!COMDATSymName.empty()) COMDATSymbol = GetOrCreateSymbol(COMDATSymName); - StringRef CachedName = Iter->first.first; + StringRef CachedName = std::get<0>(Iter->first); MCSectionCOFF *Result = new (*this) MCSectionCOFF(CachedName, Characteristics, COMDATSymbol, Selection, Kind); @@ -309,8 +309,8 @@ MCContext::getCOFFSection(StringRef Section, unsigned Characteristics, } const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) { - SectionGroupPair P(Section, ""); - auto Iter = COFFUniquingMap.find(P); + SectionGroupTriple T(Section, "", 0); + auto Iter = COFFUniquingMap.find(T); if (Iter == COFFUniquingMap.end()) return nullptr; return Iter->second; diff --git a/lib/MC/MCParser/COFFAsmParser.cpp b/lib/MC/MCParser/COFFAsmParser.cpp index 0d914efe874..146889599e0 100644 --- a/lib/MC/MCParser/COFFAsmParser.cpp +++ b/lib/MC/MCParser/COFFAsmParser.cpp @@ -292,8 +292,7 @@ bool COFFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) { bool COFFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Characteristics, SectionKind Kind) { - return ParseSectionSwitch(Section, Characteristics, Kind, "", - COFF::IMAGE_COMDAT_SELECT_ANY); + return ParseSectionSwitch(Section, Characteristics, Kind, "", (COFF::COMDATType)0); } bool COFFAsmParser::ParseSectionSwitch(StringRef Section, @@ -357,9 +356,10 @@ bool COFFAsmParser::ParseDirectiveSection(StringRef, SMLoc) { return true; } - COFF::COMDATType Type = COFF::IMAGE_COMDAT_SELECT_ANY; + COFF::COMDATType Type = (COFF::COMDATType)0; StringRef COMDATSymName; if (getLexer().is(AsmToken::Comma)) { + Type = COFF::IMAGE_COMDAT_SELECT_ANY;; Lex(); Flags |= COFF::IMAGE_SCN_LNK_COMDAT; diff --git a/test/MC/COFF/section-comdat.s b/test/MC/COFF/section-comdat.s index 8a7de1a1d91..e7052d8f5ae 100644 --- a/test/MC/COFF/section-comdat.s +++ b/test/MC/COFF/section-comdat.s @@ -39,6 +39,11 @@ Symbol6: Symbol7: .long 1 +.section assocSec, "dr", associative, "assocSym" +.globl Symbol8 +Symbol8: +.long 1 + // CHECK: Sections [ // CHECK: Section { // CHECK: Number: 4 @@ -185,7 +190,19 @@ Symbol7: // CHECK: Section: SecName (11) // CHECK: } // CHECK: Symbol { +// CHECK: Name: assocSec +// CHECK: Section: assocSec (12) +// CHECK: AuxSectionDef { +// CHECK: Selection: Associative (0x5) +// CHECK: AssocSection: assocSec (4) +// CHECK: } +// CHECK: } +// CHECK: Symbol { // CHECK: Name: Symbol5 // CHECK: Section: SecName (9) // CHECK: } +// CHECK: Symbol { +// CHECK: Name: Symbol8 +// CHECK: Section: assocSec (12) +// CHECK: } // CHECK: ] -- 2.34.1