[llvm] r206659 - Compress debug sections only when beneficial.

David Blaikie dblaikie at gmail.com
Fri Apr 18 14:52:26 PDT 2014


Author: dblaikie
Date: Fri Apr 18 16:52:26 2014
New Revision: 206659

URL: http://llvm.org/viewvc/llvm-project?rev=206659&view=rev
Log:
Compress debug sections only when beneficial.

Both ZLIB and the debug info compressed section header ("ZLIB" + the
size of the uncompressed data) take some constant overhead so in some
cases the compressed data is actually larger than the uncompressed data.
In these cases, just don't compress or rename the section at all.

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/test/MC/ELF/compression.s

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=206659&r1=206658&r2=206659&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri Apr 18 16:52:26 2014
@@ -1209,10 +1209,12 @@ getUncompressedData(MCAsmLayout &Layout,
 // Include the debug info compression header:
 // "ZLIB" followed by 8 bytes representing the uncompressed size of the section,
 // useful for consumers to preallocate a buffer to decompress into.
-static void
+static bool
 prependCompressionHeader(uint64_t Size,
                          SmallVectorImpl<char> &CompressedContents) {
   static const StringRef Magic = "ZLIB";
+  if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
+    return false;
   if (sys::IsLittleEndianHost)
     Size = sys::SwapByteOrder(Size);
   CompressedContents.insert(CompressedContents.begin(),
@@ -1221,6 +1223,7 @@ prependCompressionHeader(uint64_t Size,
   std::copy(reinterpret_cast<char *>(&Size),
             reinterpret_cast<char *>(&Size + 1),
             CompressedContents.begin() + Magic.size());
+  return true;
 }
 
 // Return a single fragment containing the compressed contents of the whole
@@ -1243,7 +1246,8 @@ getCompressedFragment(MCAsmLayout &Layou
   if (Success != zlib::StatusOK)
     return nullptr;
 
-  prependCompressionHeader(UncompressedData.size(), CompressedContents);
+  if (!prependCompressionHeader(UncompressedData.size(), CompressedContents))
+    return nullptr;
 
   return CompressedFragment;
 }

Modified: llvm/trunk/test/MC/ELF/compression.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/compression.s?rev=206659&r1=206658&r2=206659&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/compression.s (original)
+++ llvm/trunk/test/MC/ELF/compression.s Fri Apr 18 16:52:26 2014
@@ -1,6 +1,6 @@
 // RUN: llvm-mc -filetype=obj -compress-debug-sections -triple x86_64-pc-linux-gnu < %s -o %t
 // RUN: llvm-objdump -s %t | FileCheck %s
-// RUN: llvm-dwarfdump -debug-dump=abbrev %t | FileCheck --check-prefix=ABBREV %s
+// RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck --check-prefix=INFO %s
 // RUN: llvm-mc -filetype=obj -compress-debug-sections -triple i386-pc-linux-gnu < %s \
 // RUN:     | llvm-readobj -symbols - | FileCheck --check-prefix=386-SYMBOLS %s
 
@@ -12,8 +12,12 @@
 // CHECK-NOT: ZLIB
 // CHECK: Contents of
 
-// CHECK: Contents of section .zdebug_abbrev:
-// CHECK-NEXT: ZLIB
+// Don't compress small sections, such as this simple debug_abbrev example
+// CHECK: Contents of section .debug_abbrev:
+// CHECK-NOT: ZLIB
+// CHECK-NOT: Contents of
+
+// CHECK: Contents of section .debug_info:
 
 // FIXME: Handle compressing alignment fragments to support compressing debug_frame
 // CHECK: Contents of section .debug_frame:
@@ -21,8 +25,7 @@
 // CHECK: Contents of
 
 // Decompress one valid dwarf section just to check that this roundtrips
-// ABBREV: Abbrev table for offset: 0x00000000
-// ABBREV: [1] DW_TAG_compile_unit DW_CHILDREN_no
+// INFO: 0x00000000: Compile Unit: length = 0x0000000c version = 0x0004 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x00000010)
 
 // In x86 32 bit named symbols are used for temporary symbols in merge
 // sections, so make sure we handle symbols inside compressed sections
@@ -41,23 +44,37 @@
 	.byte	14                      # DW_FORM_strp
 	.byte	0                       # EOM(1)
 	.byte	0                       # EOM(2)
+
+	.section	.debug_info,"", at progbits
+	.long	12                      # Length of Unit
+	.short	4                       # DWARF version number
+	.long	.Lsection_abbrev        # Offset Into Abbrev. Section
+	.byte	8                       # Address Size (in bytes)
+	.byte	1                       # Abbrev [1] DW_TAG_compile_unit
+	.long	.Linfo_string0          # DW_AT_comp_dir
+
 	.text
 foo:
 	.cfi_startproc
 	.file 1 "Driver.ii"
+# pad out the line table to make sure it's big enough to warrant compression
 	.loc 1 2 0
         nop
+	.loc 1 3 0
+        nop
+	.loc 1 4 0
+        nop
+	.loc 1 5 0
+        nop
+	.loc 1 6 0
+        nop
+	.loc 1 7 0
+        nop
+	.loc 1 8 0
+        nop
 	.cfi_endproc
 	.cfi_sections .debug_frame
 
 	.section        .debug_str,"MS", at progbits,1
 .Linfo_string0:
-        .asciz  "foo"
-
-	.section	.debug_info,"", at progbits
-	.long	40                      # Length of Unit
-	.short	4                       # DWARF version number
-	.long	.Lsection_abbrev        # Offset Into Abbrev. Section
-	.byte	4                       # Address Size (in bytes)
-	.byte	1                       # Abbrev [1] DW_TAG_compile_unit
-	.long	.Linfo_string0          # DW_AT_comp_dir
+        .asciz  "compress this                                    "





More information about the llvm-commits mailing list