This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Only compress debug sections if this saves space
- From: Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>
- To: binutils at sourceware dot org
- Date: Fri, 10 May 2013 15:39:48 +0200
- Subject: Only compress debug sections if this saves space
The Solaris toolchain currently gains support for compressed debug
sections, both for the current GNU format and the new format already
approved for the ELF gABI. While working on gcc support starting at
http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00679.html
I noticed elfdump complaining about some of the object files with
compressed debug sections, e.g. the gas testcase:
% elfdump -c dw2-compress-1.o
[...]
Section Header[6]: sh_name: .zdebug_abbrev
sh_addr: 0 sh_flags: 0
sh_size: 0x46 sh_type: [ SHT_PROGBITS ]
sh_offset: 0x8b sh_entsize: 0
sh_link: 0 sh_info: 0
sh_addralign: 0x1
ch_size: 0x33 ch_type: ZLIB (GNU format)
dw2-compress-1.o.orig: .zdebug_abbrev: compressed section is larger than original: size 0x46: uncompressed size 0x33
[...]
The warning is correct and easy to fix, as shown by the following
patch. In the testcase above, only one out of three debug sections
shrinks when compressing. I've chosen to adapt the .d file to account
for this and didn't try to create a larger testcase where all debug
sections do compress.
Given that the testcase is from the gdb testsuite, that should be
adapted as well, but will need to account for both compressed and
uncompressed debug sections.
Ok for mainline?
Thanks.
Rainer
2013-05-10 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
gas:
* write.c (compress_debug): Only compress if it saves space.
gas/testsuite:
* gas/i386/dw2-compress-1.d: .debug_info and .debug_abbrev aren't
compressed.
# HG changeset patch
# Parent 39bc7ba94578e7d8c309a411b79f976a1529190d
Only compress debug sections if this saves space
diff --git a/gas/testsuite/gas/i386/dw2-compress-1.d b/gas/testsuite/gas/i386/dw2-compress-1.d
--- a/gas/testsuite/gas/i386/dw2-compress-1.d
+++ b/gas/testsuite/gas/i386/dw2-compress-1.d
@@ -2,7 +2,7 @@
#readelf: -w
#name: DWARF2 debugging information 1
-Contents of the .zdebug_info section:
+Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0x4e \(32-bit\)
@@ -31,7 +31,7 @@ Contents of the .zdebug_info section:
<50> DW_AT_encoding : 5 \(signed\)
<1><51>: Abbrev Number: 0
-Contents of the .zdebug_abbrev section:
+Contents of the .debug_abbrev section:
Number TAG \(0x0\)
1 DW_TAG_compile_unit \[has children\]
diff --git a/gas/write.c b/gas/write.c
--- a/gas/write.c
+++ b/gas/write.c
@@ -1521,6 +1521,11 @@ compress_debug (bfd *abfd, asection *sec
break;
}
+ /* Don't compress if it doesn't save space. */
+ uncompressed_size = (bfd_size_type) sec->size;
+ if (compressed_size >= uncompressed_size)
+ return;
+
/* Replace the uncompressed frag list with the compressed frag list. */
seginfo->frchainP->frch_root = first_newf;
seginfo->frchainP->frch_last = last_newf;
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University