This is the mail archive of the
mailing list for the binutils project.
Re: [PATCH] Fix uninitialized elf_segment_map fields in rewrite_elf_program_header
- From: Joe Seymour <jseymour at codesourcery dot com>
- To: <binutils at sourceware dot org>
- Date: Tue, 13 Nov 2012 20:23:32 +0000
- Subject: Re: [PATCH] Fix uninitialized elf_segment_map fields in rewrite_elf_program_header
- References: <50A2AA10.firstname.lastname@example.org>
On 11/13/12 20:14, Joe Seymour wrote:
> When using objcopy to adjust section LMA's, via --change-section-lma, I'm
> observing errors of the form "<section name> can't be allocated in segment <number>"
> This happens because elf_segment_map structure allocated in
> rewrite_elf_program_header isn't fully initialized (valgrind provides copious
> amounts of output as evidence of this). In this case p_vaddr_offset having a
> garbage value is the problem, however there are some other fields not obviously
> Elsewhere in rewrite_elf_program_header bfd_zalloc is used, instead of
> bfd_alloc. Therefore this patch seems appropriate. The structure definition
> elf/internal.h supports this assessment:
> - The values of p_align and p_size are irrelevant as p_align_valid and
> p_size_valid will both be zero.
> - The surrounding code sets both includes_filehdr and includes_phdrs to zero, so
> header_size should be irrelevant.
> - No sections have been added to the segment yet so having zero count is
> appropriate, and sections is irrelevant. By the same logic it is appropriate
> that p_vaddr_offset be zero, as it records the difference between the segment
> vma and that for its first section.
> Unfortunately the port I'm seeing this on isn't upstream, and I haven't managed
> to observe it for other targets. Hopefully this is trivial/obvious enough to be OK?
> As I don't have commit access perhaps someone could commit for me, if this is
> 2012-11-13 Joe Seymour <email@example.com>
> * elf.c (rewrite_elf_program_header): Allocate elf_segment_map with
> bfd_zalloc, instead of bfd_alloc.
Sorry, that patch was against an old binutils. Here's one against HEAD:
2012-11-13 Joe Seymour <firstname.lastname@example.org>
* elf.c (rewrite_elf_program_header): Allocate elf_segment_map with
bfd_zalloc, instead of bfd_alloc.
diff --git a/bfd/elf.c b/bfd/elf.c
index f40e81b..b8bb6d3 100644
@@ -6043,7 +6043,7 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
and carry on looping. */
amt = sizeof (struct elf_segment_map);
amt += ((bfd_size_type) section_count - 1) * sizeof (asection *);
- map = (struct elf_segment_map *) bfd_alloc (obfd, amt);
+ map = (struct elf_segment_map *) bfd_zalloc (obfd, amt);
if (map == NULL)