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]

Fix PR ld/7028, valgrind complaint for ld-elf/header


The comment in the patch should say it all.  There's a
    BFD_ASSERT (elf_tdata (abfd)->program_header_size
		>= alloc * bed->s->sizeof_phdr);
above the patch that asserts that we with this change never
allocate never less than needed.  Fixes the problem with no
regressions on native i686-pc-linux-gnu and crosses to
cris-axis-linux-gnu and arm-unknown-linux-gnu.

Ok to commit?

bfd:
	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.

Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.467
diff -p -u -r1.467 elf.c
--- elf.c	10 Nov 2008 22:47:58 -0000	1.467
+++ elf.c	13 Nov 2008 02:16:27 -0000
@@ -4181,7 +4181,21 @@ assign_file_positions_for_load_sections 
       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;

brgds, H-P


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