[llvm] r211913 - MC: Fix associative sections on COFF

David Majnemer david.majnemer at gmail.com
Fri Jun 27 10:19:44 PDT 2014


Author: majnemer
Date: Fri Jun 27 12:19:44 2014
New Revision: 211913

URL: http://llvm.org/viewvc/llvm-project?rev=211913&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp
    llvm/trunk/test/MC/COFF/section-comdat.s

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=211913&r1=211912&r2=211913&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Fri Jun 27 12:19:44 2014
@@ -22,6 +22,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include <map>
+#include <tuple>
 #include <vector> // FIXME: Shouldn't be needed.
 
 namespace llvm {
@@ -160,10 +161,11 @@ namespace llvm {
     unsigned DwarfCompileUnitID;
 
     typedef std::pair<std::string, std::string> SectionGroupPair;
+    typedef std::tuple<std::string, std::string, int> SectionGroupTriple;
 
     StringMap<const MCSectionMachO*> MachOUniquingMap;
     std::map<SectionGroupPair, const MCSectionELF *> ELFUniquingMap;
-    std::map<SectionGroupPair, const MCSectionCOFF *> COFFUniquingMap;
+    std::map<SectionGroupTriple, const MCSectionCOFF *> COFFUniquingMap;
 
     /// Do automatic reset in destructor
     bool AutoReset;

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=211913&r1=211912&r2=211913&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Fri Jun 27 12:19:44 2014
@@ -284,8 +284,8 @@ const MCSectionCOFF *MCContext::getCOFFS
                                                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::getCOFFS
   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 Sect
 }
 
 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;

Modified: llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp?rev=211913&r1=211912&r2=211913&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp Fri Jun 27 12:19:44 2014
@@ -292,8 +292,7 @@ bool COFFAsmParser::ParseDirectiveSymbol
 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::ParseDirectiveSectio
       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;

Modified: llvm/trunk/test/MC/COFF/section-comdat.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/section-comdat.s?rev=211913&r1=211912&r2=211913&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/section-comdat.s (original)
+++ llvm/trunk/test/MC/COFF/section-comdat.s Fri Jun 27 12:19:44 2014
@@ -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: ]





More information about the llvm-commits mailing list