[llvm] r314208 - [dwarfdump] Skip 'stripped' sections

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 07:22:35 PDT 2017


Author: jdevlieghere
Date: Tue Sep 26 07:22:35 2017
New Revision: 314208

URL: http://llvm.org/viewvc/llvm-project?rev=314208&view=rev
Log:
[dwarfdump] Skip 'stripped' sections

When dsymutil generates the companion file, its strips all unnecessary
sections by omitting their body and setting the offset in their
corresponding load command to zero.

One such section is the .eh_frame section, as it contains runtime
information rather than debug information and is part of the __TEXT
segment. When reading this section, we would just read the number of
bytes specified in the load command, starting from offset 0 (i.e. the
beginning of the file).

Rather than trying to parse this obviously invalid section, dwarfdump
now skips this.

Differential revision: https://reviews.llvm.org/D38135

Added:
    llvm/trunk/test/tools/llvm-dwarfdump/X86/Inputs/empty.dSYM
    llvm/trunk/test/tools/llvm-dwarfdump/X86/stripped.test
Modified:
    llvm/trunk/include/llvm/Object/MachO.h
    llvm/trunk/include/llvm/Object/ObjectFile.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/Object/MachOObjectFile.cpp
    llvm/trunk/lib/Object/ObjectFile.cpp

Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=314208&r1=314207&r2=314208&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Tue Sep 26 07:22:35 2017
@@ -310,6 +310,16 @@ public:
   bool isSectionBSS(DataRefImpl Sec) const override;
   bool isSectionVirtual(DataRefImpl Sec) const override;
   bool isSectionBitcode(DataRefImpl Sec) const override;
+
+  /// When dsymutil generates the companion file, it strips all unnecessary
+  /// sections (e.g. everything in the _TEXT segment) by omitting their body
+  /// and setting the offset in their corresponding load command to zero.
+  ///
+  /// While the load command itself is valid, reading the section corresponds
+  /// to reading the number of bytes specified in the load command, starting
+  /// from offset 0 (i.e. the Mach-O header at the beginning of the file).
+  bool isSectionStripped(DataRefImpl Sec) const override;
+
   relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
   relocation_iterator section_rel_end(DataRefImpl Sec) const override;
 

Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=314208&r1=314207&r2=314208&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Tue Sep 26 07:22:35 2017
@@ -109,6 +109,7 @@ public:
   bool isBSS() const;
   bool isVirtual() const;
   bool isBitcode() const;
+  bool isStripped() const;
 
   bool containsSymbol(SymbolRef S) const;
 
@@ -236,6 +237,7 @@ protected:
   // A section is 'virtual' if its contents aren't present in the object image.
   virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
   virtual bool isSectionBitcode(DataRefImpl Sec) const;
+  virtual bool isSectionStripped(DataRefImpl Sec) const;
   virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
   virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
   virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
@@ -442,6 +444,10 @@ inline bool SectionRef::isBitcode() cons
   return OwningObject->isSectionBitcode(SectionPimpl);
 }
 
+inline bool SectionRef::isStripped() const {
+  return OwningObject->isSectionStripped(SectionPimpl);
+}
+
 inline relocation_iterator SectionRef::relocation_begin() const {
   return OwningObject->section_rel_begin(SectionPimpl);
 }

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=314208&r1=314207&r2=314208&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Tue Sep 26 07:22:35 2017
@@ -1135,6 +1135,10 @@ public:
       if (Section.isBSS() || Section.isVirtual())
         continue;
 
+      // Skip sections stripped by dsymutil.
+      if (Section.isStripped())
+        continue;
+
       StringRef Data;
       section_iterator RelocatedSection = Section.getRelocatedSection();
       // Try to obtain an already relocated version of this section.

Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=314208&r1=314207&r2=314208&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Tue Sep 26 07:22:35 2017
@@ -1928,6 +1928,12 @@ bool MachOObjectFile::isSectionBitcode(D
   return false;
 }
 
+bool MachOObjectFile::isSectionStripped(DataRefImpl Sec) const {
+  if (is64Bit())
+    return getSection64(Sec).offset == 0;
+  return getSection(Sec).offset == 0;
+}
+
 relocation_iterator MachOObjectFile::section_rel_begin(DataRefImpl Sec) const {
   DataRefImpl Ret;
   Ret.d.a = Sec.d.a;

Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=314208&r1=314207&r2=314208&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Tue Sep 26 07:22:35 2017
@@ -75,6 +75,8 @@ bool ObjectFile::isSectionBitcode(DataRe
   return false;
 }
 
+bool ObjectFile::isSectionStripped(DataRefImpl Sec) const { return false; }
+
 section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
   return section_iterator(SectionRef(Sec, this));
 }

Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/Inputs/empty.dSYM
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/Inputs/empty.dSYM?rev=314208&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwarfdump/X86/Inputs/empty.dSYM (added) and llvm/trunk/test/tools/llvm-dwarfdump/X86/Inputs/empty.dSYM Tue Sep 26 07:22:35 2017 differ

Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/stripped.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/stripped.test?rev=314208&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/stripped.test (added)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/stripped.test Tue Sep 26 07:22:35 2017
@@ -0,0 +1,11 @@
+RUN: llvm-dwarfdump -debug-frame %S/Inputs/empty.dSYM | FileCheck %s
+
+You can generate an empty dSYM companion file by invoking dsymutil on any
+object file.
+
+CHECK: .debug_frame contents:
+CHECK-NOT: CIE
+CHECK-NOT: FDE
+CHECK: .eh_frame contents:
+CHECK-NOT: CIE
+CHECK-NOT: FDE




More information about the llvm-commits mailing list