DebugInfo: Move unit begin/end labels into the unit
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 6 Dec 2013 22:33:05 +0000 (22:33 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 6 Dec 2013 22:33:05 +0000 (22:33 +0000)
This removes another case of spooky action at a distance (building the
same label names in multiple places creating an implicit dependency
between those places) and helps pave the way for type units.

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

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfUnit.h

index d92258ce1d88f5b8f4cac9d0a6ea574e44f018eb..14d784e8a26b089952eb31ef81b3e7230ce79235 100644 (file)
@@ -2137,8 +2137,7 @@ void DwarfFile::emitUnits(DwarfDebug *DD, const MCSection *ASection,
     Asm->OutStreamer.SwitchSection(USection);
 
     // Emit the compile units header.
-    Asm->OutStreamer.EmitLabel(
-        Asm->GetTempSymbol(USection->getLabelBeginName(), TheU->getUniqueID()));
+    Asm->OutStreamer.EmitLabel(TheU->getLabelBegin());
 
     // Emit size of content not including length itself
     Asm->OutStreamer.AddComment("Length of Unit");
@@ -2147,8 +2146,7 @@ void DwarfFile::emitUnits(DwarfDebug *DD, const MCSection *ASection,
     TheU->emitHeader(ASection, ASectionSym);
 
     DD->emitDIE(Die);
-    Asm->OutStreamer.EmitLabel(
-        Asm->GetTempSymbol(USection->getLabelEndName(), TheU->getUniqueID()));
+    Asm->OutStreamer.EmitLabel(TheU->getLabelEnd());
   }
 }
 
@@ -2414,7 +2412,6 @@ static dwarf::PubIndexEntryDescriptor computeIndexValue(Unit *CU,
 /// emitDebugPubNames - Emit visible names into a debug pubnames section.
 ///
 void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
-  const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection();
   const MCSection *PSec =
       GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
                : Asm->getObjFileLowering().getDwarfPubNamesSection();
@@ -2444,13 +2441,10 @@ void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
     Asm->EmitInt16(dwarf::DW_PUBNAMES_VERSION);
 
     Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
-    Asm->EmitSectionOffset(Asm->GetTempSymbol(ISec->getLabelBeginName(), ID),
-                           TheU->getSectionSym());
+    Asm->EmitSectionOffset(TheU->getLabelBegin(), TheU->getSectionSym());
 
     Asm->OutStreamer.AddComment("Compilation Unit Length");
-    Asm->EmitLabelDifference(Asm->GetTempSymbol(ISec->getLabelEndName(), ID),
-                             Asm->GetTempSymbol(ISec->getLabelBeginName(), ID),
-                             4);
+    Asm->EmitLabelDifference(TheU->getLabelEnd(), TheU->getLabelBegin(), 4);
 
     // Emit the pubnames for this compilation unit.
     const StringMap<const DIE *> &Globals = getUnits()[ID]->getGlobalNames();
@@ -2482,7 +2476,6 @@ void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
 }
 
 void DwarfDebug::emitDebugPubTypes(bool GnuStyle) {
-  const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection();
   const MCSection *PSec =
       GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
                : Asm->getObjFileLowering().getDwarfPubTypesSection();
@@ -2512,14 +2505,10 @@ void DwarfDebug::emitDebugPubTypes(bool GnuStyle) {
     Asm->EmitInt16(dwarf::DW_PUBTYPES_VERSION);
 
     Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
-    Asm->EmitSectionOffset(
-        Asm->GetTempSymbol(ISec->getLabelBeginName(), TheU->getUniqueID()),
-        TheU->getSectionSym());
+    Asm->EmitSectionOffset(TheU->getLabelBegin(), TheU->getSectionSym());
 
     Asm->OutStreamer.AddComment("Compilation Unit Length");
-    Asm->EmitLabelDifference(
-        Asm->GetTempSymbol(ISec->getLabelEndName(), TheU->getUniqueID()),
-        Asm->GetTempSymbol(ISec->getLabelBeginName(), TheU->getUniqueID()), 4);
+    Asm->EmitLabelDifference(TheU->getLabelEnd(), TheU->getLabelBegin(), 4);
 
     // Emit the pubtypes.
     const StringMap<const DIE *> &Globals = getUnits()[ID]->getGlobalTypes();
@@ -2825,7 +2814,6 @@ void DwarfDebug::emitDebugARanges() {
     }
   }
 
-  const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection();
   unsigned PtrSize = Asm->getDataLayout().getPointerSize();
 
   // Build a list of CUs used.
@@ -2866,9 +2854,7 @@ void DwarfDebug::emitDebugARanges() {
     Asm->OutStreamer.AddComment("DWARF Arange version number");
     Asm->EmitInt16(dwarf::DW_ARANGES_VERSION);
     Asm->OutStreamer.AddComment("Offset Into Debug Info Section");
-    Asm->EmitSectionOffset(
-        Asm->GetTempSymbol(ISec->getLabelBeginName(), CU->getUniqueID()),
-        CU->getSectionSym());
+    Asm->EmitSectionOffset(CU->getLabelBegin(), CU->getSectionSym());
     Asm->OutStreamer.AddComment("Address Size (in bytes)");
     Asm->EmitInt8(PtrSize);
     Asm->OutStreamer.AddComment("Segment Size (in bytes)");
index 852b4c3cc5a9c9ffae000571e05bfc65948e1559..0ffaacf02a1ec478321a4b3b1827f430c394ca4a 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/DebugInfo.h"
 #include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCSection.h"
 
 namespace llvm {
 
@@ -133,6 +134,12 @@ protected:
   /// A label at the start of the non-dwo section related to this unit.
   MCSymbol *SectionSym;
 
+  /// The start of the unit within its section.
+  MCSymbol *LabelBegin;
+
+  /// The end of the unit within its section.
+  MCSymbol *LabelEnd;
+
   Unit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A, DwarfDebug *DW,
        DwarfFile *DWU);
 
@@ -146,17 +153,31 @@ public:
     assert(!this->Section);
     this->Section = Section;
     this->SectionSym = SectionSym;
+    this->LabelBegin =
+        Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID());
+    this->LabelEnd =
+        Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID());
   }
   const MCSection *getSection() const {
     assert(Section);
     return Section;
   }
 
-  MCSymbol *getSectionSym() {
+  MCSymbol *getSectionSym() const {
     assert(Section);
     return SectionSym;
   }
 
+  MCSymbol *getLabelBegin() const {
+    assert(Section);
+    return LabelBegin;
+  }
+
+  MCSymbol *getLabelEnd() const {
+    assert(Section);
+    return LabelEnd;
+  }
+
   // Accessors.
   unsigned getUniqueID() const { return UniqueID; }
   virtual uint16_t getLanguage() const = 0;