Close unique sections when switching away from them.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 27 Mar 2015 15:01:40 +0000 (15:01 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 27 Mar 2015 15:01:40 +0000 (15:01 +0000)
It is not possible to switch back to unique secitons, so close them
automatically when switching away.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233380 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCSection.h
include/llvm/MC/MCSectionCOFF.h
include/llvm/MC/MCSectionELF.h
lib/MC/MCSectionMachO.cpp
lib/MC/MCStreamer.cpp
lib/Target/NVPTX/NVPTXSection.h
test/CodeGen/X86/global-sections-comdat.ll

index ab8968ef2baf0a4e6918b6d2a25f253fb38bccb0..fc0fc7bc8ffa2f5cd8235d7e38cef6f654c7a4e1 100644 (file)
@@ -39,10 +39,11 @@ private:
   mutable MCSymbol *End;
 
 protected:
-  MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
-      : Begin(Begin), End(nullptr), Variant(V), Kind(K) {}
+  MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin, bool Unique)
+      : Begin(Begin), End(nullptr), Variant(V), Kind(K), Unique(Unique) {}
   SectionVariant Variant;
   SectionKind Kind;
+  bool Unique;
 
 public:
   virtual ~MCSection();
@@ -54,6 +55,7 @@ public:
   MCSymbol *getBeginSymbol() const { return Begin; }
   MCSymbol *getEndSymbol(MCContext &Ctx) const;
   bool hasEnded() const;
+  bool isUnique() const { return Unique; }
 
   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
                                     const MCExpr *Subsection) const = 0;
index b6ec1d852d4f6c3c47f71ff7915d208cbf9e3643..201c4fae294027bedc0cf1962dc18b17ae37e3a7 100644 (file)
@@ -47,7 +47,7 @@ class MCSymbol;
     MCSectionCOFF(StringRef Section, unsigned Characteristics,
                   MCSymbol *COMDATSymbol, int Selection, SectionKind K,
                   MCSymbol *Begin)
-        : MCSection(SV_COFF, K, Begin), SectionName(Section),
+        : MCSection(SV_COFF, K, Begin, /*Unique*/ false), SectionName(Section),
           Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
           Selection(Selection) {
       assert ((Characteristics & 0x00F00000) == 0 &&
index 434a5b6a892cf252133779275c7b5c32add941b1..2bbc81fd79b7c5143421c2a1f20c532375fce7d2 100644 (file)
@@ -39,8 +39,6 @@ class MCSectionELF : public MCSection {
   /// below.
   unsigned Flags;
 
-  bool Unique;
-
   /// EntrySize - The size of each entry in this section. This size only
   /// makes sense for sections that contain fixed-sized entries. If a
   /// section does not contain fixed-sized entries 'EntrySize' will be 0.
@@ -53,8 +51,8 @@ private:
   MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
                unsigned entrySize, const MCSymbol *group, bool Unique,
                MCSymbol *Begin)
-      : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
-        Flags(flags), Unique(Unique), EntrySize(entrySize), Group(group) {}
+      : MCSection(SV_ELF, K, Begin, Unique), SectionName(Section), Type(type),
+        Flags(flags), EntrySize(entrySize), Group(group) {}
   ~MCSectionELF();
 
   void setSectionName(StringRef Name) { SectionName = Name; }
index c9f15914e4b17d60be7108366510d7eb0cee4562..606d074752830898fb215b130005c3457578d021 100644 (file)
@@ -72,7 +72,7 @@ ENTRY(nullptr /*FIXME*/,     S_ATTR_LOC_RELOC)
 MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
                                unsigned TAA, unsigned reserved2, SectionKind K,
                                MCSymbol *Begin)
-    : MCSection(SV_MachO, K, Begin), TypeAndAttributes(TAA),
+    : MCSection(SV_MachO, K, Begin, /*Unique*/ false), TypeAndAttributes(TAA),
       Reserved2(reserved2) {
   assert(Segment.size() <= 16 && Section.size() <= 16 &&
          "Segment or section string too long");
index 27d0355bb1175882fa552e186cbe964ad6deb465..3db2345540424791eeb09f95f83b8da1aed92194 100644 (file)
@@ -669,6 +669,12 @@ void MCStreamer::SwitchSection(const MCSection *Section,
   MCSectionSubPair curSection = SectionStack.back().first;
   SectionStack.back().second = curSection;
   if (MCSectionSubPair(Section, Subsection) != curSection) {
+    const MCSection *CurSec = curSection.first;
+    if (CurSec && CurSec->isUnique()) {
+      MCSymbol *Sym = curSection.first->getEndSymbol(Context);
+      if (!Sym->isInSection())
+        EmitLabel(Sym);
+    }
     SectionStack.back().first = MCSectionSubPair(Section, Subsection);
     assert(!Section->hasEnded() && "Section already ended");
     ChangeSection(Section, Subsection);
index 0d2627d62ebdd3dbfa373f73a0340a69827ee8d9..eb6194a23ee4e665420835dc1b1bc19d9bbed14a 100644 (file)
@@ -26,7 +26,8 @@ namespace llvm {
 class NVPTXSection : public MCSection {
   virtual void anchor();
 public:
-  NVPTXSection(SectionVariant V, SectionKind K) : MCSection(V, K, nullptr) {}
+  NVPTXSection(SectionVariant V, SectionKind K)
+      : MCSection(V, K, nullptr, /*Unique*/ false) {}
   virtual ~NVPTXSection() {}
 
   /// Override this as NVPTX has its own way of printing switching
index 730050dda5f30ebaf969bbfd60b23a56531f98e6..46188e7153bea6175f515e1225511fb58417144f 100644 (file)
@@ -36,6 +36,7 @@ bb5:
 ; LINUX-SECTIONS-SHORT: .section        .text,"axG",@progbits,F1,comdat
 ; LINUX-SECTIONS-SHORT: .size   F1,
 ; LINUX-SECTIONS-SHORT-NEXT: .cfi_endproc
+; LINUX-SECTIONS-SHORT-NEXT: .Lsec_end0:
 ; LINUX-SECTIONS-SHORT-NEXT: .section        .rodata,"aG",@progbits,F1,comdat
 
 $G16 = comdat any