[llvm] r197197 - DebugInfo: Move type units into the debug_types section with appropriate comdat grouping and type unit headers

David Blaikie dblaikie at gmail.com
Thu Dec 12 17:06:41 PST 2013


Author: dblaikie
Date: Thu Dec 12 19:06:41 2013
New Revision: 197197

URL: http://llvm.org/viewvc/llvm-project?rev=197197&view=rev
Log:
DebugInfo: Move type units into the debug_types section with appropriate comdat grouping and type unit headers

This commit does not complete the type units feature - there are issues
around fission support (skeletal type units, pubtypes/pubnames) and
hashing of some types including those containing references to types in
other type units.

Originally committed as r197073 and reverted in r197079.

This commit originally got jumbled up with another build-breaking commit
and I can't find the failures I thought this caused anymore.
Recommitting to hopefully get some clean buildbot results to work from.
I have a sneaking suspicion there's unstable output in the comdat group
output of MCStreamer...

Modified:
    llvm/trunk/include/llvm/MC/MCObjectFileInfo.h
    llvm/trunk/include/llvm/MC/MCSectionELF.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
    llvm/trunk/lib/MC/MCObjectFileInfo.cpp
    llvm/trunk/test/DebugInfo/X86/c-type-units.ll
    llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll

Modified: llvm/trunk/include/llvm/MC/MCObjectFileInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectFileInfo.h?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectFileInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectFileInfo.h Thu Dec 12 19:06:41 2013
@@ -262,6 +262,8 @@ public:
   const MCSection *getDwarfInfoDWOSection() const {
     return DwarfInfoDWOSection;
   }
+  const MCSection *getDwarfTypesSection(uint64_t Hash) const;
+  const MCSection *getDwarfTypesDWOSection(uint64_t Hash) const;
   const MCSection *getDwarfAbbrevDWOSection() const {
     return DwarfAbbrevDWOSection;
   }

Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Thu Dec 12 19:06:41 2013
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCSymbol.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/raw_ostream.h"
@@ -60,8 +61,13 @@ public:
 
   StringRef getSectionName() const { return SectionName; }
   virtual std::string getLabelBeginName() const {
-    return SectionName.str() + "_begin"; }
+    if (Group)
+      return (SectionName.str() + '_' + Group->getName() + "_begin").str();
+    return SectionName.str() + "_begin";
+  }
   virtual std::string getLabelEndName() const {
+    if (Group)
+      return (SectionName.str() + '_' + Group->getName() + "_end").str();
     return SectionName.str() + "_end";
   }
   unsigned getType() const { return Type; }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Dec 12 19:06:41 2013
@@ -3056,19 +3056,17 @@ void DwarfDebug::addDwarfTypeUnitType(ui
     // referenced type, or possibly walk the precomputed hashes of related types
     // at the end.
     uint64_t Signature = DIEHash().computeTypeSignature(*Die);
+    NewTU->setTypeSignature(Signature);
+    NewTU->setType(Die);
 
     // Remove the References vector and add the type hash.
     I->second.first = Signature;
     I->second.second = NULL;
 
     NewTU->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
-        useSplitDwarf() ? NULL : DwarfInfoSectionSym);
+        useSplitDwarf()
+            ? Asm->getObjFileLowering().getDwarfTypesDWOSection(Signature)
+            : Asm->getObjFileLowering().getDwarfTypesSection(Signature));
   }
 
   // Populate all the signatures.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Thu Dec 12 19:06:41 2013
@@ -1997,3 +1997,27 @@ void DwarfUnit::emitHeader(const MCSecti
   Asm->OutStreamer.AddComment("Address Size (in bytes)");
   Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
 }
+
+void DwarfTypeUnit::emitHeader(const MCSection *ASection,
+                               const MCSymbol *ASectionSym) const {
+  DwarfUnit::emitHeader(ASection, ASectionSym);
+  Asm->OutStreamer.AddComment("Type Signature");
+  Asm->OutStreamer.EmitIntValue(TypeSignature, sizeof(TypeSignature));
+  Asm->OutStreamer.AddComment("Type DIE Offset");
+  Asm->OutStreamer.EmitIntValue(Ty->getOffset(), sizeof(Ty->getOffset()));
+}
+
+void DwarfTypeUnit::initSection(const MCSection *Section) {
+  assert(!this->Section);
+  this->Section = Section;
+  // Since each type unit is contained in its own COMDAT section, the begin
+  // label and the section label are the same. Using the begin label emission in
+  // DwarfDebug to emit the section label as well is slightly subtle/sneaky, but
+  // the only other alternative of lazily constructing start-of-section labels
+  // and storing a mapping in DwarfDebug (or AsmPrinter).
+  this->SectionSym = this->LabelBegin =
+      Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID());
+  this->LabelEnd =
+      Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID());
+  this->LabelRange = Asm->GetTempSymbol("gnu_ranges", getUniqueID());
+}

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Thu Dec 12 19:06:41 2013
@@ -413,14 +413,15 @@ public:
 
   /// Compute the size of a header for this unit, not including the initial
   /// length field.
-  unsigned getHeaderSize() const {
+  virtual unsigned getHeaderSize() const {
     return sizeof(int16_t) + // DWARF version number
            sizeof(int32_t) + // Offset Into Abbrev. Section
            sizeof(int8_t);   // Pointer Size (in bytes)
   }
 
   /// Emit the header for this unit, not including the initial length field.
-  void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym) const;
+  virtual void emitHeader(const MCSection *ASection,
+                          const MCSymbol *ASectionSym) const;
 
 protected:
   /// getOrCreateStaticMemberDIE - Create new static data member DIE.
@@ -513,12 +514,25 @@ public:
 class DwarfTypeUnit : public DwarfUnit {
 private:
   uint16_t Language;
+  uint64_t TypeSignature;
+  const DIE *Ty;
 
 public:
   DwarfTypeUnit(unsigned UID, DIE *D, uint16_t Language, AsmPrinter *A,
                 DwarfDebug *DW, DwarfFile *DWU);
 
+  void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
+  void setType(const DIE *Ty) { this->Ty = Ty; }
+
   uint16_t getLanguage() const LLVM_OVERRIDE { return Language; }
+  /// Emit the header for this unit, not including the initial length field.
+  void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym) const
+      LLVM_OVERRIDE;
+  unsigned getHeaderSize() const LLVM_OVERRIDE {
+    return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
+           sizeof(uint32_t);                               // Type DIE Offset
+  }
+  void initSection(const MCSection *Section);
 };
 } // end llvm namespace
 #endif

Modified: llvm/trunk/lib/MC/MCObjectFileInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectFileInfo.cpp?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectFileInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectFileInfo.cpp Thu Dec 12 19:06:41 2013
@@ -9,6 +9,7 @@
 
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSectionCOFF.h"
@@ -718,6 +719,17 @@ void MCObjectFileInfo::InitMCObjectFileI
   }
 }
 
+const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
+  return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
+                            SectionKind::getMetadata(), 0, utostr(Hash));
+}
+
+const MCSection *
+MCObjectFileInfo::getDwarfTypesDWOSection(uint64_t Hash) const {
+  return Ctx->getELFSection(".debug_types.dwo", ELF::SHT_GROUP, 0,
+                            SectionKind::getMetadata(), 0, utostr(Hash));
+}
+
 void MCObjectFileInfo::InitEHFrameSection() {
   if (Env == IsMachO)
     EHFrameSection =

Modified: llvm/trunk/test/DebugInfo/X86/c-type-units.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/c-type-units.ll?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/c-type-units.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/c-type-units.ll Thu Dec 12 19:06:41 2013
@@ -1,6 +1,6 @@
 ; REQUIRES: object-emission
 
-; RUN: llc -o - %s -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu | llvm-dwarfdump -debug-dump=info - | FileCheck %s
+; RUN: llc -o - %s -filetype=obj -O0 -generate-dwarf-pub-sections=Disable -generate-type-units -mtriple=x86_64-unknown-linux-gnu | llvm-dwarfdump -debug-dump=types - | FileCheck %s
 
 ; struct foo {
 ; } f;

Modified: llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll?rev=197197&r1=197196&r2=197197&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll Thu Dec 12 19:06:41 2013
@@ -45,13 +45,12 @@
 
 ; CHECK-LABEL: .debug_info contents:
 ; CHECK: Compile Unit: length = [[CU_SIZE:[0-9a-f]+]]
-; Check that we generate a hash for bar and the value.
-; CHECK-LABEL: DW_AT_GNU_odr_signature [DW_FORM_data8] (0x200520c0d5b90eff)
-; CHECK: DW_TAG_structure_type
-; CHECK-NEXT: debug_str{{.*}}"bar"
+
+; CHECK-LABEL: .debug_types contents:
 
 ; Check that we generate a hash for fluffy and the value.
-; CHECK-LABEL: DW_AT_GNU_odr_signature [DW_FORM_data8]   (0x9a0124d5a0c21c52)
+; CHECK-LABEL: type_signature = 0x139b2e1ea94afec7
+; CHECK: DW_AT_GNU_odr_signature [DW_FORM_data8]   (0x9a0124d5a0c21c52)
 ; CHECK: DW_TAG_namespace
 ; CHECK-NEXT: debug_str{{.*}}"echidna"
 ; CHECK: DW_TAG_namespace
@@ -61,10 +60,24 @@
 ; CHECK: DW_TAG_class_type
 ; CHECK-NEXT: debug_str{{.*}}"fluffy"
 
-; We emit no hash for walrus since the type is contained in an anonymous
+; Check that we generate a hash for wombat and the value, but not for the
+; anonymous type contained within.
+; CHECK-LABEL: type_signature = 0x73776f130648b986
+; CHECK: DW_AT_GNU_odr_signature [DW_FORM_data8] (0x685bcc220141e9d7)
+; CHECK: DW_TAG_structure_type
+; CHECK-NEXT: debug_str{{.*}}"wombat"
+
+; Check that we generate a hash for bar and the value.
+; CHECK-LABEL: type_signature = 0x6a7ee3d400662e88
+; CHECK: DW_AT_GNU_odr_signature [DW_FORM_data8] (0x200520c0d5b90eff)
+; CHECK: DW_TAG_structure_type
+; CHECK-NEXT: debug_str{{.*}}"bar"
+
 ; namespace and won't violate any ODR-ness.
+; CHECK-LABEL: type_signature = 0xc0d031d6449dbca7
 ; CHECK: DW_TAG_type_unit
 ; CHECK-NOT: NULL
+; We emit no hash for walrus since the type is contained in an anonymous
 ; CHECK-NOT: DW_AT_GNU_odr_signature
 ; CHECK: DW_TAG_structure_type
 ; CHECK-NEXT: debug_str{{.*}}"walrus"
@@ -74,13 +87,8 @@
 ; CHECK: DW_TAG_subprogram
 
 
-; Check that we generate a hash for wombat and the value, but not for the
-; anonymous type contained within.
-; CHECK-LABEL: DW_AT_GNU_odr_signature [DW_FORM_data8] (0x685bcc220141e9d7)
-; CHECK: DW_TAG_structure_type
-; CHECK-NEXT: debug_str{{.*}}"wombat"
-; CHECK: DW_TAG_type_unit
-; CHECK: DW_TAG_structure_type
+; Check that we generate no ODR hash for the anonymous type nested inside 'wombat'
+; CHECK-LABEL: type_signature = 0xbf6fc40e82583d7c
 ; The signature for the outer 'wombat' type - this can be FileChecked once the
 ; type units are moved to their own section with the full type unit header
 ; including the signature
@@ -98,20 +106,20 @@
 ; CHECK-NEXT: unit_size = [[CU_SIZE]]
 ; CHECK-NEXT: Offset Name
 ; Type unit for 'bar'
-; CHECK-NEXT: unit_size = 0x0000001f
+; CHECK-NEXT: unit_size = 0x0000002b
 ; CHECK-NEXT: Offset Name
 ; CHECK-NEXT: "bar"
-; CHECK-NEXT: unit_size = 0x00000059
+; CHECK-NEXT: unit_size = 0x00000065
 ; CHECK-NEXT: Offset Name
 ; CHECK-NEXT: "int"
 ; CHECK-NEXT: "echidna::capybara::mongoose::fluffy"
-; CHECK-NEXT: unit_size = 0x0000002f
+; CHECK-NEXT: unit_size = 0x0000003b
 ; CHECK-NEXT: Offset Name
 ; CHECK-NEXT: "walrus"
-; CHECK-NEXT: unit_size = 0x00000036
+; CHECK-NEXT: unit_size = 0x00000042
 ; CHECK-NEXT: Offset Name
 ; CHECK-NEXT: "wombat"
-; CHECK-NEXT: unit_size = 0x0000003f
+; CHECK-NEXT: unit_size = 0x0000004b
 ; CHECK-NEXT: Offset Name
 ; CHECK-NEXT: "int"
 





More information about the llvm-commits mailing list