[llvm] r180088 - Use zlib to uncompress debug sections in DWARF parser.

Alexey Samsonov samsonov at google.com
Tue Apr 23 03:17:35 PDT 2013


Author: samsonov
Date: Tue Apr 23 05:17:34 2013
New Revision: 180088

URL: http://llvm.org/viewvc/llvm-project?rev=180088&view=rev
Log:
Use zlib to uncompress debug sections in DWARF parser.

This makes llvm-dwarfdump and llvm-symbolizer understand
debug info sections compressed by ld.gold linker.

Added:
    llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc
    llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.elf-x86-64   (with props)
    llvm/trunk/test/DebugInfo/dwarfdump-zlib.test
Modified:
    llvm/trunk/cmake/config-ix.cmake
    llvm/trunk/lib/DebugInfo/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARFContext.h
    llvm/trunk/test/Makefile
    llvm/trunk/test/lit.cfg
    llvm/trunk/test/lit.site.cfg.in

Modified: llvm/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/config-ix.cmake?rev=180088&r1=180087&r2=180088&view=diff
==============================================================================
--- llvm/trunk/cmake/config-ix.cmake (original)
+++ llvm/trunk/cmake/config-ix.cmake Tue Apr 23 05:17:34 2013
@@ -105,7 +105,11 @@ if( NOT PURE_WINDOWS )
   endif()
   check_library_exists(dl dlopen "" HAVE_LIBDL)
   check_library_exists(rt clock_gettime "" HAVE_LIBRT)
-  check_library_exists(z compress2 "" HAVE_LIBZ)
+  if (LLVM_ENABLE_ZLIB)
+    check_library_exists(z compress2 "" HAVE_LIBZ)
+  else()
+    set(HAVE_LIBZ 0)
+  endif()
 endif()
 
 # function checks

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=180088&r1=180087&r2=180088&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.cpp Tue Apr 23 05:17:34 2013
@@ -10,6 +10,8 @@
 #include "DWARFContext.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Compression.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/Path.h"
@@ -483,6 +485,22 @@ DIInliningInfo DWARFContext::getInlining
   return InliningInfo;
 }
 
+static bool consumeCompressedDebugSectionHeader(StringRef &data,
+                                                uint64_t &OriginalSize) {
+  // Consume "ZLIB" prefix.
+  if (!data.startswith("ZLIB"))
+    return false;
+  data = data.substr(4);
+  // Consume uncompressed section size (big-endian 8 bytes).
+  DataExtractor extractor(data, false, 8);
+  uint32_t Offset = 0;
+  OriginalSize = extractor.getU64(&Offset);
+  if (Offset == 0)
+    return false;
+  data = data.substr(Offset);
+  return true;
+}
+
 DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
   IsLittleEndian(Obj->isLittleEndian()),
   AddressSize(Obj->getBytesInAddress()) {
@@ -497,6 +515,22 @@ DWARFContextInMemory::DWARFContextInMemo
 
     name = name.substr(name.find_first_not_of("._")); // Skip . and _ prefixes.
 
+    // Check if debug info section is compressed with zlib.
+    if (name.startswith("zdebug_")) {
+      uint64_t OriginalSize;
+      if (!zlib::isAvailable() ||
+          !consumeCompressedDebugSectionHeader(data, OriginalSize))
+        continue;
+      OwningPtr<MemoryBuffer> UncompressedSection;
+      if (zlib::uncompress(data, UncompressedSection, OriginalSize) !=
+          zlib::StatusOK)
+        continue;
+      // Make data point to uncompressed section contents and save its contents.
+      name = name.substr(1);
+      data = UncompressedSection->getBuffer();
+      UncompressedSections.push_back(UncompressedSection.take());
+    }
+
     StringRef *Section = StringSwitch<StringRef*>(name)
         .Case("debug_info", &InfoSection)
         .Case("debug_abbrev", &AbbrevSection)
@@ -584,4 +618,8 @@ DWARFContextInMemory::DWARFContextInMemo
   }
 }
 
+DWARFContextInMemory::~DWARFContextInMemory() {
+  DeleteContainerPointers(UncompressedSections);
+}
+
 void DWARFContextInMemory::anchor() { }

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=180088&r1=180087&r2=180088&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.h Tue Apr 23 05:17:34 2013
@@ -161,8 +161,11 @@ class DWARFContextInMemory : public DWAR
   StringRef RangeDWOSection;
   StringRef AddrSection;
 
+  SmallVector<MemoryBuffer*, 4> UncompressedSections;
+
 public:
   DWARFContextInMemory(object::ObjectFile *);
+  ~DWARFContextInMemory();
   virtual bool isLittleEndian() const { return IsLittleEndian; }
   virtual uint8_t getAddressSize() const { return AddressSize; }
   virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }

Added: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc?rev=180088&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc (added)
+++ llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc Tue Apr 23 05:17:34 2013
@@ -0,0 +1,24 @@
+class DummyClass {
+  int a_;
+ public:
+  DummyClass(int a) : a_(a) {}
+  int add(int b) {
+    return a_ + b;
+  }
+};
+
+int f(int a, int b) {
+  DummyClass c(a);
+  return c.add(b);
+}
+
+int main() {
+  return f(2, 3);
+}
+
+// Built with Clang 3.2 and ld.gold linker:
+// $ mkdir -p /tmp/dbginfo
+// $ cp dwarfdump-test-zlib.cc /tmp/dbginfo
+// $ cd /tmp/dbginfo
+// $ clang++ -g dwarfdump-test-zlib.cc -Wl,--compress-debug-sections=zlib \
+//   -o <output>

Added: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.elf-x86-64?rev=180088&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.elf-x86-64
------------------------------------------------------------------------------
    svn:executable = *

Propchange: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test-zlib.elf-x86-64
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: llvm/trunk/test/DebugInfo/dwarfdump-zlib.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-zlib.test?rev=180088&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/dwarfdump-zlib.test (added)
+++ llvm/trunk/test/DebugInfo/dwarfdump-zlib.test Tue Apr 23 05:17:34 2013
@@ -0,0 +1,12 @@
+REQUIRES: zlib
+
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test-zlib.elf-x86-64  \
+RUN:   | FileCheck %s -check-prefix FULLDUMP
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test-zlib.elf-x86-64  \
+RUN:   --address=0x400559 --functions | FileCheck %s -check-prefix MAIN
+
+FULLDUMP: .debug_abbrev contents
+FULLDUMP: .debug_info contents
+
+MAIN: main
+MAIN-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test-zlib.cc:16

Modified: llvm/trunk/test/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Makefile?rev=180088&r1=180087&r2=180088&view=diff
==============================================================================
--- llvm/trunk/test/Makefile (original)
+++ llvm/trunk/test/Makefile Tue Apr 23 05:17:34 2013
@@ -141,6 +141,7 @@ lit.site.cfg: FORCE
 	@$(ECHOPATH) s=@LLVM_BINDINGS@=$(BINDINGS_TO_BUILD)=g >> lit.tmp
 	@$(ECHOPATH) s=@HOST_OS@=$(HOST_OS)=g >> lit.tmp
 	@$(ECHOPATH) s=@HOST_ARCH@=$(HOST_ARCH)=g >> lit.tmp
+	@$(ECHOPATH) s=@HAVE_LIBZ@=$(HAVE_LIBZ)=g >> lit.tmp
 	@sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@
 	@-rm -f lit.tmp
 

Modified: llvm/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=180088&r1=180087&r2=180088&view=diff
==============================================================================
--- llvm/trunk/test/lit.cfg (original)
+++ llvm/trunk/test/lit.cfg Tue Apr 23 05:17:34 2013
@@ -268,6 +268,9 @@ if (config.llvm_use_sanitizer == "Memory
 if not 'hexagon' in config.target_triple:
     config.available_features.add("object-emission")
 
+if config.have_zlib == "1":
+    config.available_features.add("zlib")
+
 # llc knows whether he is compiled with -DNDEBUG.
 import subprocess
 try:

Modified: llvm/trunk/test/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.site.cfg.in?rev=180088&r1=180087&r2=180088&view=diff
==============================================================================
--- llvm/trunk/test/lit.site.cfg.in (original)
+++ llvm/trunk/test/lit.site.cfg.in Tue Apr 23 05:17:34 2013
@@ -19,6 +19,7 @@ config.host_os = "@HOST_OS@"
 config.host_arch = "@HOST_ARCH@"
 config.llvm_use_intel_jitevents = "@LLVM_USE_INTEL_JITEVENTS@"
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
+config.have_zlib = "@HAVE_LIBZ@"
 
 # Support substitution of the tools_dir with user parameters. This is
 # used when we can't determine the tool dir at configuration time.





More information about the llvm-commits mailing list