[llvm] r222029 - [dwarfdump] Handle relocations in Dwarf accelerator tables

Frederic Riss friss at apple.com
Fri Nov 14 11:30:08 PST 2014


Author: friss
Date: Fri Nov 14 13:30:08 2014
New Revision: 222029

URL: http://llvm.org/viewvc/llvm-project?rev=222029&view=rev
Log:
[dwarfdump] Handle relocations in Dwarf accelerator tables

ELF targets (and maybe COFF) use relocations when referring
to strings in the .debug_str section. Handle that in the
accelerator table dumper. This commit restores the
test/DebugInfo/cross-cu-inlining.ll test to its expected
platform independant form, validating that the fix works
(this test failed on linux boxes).

Modified:
    llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.cpp
    llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.h
    llvm/trunk/lib/DebugInfo/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARFContext.h
    llvm/trunk/test/DebugInfo/cross-cu-inlining.ll

Modified: llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.cpp?rev=222029&r1=222028&r2=222029&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.cpp Fri Nov 14 13:30:08 2014
@@ -92,7 +92,13 @@ void DWARFAcceleratorTable::dump(raw_ost
         OS << "    Invalid section offset\n";
         continue;
       }
-      while (unsigned StringOffset = AccelSection.getU32(&DataOffset)) {
+      while (AccelSection.isValidOffsetForDataOfSize(DataOffset, 4)) {
+        unsigned StringOffset = AccelSection.getU32(&DataOffset);
+        RelocAddrMap::const_iterator Reloc = Relocs.find(DataOffset-4);
+        if (Reloc != Relocs.end())
+          StringOffset += Reloc->second.second;
+        if (!StringOffset)
+          break;
         OS << format("    Name: %08x \"%s\"\n", StringOffset,
                      StringSection.getCStr(&StringOffset));
         unsigned NumData = AccelSection.getU32(&DataOffset);

Modified: llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.h?rev=222029&r1=222028&r2=222029&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFAcceleratorTable.h Fri Nov 14 13:30:08 2014
@@ -1,4 +1,6 @@
 
+#include "DWARFRelocMap.h"
+
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/DebugInfo/DWARFFormValue.h"
 
@@ -27,9 +29,11 @@ class DWARFAcceleratorTable {
   struct HeaderData HdrData;
   DataExtractor AccelSection;
   DataExtractor StringSection;
+  const RelocAddrMap& Relocs;
 public:
-  DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection)
-    : AccelSection(AccelSection), StringSection(StringSection) {}
+  DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection,
+                        const RelocAddrMap &Relocs)
+    : AccelSection(AccelSection), StringSection(StringSection), Relocs(Relocs) {}
 
   bool extract();
   void dump(raw_ostream &OS);

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=222029&r1=222028&r2=222029&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.cpp Fri Nov 14 13:30:08 2014
@@ -60,12 +60,13 @@ static void dumpPubSection(raw_ostream &
   }
 }
 
-static void dumpAccelSection(raw_ostream &OS, StringRef Name, StringRef Data,
-                             StringRef StringSection, bool LittleEndian) {
-  DataExtractor AccelSection(Data, LittleEndian, 0);
+static void dumpAccelSection(raw_ostream &OS, StringRef Name,
+                             const DWARFSection& Section, StringRef StringSection,
+                             bool LittleEndian) {
+  DataExtractor AccelSection(Section.Data, LittleEndian, 0);
   DataExtractor StrData(StringSection, LittleEndian, 0);
   OS << "\n." << Name << " contents:\n";
-  DWARFAcceleratorTable Accel(AccelSection, StrData);
+  DWARFAcceleratorTable Accel(AccelSection, StrData, Section.Relocs);
   if (!Accel.extract())
     return;
   Accel.dump(OS);
@@ -593,11 +594,11 @@ DWARFContextInMemory::DWARFContextInMemo
             .Case("debug_str.dwo", &StringDWOSection)
             .Case("debug_str_offsets.dwo", &StringOffsetDWOSection)
             .Case("debug_addr", &AddrSection)
-            .Case("apple_names", &AppleNamesSection)
-            .Case("apple_types", &AppleTypesSection)
-            .Case("apple_namespaces", &AppleNamespacesSection)
-            .Case("apple_namespac", &AppleNamespacesSection)
-            .Case("apple_objc", &AppleObjCSection)
+            .Case("apple_names", &AppleNamesSection.Data)
+            .Case("apple_types", &AppleTypesSection.Data)
+            .Case("apple_namespaces", &AppleNamespacesSection.Data)
+            .Case("apple_namespac", &AppleNamespacesSection.Data)
+            .Case("apple_objc", &AppleObjCSection.Data)
             // Any more debug info sections go here.
             .Default(nullptr);
     if (SectionData) {
@@ -630,6 +631,11 @@ DWARFContextInMemory::DWARFContextInMemo
         .Case("debug_loc", &LocSection.Relocs)
         .Case("debug_info.dwo", &InfoDWOSection.Relocs)
         .Case("debug_line", &LineSection.Relocs)
+        .Case("apple_names", &AppleNamesSection.Relocs)
+        .Case("apple_types", &AppleTypesSection.Relocs)
+        .Case("apple_namespaces", &AppleNamespacesSection.Relocs)
+        .Case("apple_namespac", &AppleNamespacesSection.Relocs)
+        .Case("apple_objc", &AppleObjCSection.Relocs)
         .Default(nullptr);
     if (!Map) {
       // Find debug_types relocs by section rather than name as there are

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=222029&r1=222028&r2=222029&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.h Fri Nov 14 13:30:08 2014
@@ -192,10 +192,10 @@ public:
   virtual StringRef getStringOffsetDWOSection() = 0;
   virtual StringRef getRangeDWOSection() = 0;
   virtual StringRef getAddrSection() = 0;
-  virtual StringRef getAppleNamesSection() = 0;
-  virtual StringRef getAppleTypesSection() = 0;
-  virtual StringRef getAppleNamespacesSection() = 0;
-  virtual StringRef getAppleObjCSection() = 0;
+  virtual const DWARFSection& getAppleNamesSection() = 0;
+  virtual const DWARFSection& getAppleTypesSection() = 0;
+  virtual const DWARFSection& getAppleNamespacesSection() = 0;
+  virtual const DWARFSection& getAppleObjCSection() = 0;
 
   static bool isSupportedVersion(unsigned version) {
     return version == 2 || version == 3 || version == 4;
@@ -240,10 +240,10 @@ class DWARFContextInMemory : public DWAR
   StringRef StringOffsetDWOSection;
   StringRef RangeDWOSection;
   StringRef AddrSection;
-  StringRef AppleNamesSection;
-  StringRef AppleTypesSection;
-  StringRef AppleNamespacesSection;
-  StringRef AppleObjCSection;
+  DWARFSection AppleNamesSection;
+  DWARFSection AppleTypesSection;
+  DWARFSection AppleNamespacesSection;
+  DWARFSection AppleObjCSection;
 
   SmallVector<SmallString<32>, 4> UncompressedSections;
 
@@ -264,10 +264,10 @@ public:
   StringRef getPubTypesSection() override { return PubTypesSection; }
   StringRef getGnuPubNamesSection() override { return GnuPubNamesSection; }
   StringRef getGnuPubTypesSection() override { return GnuPubTypesSection; }
-  StringRef getAppleNamesSection() override { return AppleNamesSection; }
-  StringRef getAppleTypesSection() override { return AppleTypesSection; }
-  StringRef getAppleNamespacesSection() override { return AppleNamespacesSection; }
-  StringRef getAppleObjCSection() override { return AppleObjCSection; }
+  const DWARFSection& getAppleNamesSection() override { return AppleNamesSection; }
+  const DWARFSection& getAppleTypesSection() override { return AppleTypesSection; }
+  const DWARFSection& getAppleNamespacesSection() override { return AppleNamespacesSection; }
+  const DWARFSection& getAppleObjCSection() override { return AppleObjCSection; }
 
   // Sections for DWARF5 split dwarf proposal.
   const DWARFSection &getInfoDWOSection() override { return InfoDWOSection; }

Modified: llvm/trunk/test/DebugInfo/cross-cu-inlining.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/cross-cu-inlining.ll?rev=222029&r1=222028&r2=222029&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/cross-cu-inlining.ll (original)
+++ llvm/trunk/test/DebugInfo/cross-cu-inlining.ll Fri Nov 14 13:30:08 2014
@@ -1,7 +1,7 @@
 ; REQUIRES: object-emission
 
 ; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck -implicit-check-not=DW_TAG %s
-; RUN: %llc_dwarf -mtriple x86_64-apple-darwin -O0 -filetype=obj < %s | llvm-dwarfdump - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
+; RUN: %llc_dwarf -dwarf-accel-tables=Enable -O0 -filetype=obj < %s | llvm-dwarfdump - | FileCheck --check-prefix=CHECK-ACCEL --check-prefix=CHECK %s
 
 ; Build from source:
 ; $ clang++ a.cpp b.cpp -g -c -emit-llvm





More information about the llvm-commits mailing list