PR ld/12451
authorNick Clifton <nickc@redhat.com>
Wed, 14 Dec 2011 11:50:13 +0000 (11:50 +0000)
committerNick Clifton <nickc@redhat.com>
Wed, 14 Dec 2011 11:50:13 +0000 (11:50 +0000)
* elfcode.h (elf_checksum_contents): Read in the section's
contents if they are not already available.
* compress.c (bfd_get_full_section_contents): Use zmalloc to
allocate the buffers so that excess bytes are guaranteed to be
zero.

bfd/ChangeLog
bfd/compress.c
bfd/elfcode.h

index 164f23190c674ce630b80fac422e4061944c9024..96ab8798d12a54ac4bbd913741f8364c067e442b 100644 (file)
@@ -1,3 +1,12 @@
+2011-12-14  Nick Clifton  <nickc@redhat.com>
+
+       PR ld/12451
+       * elfcode.h (elf_checksum_contents): Read in the section's
+       contents if they are not already available.
+       * compress.c (bfd_get_full_section_contents): Use zmalloc to
+       allocate the buffers so that excess bytes are guaranteed to be
+       zero.
+
 2011-12-14  Iain Sandoe  <iains@gcc.gnu.org>
 
        * mach-o-i386.c (text_section_names_xlat): New table.
index a82a8bc9e3cb205ef6b881fc73b91ff1eda8709d..713e30adc3fe019b6b4bc6e441c8f89ee203efe6 100644 (file)
@@ -181,7 +181,7 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
     case COMPRESS_SECTION_NONE:
       if (p == NULL)
        {
-         p = (bfd_byte *) bfd_malloc (sz);
+         p = (bfd_byte *) bfd_zmalloc (sz);
          if (p == NULL)
            return FALSE;
        }
@@ -221,7 +221,7 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr)
       if (!ret)
        goto fail_compressed;
 
-      uncompressed_buffer = (bfd_byte *) bfd_malloc (uncompressed_size);
+      uncompressed_buffer = (bfd_byte *) bfd_zmalloc (uncompressed_size);
       if (uncompressed_buffer == NULL)
        goto fail_compressed;
 
index b7e022614ca59648f0c8e941a9fc0a7789f53674..f5727feda442bb0f8cc690706ea990303ae73908 100644 (file)
@@ -1097,8 +1097,28 @@ elf_checksum_contents (bfd *abfd,
       elf_swap_shdr_out (abfd, &i_shdr, &x_shdr);
       (*process) (&x_shdr, sizeof x_shdr, arg);
 
+      /* PR ld/12451:
+        Process the section's contents; reading them in if necessary.  */
       if (i_shdr.contents)
        (*process) (i_shdr.contents, i_shdr.sh_size, arg);
+      else
+       {
+         asection *sec;
+
+         sec = bfd_section_from_elf_index (abfd, count);
+         if (sec != NULL)
+           {
+             if (sec->contents == NULL)
+               {
+                 /* Force rereading from file.  */
+                 sec->flags &= ~SEC_IN_MEMORY;
+                 if (! bfd_malloc_and_get_section (abfd, sec, & sec->contents))
+                   continue;
+               }
+             if (sec->contents != NULL)
+               (*process) (sec->contents, i_shdr.sh_size, arg);
+           }
+       }
     }
 
   return TRUE;