]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
backport 2008-11-13 Hans-Peter Nilsson <hp@axis.com>
authorAlan Modra <amodra@gmail.com>
Mon, 2 Mar 2009 13:40:15 +0000 (13:40 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 2 Mar 2009 13:40:15 +0000 (13:40 +0000)
bfd/ChangeLog
bfd/elf.c

index 66e1b2e44854fd8cb1ed82a226d4d0011818f8cd..d5b365a7b2b3c6f7c8b8c014d70002a09020c7a5 100644 (file)
@@ -1,5 +1,11 @@
 2009-03-02  Alan Modra  <amodra@bigpond.net.au>
 
+       2008-11-13  Hans-Peter Nilsson  <hp@axis.com>
+       PR ld/7028
+       * elf.c (assign_file_positions_for_load_sections): Allocate phrds
+       with bfd_zalloc2 instead of bfd_alloc2.  For the amount, use
+       the possibly-preset header-size, not the computed one.
+
        2008-11-13  Alan Modra  <amodra@bigpond.net.au>
        PR 7023
        * elf.c (bfd_section_from_shdr <SHT_SYMTAB>): Fail on invalid sh_info.
index cb7d2fc3e447b50da53ad3958cc6bd5d8a9968d0..3d52724010eb65bcbe90db4d6300c5ac87e6adcd 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4183,7 +4183,21 @@ assign_file_positions_for_load_sections (bfd *abfd,
       return TRUE;
     }
 
-  phdrs = bfd_alloc2 (abfd, alloc, sizeof (Elf_Internal_Phdr));
+  /* We're writing the size in elf_tdata (abfd)->program_header_size,
+     see assign_file_positions_except_relocs, so make sure we have
+     that amount allocated, with trailing space cleared.
+     The variable alloc contains the computed need, while elf_tdata
+     (abfd)->program_header_size contains the size used for the
+     layout.
+     See ld/emultempl/elf-generic.em:gld${EMULATION_NAME}_map_segments
+     where the layout is forced to according to a larger size in the
+     last iterations for the testcase ld-elf/header.  */
+  BFD_ASSERT (elf_tdata (abfd)->program_header_size % bed->s->sizeof_phdr
+             == 0);
+  phdrs = bfd_zalloc2 (abfd,
+                      (elf_tdata (abfd)->program_header_size
+                       / bed->s->sizeof_phdr),
+                      sizeof (Elf_Internal_Phdr));
   elf_tdata (abfd)->phdr = phdrs;
   if (phdrs == NULL)
     return FALSE;