[llvm] r233380 - Close unique sections when switching away from them.

Rafael Espindola rafael.espindola at gmail.com
Fri Mar 27 08:01:41 PDT 2015


Author: rafael
Date: Fri Mar 27 10:01:40 2015
New Revision: 233380

URL: http://llvm.org/viewvc/llvm-project?rev=233380&view=rev
Log:
Close unique sections when switching away from them.

It is not possible to switch back to unique secitons, so close them
automatically when switching away.

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

Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=233380&r1=233379&r2=233380&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Fri Mar 27 10:01:40 2015
@@ -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;

Modified: llvm/trunk/include/llvm/MC/MCSectionCOFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionCOFF.h?rev=233380&r1=233379&r2=233380&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionCOFF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionCOFF.h Fri Mar 27 10:01:40 2015
@@ -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 &&

Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=233380&r1=233379&r2=233380&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Fri Mar 27 10:01:40 2015
@@ -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; }

Modified: llvm/trunk/lib/MC/MCSectionMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSectionMachO.cpp?rev=233380&r1=233379&r2=233380&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSectionMachO.cpp (original)
+++ llvm/trunk/lib/MC/MCSectionMachO.cpp Fri Mar 27 10:01:40 2015
@@ -72,7 +72,7 @@ ENTRY(nullptr /*FIXME*/,     S_ATTR_LOC_
 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");

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=233380&r1=233379&r2=233380&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Fri Mar 27 10:01:40 2015
@@ -669,6 +669,12 @@ void MCStreamer::SwitchSection(const MCS
   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);

Modified: llvm/trunk/lib/Target/NVPTX/NVPTXSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXSection.h?rev=233380&r1=233379&r2=233380&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXSection.h (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXSection.h Fri Mar 27 10:01:40 2015
@@ -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

Modified: llvm/trunk/test/CodeGen/X86/global-sections-comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/global-sections-comdat.ll?rev=233380&r1=233379&r2=233380&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/global-sections-comdat.ll (original)
+++ llvm/trunk/test/CodeGen/X86/global-sections-comdat.ll Fri Mar 27 10:01:40 2015
@@ -36,6 +36,7 @@ bb5:
 ; LINUX-SECTIONS-SHORT: .section        .text,"axG", at 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", at progbits,F1,comdat
 
 $G16 = comdat any





More information about the llvm-commits mailing list