Revert r198208 and reapply:
authorEric Christopher <echristo@gmail.com>
Mon, 30 Dec 2013 17:22:27 +0000 (17:22 +0000)
committerEric Christopher <echristo@gmail.com>
Mon, 30 Dec 2013 17:22:27 +0000 (17:22 +0000)
      r198196: Use a pointer to keep track of the skeleton unit for each normal unit and construct it up front.
      r198199: Reapply r198196 with a fix to zero initialize the skeleton pointer.
      r198202: Fix aranges and split dwarf by ensuring that the symbol and relocation back to the compile unit from the aranges section is to the skeleton unit and not the one in the dwo.

with a fix to use integer 0 for DW_AT_low_pc since the relocation to the text section symbol was causing issues with COFF. Accordingly remove addLocalLabelAddress and machinery since we're not currently using it.

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

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
lib/CodeGen/AsmPrinter/DwarfUnit.h
test/DebugInfo/X86/arange.ll
test/DebugInfo/X86/fission-cu.ll
test/DebugInfo/X86/stmt-list-multiple-compile-units.ll

index a30e8bbd954917619845410ad2cc0a5150bcb84e..acb25ccaaf173b339454a3f48c8c8623c4812f5e 100644 (file)
@@ -773,12 +773,6 @@ DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
                  DIUnit.getLanguage());
   NewCU->addString(Die, dwarf::DW_AT_name, FN);
 
-  // 2.17.1 requires that we use DW_AT_low_pc for a single entry point
-  // into an entity. We're using 0 (or a NULL label) for this. For
-  // split dwarf it's in the skeleton CU so omit it here.
-  if (!useSplitDwarf())
-    NewCU->addLabelAddress(Die, dwarf::DW_AT_low_pc, NULL);
-
   // Define start line table label for each Compile Unit.
   MCSymbol *LineTableStartSym =
       Asm->GetTempSymbol("line_table_start", NewCU->getUniqueID());
@@ -831,11 +825,11 @@ DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
   NewCU->initSection(
       useSplitDwarf() ? Asm->getObjFileLowering().getDwarfInfoDWOSection()
                       : Asm->getObjFileLowering().getDwarfInfoSection(),
-      // FIXME: This is subtle (using the info section even when
-      // this CU is in the dwo section) and necessary for the
-      // current arange code - ideally it should iterate
-      // skeleton units, not full units, if it's going to reference skeletons
-      DwarfInfoSectionSym);
+      useSplitDwarf() ? DwarfInfoDWOSectionSym : DwarfInfoSectionSym);
+
+  // If we're splitting the dwarf then construct the skeleton CU now.
+  if (useSplitDwarf())
+    NewCU->setSkeleton(constructSkeletonCU(NewCU));
 
   CUMap.insert(std::make_pair(DIUnit, NewCU));
   CUDieMap.insert(std::make_pair(Die, NewCU));
@@ -1082,7 +1076,9 @@ void DwarfDebug::finalizeModuleInfo() {
     // Add CU specific attributes if we need to add any.
     if (TheU->getUnitDie()->getTag() == dwarf::DW_TAG_compile_unit) {
       // If we're splitting the dwarf out now that we've got the entire
-      // CU then construct a skeleton CU based upon it.
+      // CU then add the dwo id to it.
+      DwarfCompileUnit *SkCU =
+          static_cast<DwarfCompileUnit *>(TheU->getSkeleton());
       if (useSplitDwarf()) {
         // This should be a unique identifier when we want to build .dwp files.
         uint64_t ID = 0;
@@ -1092,19 +1088,21 @@ void DwarfDebug::finalizeModuleInfo() {
         }
         TheU->addUInt(TheU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
                       dwarf::DW_FORM_data8, ID);
-        // Now construct the skeleton CU associated.
-        DwarfCompileUnit *SkCU =
-            constructSkeletonCU(static_cast<DwarfCompileUnit *>(TheU));
         SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
                       dwarf::DW_FORM_data8, ID);
-      } else {
-        // Attribute if we've emitted a range list for the compile unit, this
-        // will get constructed for the skeleton CU separately if we have one.
-        if (DwarfCURanges && TheU->getRanges().size())
-          addSectionLabel(Asm, TheU, TheU->getUnitDie(), dwarf::DW_AT_ranges,
-                          Asm->GetTempSymbol("cu_ranges", TheU->getUniqueID()),
-                          DwarfDebugRangeSectionSym);
       }
+
+      // If we've requested ranges and have them emit a DW_AT_ranges attribute
+      // on the unit that will remain in the .o file, otherwise add a DW_AT_low_pc.
+      // FIXME: Also add a high pc if we can.
+      // FIXME: We should use ranges if we have multiple compile units.
+      DwarfCompileUnit *U = SkCU ? SkCU : static_cast<DwarfCompileUnit *>(TheU);
+      if (DwarfCURanges && TheU->getRanges().size())
+        addSectionLabel(Asm, U, U->getUnitDie(), dwarf::DW_AT_ranges,
+                        Asm->GetTempSymbol("cu_ranges", U->getUniqueID()),
+                        DwarfDebugRangeSectionSym);
+      else
+        U->addUInt(U->getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);
     }
   }
 
@@ -2007,6 +2005,9 @@ void DwarfDebug::emitSectionLabels() {
   // Dwarf sections base addresses.
   DwarfInfoSectionSym =
       emitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info");
+  if (useSplitDwarf())
+    DwarfInfoDWOSectionSym =
+        emitSectionSym(Asm, TLOF.getDwarfInfoDWOSection(), "section_info_dwo");
   DwarfAbbrevSectionSym =
       emitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev");
   if (useSplitDwarf())
@@ -2872,7 +2873,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(CU->getLabelBegin(), CU->getSectionSym());
+    Asm->EmitSectionOffset(CU->getLocalLabelBegin(), CU->getLocalSectionSym());
     Asm->OutStreamer.AddComment("Address Size (in bytes)");
     Asm->EmitInt8(PtrSize);
     Asm->OutStreamer.AddComment("Segment Size (in bytes)");
@@ -2997,15 +2998,6 @@ DwarfCompileUnit *DwarfDebug::constructSkeletonCU(const DwarfCompileUnit *CU) {
   else
     NewCU->addSectionOffset(Die, dwarf::DW_AT_GNU_addr_base, 0);
 
-  // Attribute if we've emitted a range list for the compile unit, this
-  // will get constructed for the skeleton CU separately if we have one.
-  if (DwarfCURanges && CU->getRanges().size())
-    addSectionLabel(Asm, NewCU, Die, dwarf::DW_AT_ranges,
-                    Asm->GetTempSymbol("cu_ranges", CU->getUniqueID()),
-                    DwarfDebugRangeSectionSym);
-  else
-    NewCU->addUInt(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);
-
   // DW_AT_stmt_list is a offset of line number information for this
   // compile unit in debug_line section.
   // FIXME: Should handle multiple compile units.
index 10ce17fa2dd920fb5cb4f3c9a1a86879be16fc42..b81688ea3f0d37293968257526aaff0405dd720f 100644 (file)
@@ -429,7 +429,8 @@ class DwarfDebug : public AsmPrinterHandler {
   MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
   MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
   MCSymbol *FunctionBeginSym, *FunctionEndSym;
-  MCSymbol *DwarfAbbrevDWOSectionSym, *DwarfStrDWOSectionSym;
+  MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
+  MCSymbol *DwarfStrDWOSectionSym;
   MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
 
   // As an optimization, there is no need to emit an entry in the directory
index 693e37ffe8d557208d4e33403c62d70b3772bc8e..e32582e76b1a5bea97bf181c346c198712e9f9f2 100644 (file)
@@ -43,7 +43,7 @@ GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
 DwarfUnit::DwarfUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
                      DwarfDebug *DW, DwarfFile *DWU)
     : UniqueID(UID), Node(Node), UnitDie(D), DebugInfoOffset(0), Asm(A), DD(DW),
-      DU(DWU), IndexTyDie(0), Section(0) {
+      DU(DWU), IndexTyDie(0), Section(0), Skeleton(0) {
   DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1);
 }
 
index 7d7b351b9b015f04cc44874066500f74f061e75e..808c9c25ed35b91ac878e5f66856897b34529bc5 100644 (file)
@@ -146,12 +146,21 @@ protected:
   /// The label for the start of the range sets for the elements of this unit.
   MCSymbol *LabelRange;
 
+  /// Skeleton unit associated with this unit.
+  DwarfUnit *Skeleton;
+
   DwarfUnit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A,
             DwarfDebug *DW, DwarfFile *DWU);
 
 public:
   virtual ~DwarfUnit();
 
+  /// Set the skeleton unit associated with this unit.
+  void setSkeleton(DwarfUnit *Skel) { Skeleton = Skel; }
+
+  /// Get the skeleton unit associated with this unit.
+  DwarfUnit *getSkeleton() const { return Skeleton; }
+
   /// Pass in the SectionSym even though we could recreate it in every compile
   /// unit (type units will have actually distinct symbols once they're in
   /// comdat sections).
@@ -171,11 +180,27 @@ public:
     return Section;
   }
 
+  /// If there's a skeleton then return the section symbol for the skeleton
+  /// unit, otherwise return the section symbol for this unit.
+  MCSymbol *getLocalSectionSym() const {
+    if (Skeleton)
+      return Skeleton->getSectionSym();
+    return SectionSym;
+  }
+
   MCSymbol *getSectionSym() const {
     assert(Section);
     return SectionSym;
   }
 
+  /// If there's a skeleton then return the begin label for the skeleton unit,
+  /// otherwise return the local label for this unit.
+  MCSymbol *getLocalLabelBegin() const {
+    if (Skeleton)
+      return Skeleton->getLabelBegin();
+    return LabelBegin;
+  }
+
   MCSymbol *getLabelBegin() const {
     assert(Section);
     return LabelBegin;
index fd0d0a3e08d2636f296af57395f4663e91631b29..819f9863bc7b6cb986f3db2be1beca8812979a56 100644 (file)
@@ -1,6 +1,7 @@
 ; REQUIRES: object-emission
 
 ; RUN: llc -mtriple=x86_64-linux -O0 -filetype=obj < %s | llvm-dwarfdump -debug-dump=aranges - | FileCheck %s
+; RUN: llc -mtriple=x86_64-linux -O0 -filetype=obj < %s | llvm-readobj --relocations - | FileCheck --check-prefix=OBJ %s
 
 ; extern int i;
 ; template<int *x>
 ; CHECK-NEXT: [0x
 ; CHECK-NOT: [0x
 
+; Check that we have a relocation back to the debug_info section from the debug_aranges section
+; OBJ: debug_aranges
+; OBJ-NEXT: R_X86_64_32 .debug_info 0x0
+
 %struct.foo = type { i8 }
 
 @f = global %struct.foo zeroinitializer, align 1
index 06408d7081500f5a5cc231d07ce617c27a066b8a..d8f7a8e30018e59ffd21ee1624a4bdcec7f8a4e9 100644 (file)
 ; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_no
 ; CHECK: DW_AT_GNU_dwo_name      DW_FORM_strp
 ; CHECK: DW_AT_GNU_addr_base     DW_FORM_sec_offset
-; CHECK: DW_AT_low_pc    DW_FORM_addr
 ; CHECK: DW_AT_stmt_list DW_FORM_sec_offset
 ; CHECK: DW_AT_comp_dir  DW_FORM_strp
 ; CHECK: DW_AT_GNU_dwo_id        DW_FORM_data8
+; CHECK: DW_AT_low_pc    DW_FORM_addr
 
 ; CHECK: .debug_info contents:
 ; CHECK: DW_TAG_compile_unit
 ; CHECK: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000000] = "baz.dwo")
 ; CHECK: DW_AT_GNU_addr_base [DW_FORM_sec_offset]                   (0x00000000)
-; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 ; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x00000000)
 ; CHECK: DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x00000008] = "/usr/local/google/home/echristo/tmp")
 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8]  (0x0000000000000000)
+; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 
 ; CHECK: .debug_str contents:
 ; CHECK: 0x00000000: "baz.dwo"
 ; OBJ-NEXT: R_X86_64_32 .debug_line
 ; OBJ-NEXT: R_X86_64_32 .debug_str
 ; OBJ-NEXT: }
+; OBJ: .debug_aranges
+; OBJ-NEXT: R_X86_64_32 .debug_info 0x0
+
 !9 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
index 147937aaf48d11529ab0b47d251c22a146c4cf9a..e63cbd11e48faddaaa14384404f7a5b7db37b10d 100644 (file)
@@ -7,12 +7,12 @@
 ; rdar://13067005
 ; CHECK: .debug_info contents:
 ; CHECK: DW_TAG_compile_unit
-; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 ; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x00000000)
+; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 
 ; CHECK: DW_TAG_compile_unit
-; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 ; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset]   (0x0000003c)
+; CHECK: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 
 ; CHECK: .debug_line contents:
 ; CHECK-NEXT: Line table prologue:
 
 ; DWARF3: .debug_info contents:
 ; DWARF3: DW_TAG_compile_unit
-; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 ; DWARF3: DW_AT_stmt_list [DW_FORM_data4]   (0x00000000)
+; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 
 ; DWARF3: DW_TAG_compile_unit
-; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 ; DWARF3: DW_AT_stmt_list [DW_FORM_data4]   (0x0000003c)
+; DWARF3: DW_AT_low_pc [DW_FORM_addr]       (0x0000000000000000)
 
 ; DWARF3: .debug_line contents:
 ; DWARF3-NEXT: Line table prologue: