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]

[committed, 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.  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.
+
 2015-03-24  Nick Clifton  <nickc@redhat.com>
 
 	PR binutils/17512
diff --git a/bfd/compress.c b/bfd/compress.c
index de74d60..993a1d3 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -96,26 +96,34 @@ bfd_compress_section_contents (bfd *abfd ATTRIBUTE_UNUSED,
       return FALSE;
     }
 
-  /* Write the zlib header.  In this case, it should be "ZLIB" followed
-     by the uncompressed section size, 8 bytes in big-endian order.  */
-  memcpy (compressed_buffer, "ZLIB", 4);
-  compressed_buffer[11] = uncompressed_size; uncompressed_size >>= 8;
-  compressed_buffer[10] = uncompressed_size; uncompressed_size >>= 8;
-  compressed_buffer[9] = uncompressed_size; uncompressed_size >>= 8;
-  compressed_buffer[8] = uncompressed_size; uncompressed_size >>= 8;
-  compressed_buffer[7] = uncompressed_size; uncompressed_size >>= 8;
-  compressed_buffer[6] = uncompressed_size; uncompressed_size >>= 8;
-  compressed_buffer[5] = uncompressed_size; uncompressed_size >>= 8;
-  compressed_buffer[4] = uncompressed_size;
   compressed_size += 12;
 
-  /* Free the uncompressed contents if we compress in place.  */
-  if (uncompressed_buffer == sec->contents)
-    free (uncompressed_buffer);
-
-  sec->contents = compressed_buffer;
-  sec->size = compressed_size;
-  sec->compress_status = COMPRESS_SECTION_DONE;
+  /* PR binutils/18087: If compression didn't make the section smaller,
+     just keep it uncompressed.  */
+  if (compressed_size < uncompressed_size)
+    {
+      /* Write the zlib header.  In this case, it should be "ZLIB" followed
+	 by the uncompressed section size, 8 bytes in big-endian order.  */
+      memcpy (compressed_buffer, "ZLIB", 4);
+      compressed_buffer[11] = uncompressed_size; uncompressed_size >>= 8;
+      compressed_buffer[10] = uncompressed_size; uncompressed_size >>= 8;
+      compressed_buffer[9] = uncompressed_size; uncompressed_size >>= 8;
+      compressed_buffer[8] = uncompressed_size; uncompressed_size >>= 8;
+      compressed_buffer[7] = uncompressed_size; uncompressed_size >>= 8;
+      compressed_buffer[6] = uncompressed_size; uncompressed_size >>= 8;
+      compressed_buffer[5] = uncompressed_size; uncompressed_size >>= 8;
+      compressed_buffer[4] = uncompressed_size;
+
+      free (uncompressed_buffer);
+      sec->contents = compressed_buffer;
+      sec->size = compressed_size;
+      sec->compress_status = COMPRESS_SECTION_DONE;
+    }
+  else
+    {
+      sec->contents = uncompressed_buffer;
+      sec->compress_status = COMPRESS_SECTION_NONE;
+    }
 
   return TRUE;
 }
@@ -424,18 +432,6 @@ bfd_init_section_compress_status (bfd *abfd ATTRIBUTE_UNUSED,
 					 uncompressed_buffer,
 					 uncompressed_size);
 
-  /* PR binutils/18087: If compression didn't make
-     the section smaller, just keep it uncompressed.  */
-  if (ret && uncompressed_size < sec->size)
-    {
-      free (sec->contents);
-      sec->contents = uncompressed_buffer;
-      sec->size = uncompressed_size;
-      sec->compress_status = COMPRESS_SECTION_NONE;
-    }
-  else
-    free (uncompressed_buffer);
-
   return ret;
 #endif
 }
-- 
1.9.3


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