Defer call to InitSections until after MCContext has been initialized. If
authorLang Hames <lhames@gmail.com>
Mon, 10 Dec 2012 22:49:11 +0000 (22:49 +0000)
committerLang Hames <lhames@gmail.com>
Mon, 10 Dec 2012 22:49:11 +0000 (22:49 +0000)
InitSections is called before the MCContext is initialized it could cause
duplicate temporary symbols to be emitted later (after context initialization
resets the temporary label counter).

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

include/llvm/MC/MCStreamer.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/LLVMTargetMachine.cpp
lib/MC/MCStreamer.cpp

index 3b368c37d140112ba53ae76c9c7e55a59996901c..c411030e2bcdf72f9afd328fa2ccf4c1feda7900 100644 (file)
@@ -70,6 +70,8 @@ namespace llvm {
     SmallVector<std::pair<const MCSection *,
                 const MCSection *>, 4> SectionStack;
 
+    bool AutoInitSections;
+
   protected:
     MCStreamer(MCContext &Ctx);
 
@@ -214,6 +216,17 @@ namespace llvm {
         SectionStack.back().first = Section;
     }
 
+    /// Initialize the streamer.
+    void InitStreamer() {
+      if (AutoInitSections)
+        InitSections();
+    }
+
+    /// Tell this MCStreamer to call InitSections upon initialization.
+    void setAutoInitSections(bool AutoInitSections) {
+      this->AutoInitSections = AutoInitSections;
+    }
+
     /// InitSections - Create the default sections and set the initial one.
     virtual void InitSections() = 0;
 
index 39a5a9d42d2384adc1dc9f6230d7db1b1444b041..68ed280c551b82d5d83082e1fcede68c8f60da91 100644 (file)
@@ -149,6 +149,8 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
 }
 
 bool AsmPrinter::doInitialization(Module &M) {
+  OutStreamer.InitStreamer();
+
   MMI = getAnalysisIfAvailable<MachineModuleInfo>();
   MMI->AnalyzeModule(M);
 
index f0d536982bc2426fd73b3c7e0ab4e8c8ad7bc5f1..1065614f4b2e1e082c1b2a9a5fe6024ed4683c0b 100644 (file)
@@ -202,7 +202,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
                                                          *Context, *MAB, Out,
                                                          MCE, hasMCRelaxAll(),
                                                          hasMCNoExecStack()));
-    AsmStreamer.get()->InitSections();
+    AsmStreamer.get()->setAutoInitSections(true);
     break;
   }
   case CGFT_Null:
index 77e3d4cea35d336ac3c21a8941a3f12bc4a80bdd..96d6d691d26b88e6db39fccbaa88983fab41da08 100644 (file)
@@ -23,7 +23,8 @@ using namespace llvm;
 
 MCStreamer::MCStreamer(MCContext &Ctx)
   : Context(Ctx), EmitEHFrame(true), EmitDebugFrame(false),
-    CurrentW64UnwindInfo(0), LastSymbol(0) {
+    CurrentW64UnwindInfo(0), LastSymbol(0),
+    AutoInitSections(false) {
   const MCSection *section = NULL;
   SectionStack.push_back(std::make_pair(section, section));
 }