]> Git Repo - binutils.git/blobdiff - bfd/bfd.c
Don't add the zlib header to SHF_COMPRESSED section
[binutils.git] / bfd / bfd.c
index ba78cf34a93f2b1ed3df60a1b1c4960bc1b58b26..ab410cb0bd6e93bb405275414f15e5408d1bcdab 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -212,6 +212,9 @@ CODE_FRAGMENT
 .  {* Set if this is the linker output BFD.  *}
 .  unsigned int is_linker_output : 1;
 .
+.  {* Set if this is the linker input BFD.  *}
+.  unsigned int is_linker_input : 1;
+.
 .  {* If this is an input for a compiler plug-in library.  *}
 .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
 .
@@ -1995,8 +1998,16 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
                }
            }
          else
-           /* Clear the SHF_COMPRESSED bit.  */
-           elf_section_flags (sec) &= ~SHF_COMPRESSED;
+           {
+             /* Clear the SHF_COMPRESSED bit.  */
+             elf_section_flags (sec) &= ~SHF_COMPRESSED;
+
+             /* Write the zlib header.  It should be "ZLIB" followed by
+                the uncompressed section size, 8 bytes in big-endian
+                order.  */
+             memcpy (contents, "ZLIB", 4);
+             bfd_putb64 (sec->size, contents + 4);
+           }
        }
     }
   else
@@ -2010,11 +2021,12 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
    SYNOPSIS
        bfd_boolean bfd_check_compression_header
          (bfd *abfd, bfd_byte *contents, asection *sec,
-          bfd_size_type uncompressed_size);
+         bfd_size_type *uncompressed_size);
 
 DESCRIPTION
-       Check the compression header at CONTENTS of SEC in ABFD with
-       the uncompressed size UNCOMPRESSED_SIZE.
+       Check the compression header at CONTENTS of SEC in ABFD and
+       store the uncompressed size in UNCOMPRESSED_SIZE if the
+       compression header is valid.
 
 RETURNS
        Return TRUE if the compression header is valid.
@@ -2023,7 +2035,7 @@ RETURNS
 bfd_boolean
 bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
                              asection *sec,
-                             bfd_size_type uncompressed_size)
+                             bfd_size_type *uncompressed_size)
 {
   if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
       && (elf_section_flags (sec) & SHF_COMPRESSED) != 0)
@@ -2044,9 +2056,12 @@ bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
          chdr.ch_size = bfd_get_64 (abfd, &echdr->ch_size);
          chdr.ch_addralign = bfd_get_64 (abfd, &echdr->ch_addralign);
        }
-      return (chdr.ch_type == ELFCOMPRESS_ZLIB
-             && chdr.ch_size == uncompressed_size
-             && chdr.ch_addralign == 1U << sec->alignment_power);
+      if (chdr.ch_type == ELFCOMPRESS_ZLIB
+         && chdr.ch_addralign == 1U << sec->alignment_power)
+       {
+         *uncompressed_size = chdr.ch_size;
+         return TRUE;
+       }
     }
 
   return FALSE;
This page took 0.025415 seconds and 4 git commands to generate.