Use bfd_putb64/bfd_getb64
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 6 Apr 2015 16:01:43 +0000 (09:01 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 6 Apr 2015 16:02:52 +0000 (09:02 -0700)
bfd/

* compress.c (get_uncompressed_size): Removed.
(bfd_compress_section_contents): Use bfd_putb64 to write
uncompressed section size.
(bfd_init_section_decompress_status): Replace
get_uncompressed_size with bfd_getb64.

gas/

* write.c (compress_debug): Use bfd_putb64 to write uncompressed
section size.

bfd/ChangeLog
bfd/compress.c
gas/ChangeLog
gas/write.c

index 4400a36b7bafad81465d7df7132fa9e2d16a1b3b..4291fc7da246d044a536adfae18e3df814a3a7aa 100644 (file)
@@ -1,3 +1,11 @@
+2015-04-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * compress.c (get_uncompressed_size): Removed.
+       (bfd_compress_section_contents): Use bfd_putb64 to write
+       uncompressed section size.
+       (bfd_init_section_decompress_status): Replace
+       get_uncompressed_size with bfd_getb64.
+
 2015-04-04  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elf.c (_bfd_elf_init_private_section_data): Also preserve the
index 56d49fe30b65686c515dd370f0e43b0b9bed9575..b57650faee19630c821628832230a6bf8f3a19fb 100644 (file)
@@ -59,27 +59,6 @@ decompress_contents (bfd_byte *compressed_buffer,
   return rc == Z_OK && strm.avail_out == 0;
 }
 
-static bfd_size_type
-get_uncompressed_size (bfd_byte *compressed_size_buffer)
-{
-  bfd_size_type uncompressed_size = compressed_size_buffer[0];
-  uncompressed_size <<= 8;
-  uncompressed_size += compressed_size_buffer[1];
-  uncompressed_size <<= 8;
-  uncompressed_size += compressed_size_buffer[2];
-  uncompressed_size <<= 8;
-  uncompressed_size += compressed_size_buffer[3];
-  uncompressed_size <<= 8;
-  uncompressed_size += compressed_size_buffer[4];
-  uncompressed_size <<= 8;
-  uncompressed_size += compressed_size_buffer[5];
-  uncompressed_size <<= 8;
-  uncompressed_size += compressed_size_buffer[6];
-  uncompressed_size <<= 8;
-  uncompressed_size += compressed_size_buffer[7];
-  return uncompressed_size;;
-}
-
 /* Compress data of the size specified in @var{uncompressed_size}
    and pointed to by @var{uncompressed_buffer} using zlib and store
    as the contents field.  This function assumes the contents
@@ -122,15 +101,7 @@ bfd_compress_section_contents (bfd *abfd ATTRIBUTE_UNUSED, sec_ptr sec,
       /* 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;
-
+      bfd_putb64 (uncompressed_size, compressed_buffer + 4);
       free (uncompressed_buffer);
       sec->contents = compressed_buffer;
       sec->size = compressed_size;
@@ -368,7 +339,7 @@ bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec)
       return FALSE;
     }
 
-  uncompressed_size = get_uncompressed_size (compressed_buffer + 4);
+  uncompressed_size = bfd_getb64 (compressed_buffer + 4);
   sec->compressed_size = sec->size;
   sec->size = uncompressed_size;
   sec->compress_status = DECOMPRESS_SECTION_SIZED;
index f2a1bf2258926b91e46160927910ec9074cc1cd1..c896dea09c843481b567c182a4733a5ba737a6e7 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * write.c (compress_debug): Use bfd_putb64 to write uncompressed
+       section size.
+
 2015-04-05  H.J. Lu  <hongjiu.lu@intel.com>
 
        * write.c (compress_debug): Don't write the zlib header if
index 248255b3b66e36999a11a737faa6803fa8205d8f..1ae47a900903bea1e8aa7e57e6181b4ecb7250c8 100644 (file)
@@ -1523,14 +1523,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
     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;
+  bfd_putb64 (uncompressed_size, header + 4);
 
   /* Replace the uncompressed frag list with the compressed frag list.  */
   seginfo->frchainP->frch_root = first_newf;