Close unique sections when switching away from them.
[oota-llvm.git] / lib / MC / MCStreamer.cpp
index d5277ffbd10c4769bc05c60e14cb1cb34eceab8b..3db2345540424791eeb09f95f83b8da1aed92194 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/MC/MCWin64EH.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -668,7 +669,29 @@ 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);
+    MCSymbol *Sym = Section->getBeginSymbol();
+    if (Sym && !Sym->isInSection())
+      EmitLabel(Sym);
   }
 }
+
+MCSymbol *MCStreamer::endSection(const MCSection *Section) {
+  // TODO: keep track of the last subsection so that this symbol appears in the
+  // correct place.
+  MCSymbol *Sym = Section->getEndSymbol(Context);
+  if (Sym->isInSection())
+    return Sym;
+
+  SwitchSection(Section);
+  EmitLabel(Sym);
+  return Sym;
+}