This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [committed, PATCH] Don't write the zlib header if not used


On Tue, Mar 24, 2015 at 1:30 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> No need to write the zlib header if compression didn't make the section
> smaller.  I checked this into master.
>
>
> H.J.
> ---
>         PR binutils/18087
>         * compress.c (bfd_compress_section_contents): Don't write the
>         zlib header and set contents as well as compress_status if
>         compression didn't make the section smaller.
>         (bfd_init_section_compress_status): Don't check compression
>         size here.
> ---
>  bfd/ChangeLog  |  9 +++++++++
>  bfd/compress.c | 56 ++++++++++++++++++++++++++------------------------------
>  2 files changed, 35 insertions(+), 30 deletions(-)
>
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index 73c155c..469066b 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,3 +1,12 @@
> +2015-03-24  H.J. Lu  <hongjiu.lu@intel.com>
> +
> +       PR gas/18087
> +       * compress.c (bfd_compress_section_contents): Don't write the
> +       zlib header and set contents as well as compress_status if
> +       compression didn't make the section smaller.
> +       (bfd_init_section_compress_status): Don't check compression
> +       size here.
> +

I also committed a similar patch for gas.


-- 
H.J.
From b422eb499be2858969fb7723b4e4e08cab20fcdc Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 24 Mar 2015 19:06:22 -0700
Subject: [PATCH] Don't write the zlib header if not used

No need to write the zlib header if compression didn't make the section
smaller.

	PR gas/18087
	* write.c (compress_debug): Don't write the zlib header if
	compression didn't make the section smaller.
---
 gas/ChangeLog |  6 ++++++
 gas/write.c   | 25 +++++++++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 6579c2f..9f92729 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gas/18087
+	* write.c (compress_debug): Don't write the zlib header if
+	compression didn't make the section smaller.
+
 2015-03-24  Terry Guo  <terry.guo@arm.com>
 
 	* config/tc-arm.c (no_cpu_selected): Use new macro to compare
diff --git a/gas/write.c b/gas/write.c
index 397ea48..6a781ea 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -1438,15 +1438,6 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
   last_newf->fr_type = rs_fill;
   last_newf->fr_fix = 12;
   header = last_newf->fr_literal;
-  memcpy (header, "ZLIB", 4);
-  header[11] = uncompressed_size; uncompressed_size >>= 8;
-  header[10] = uncompressed_size; uncompressed_size >>= 8;
-  header[9] = uncompressed_size; uncompressed_size >>= 8;
-  header[8] = uncompressed_size; uncompressed_size >>= 8;
-  header[7] = uncompressed_size; uncompressed_size >>= 8;
-  header[6] = uncompressed_size; uncompressed_size >>= 8;
-  header[5] = uncompressed_size; uncompressed_size >>= 8;
-  header[4] = uncompressed_size;
   compressed_size = 12;
 
   /* Stream the frags through the compression engine, adding new frags
@@ -1526,11 +1517,21 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
 	break;
     }
 
-  /* PR binutils/18087: If compression didn't make
-     the section smaller, just keep it uncompressed.  */
-  if (compressed_size > sec->size)
+  /* PR binutils/18087: If compression didn't make the section smaller,
+     just keep it uncompressed.  */
+  if (compressed_size > uncompressed_size)
     return;
 
+  memcpy (header, "ZLIB", 4);
+  header[11] = uncompressed_size; uncompressed_size >>= 8;
+  header[10] = uncompressed_size; uncompressed_size >>= 8;
+  header[9] = uncompressed_size; uncompressed_size >>= 8;
+  header[8] = uncompressed_size; uncompressed_size >>= 8;
+  header[7] = uncompressed_size; uncompressed_size >>= 8;
+  header[6] = uncompressed_size; uncompressed_size >>= 8;
+  header[5] = uncompressed_size; uncompressed_size >>= 8;
+  header[4] = uncompressed_size;
+
   /* Replace the uncompressed frag list with the compressed frag list.  */
   seginfo->frchainP->frch_root = first_newf;
   seginfo->frchainP->frch_last = last_newf;
-- 
2.1.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]