This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
rewrite_elf_program_header and lma changes
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sourceware dot org
- Date: Fri, 1 Aug 2008 16:09:01 +0930
- Subject: rewrite_elf_program_header and lma changes
objcopy allows section lma changes which can result in elf headers
being trashed. This patch cures one source of error.
bfd/
* elf.c (rewrite_elf_program_header): Don't wrap p_paddr to
include file or program headers.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.459
diff -u -p -r1.459 elf.c
--- bfd/elf.c 30 Jul 2008 04:34:56 -0000 1.459
+++ bfd/elf.c 1 Aug 2008 06:19:51 -0000
@@ -5559,19 +5559,32 @@ rewrite_elf_program_header (bfd *ibfd, b
/* Offset the segment physical address from the lma
to allow for space taken up by elf headers. */
if (map->includes_filehdr)
- map->p_paddr -= iehdr->e_ehsize;
+ {
+ if (map->p_paddr >= iehdr->e_ehsize)
+ map->p_paddr -= iehdr->e_ehsize;
+ else
+ {
+ map->includes_filehdr = FALSE;
+ map->includes_phdrs = FALSE;
+ }
+ }
if (map->includes_phdrs)
{
- map->p_paddr -= iehdr->e_phnum * iehdr->e_phentsize;
+ if (map->p_paddr >= iehdr->e_phnum * iehdr->e_phentsize)
+ {
+ map->p_paddr -= iehdr->e_phnum * iehdr->e_phentsize;
- /* iehdr->e_phnum is just an estimate of the number
- of program headers that we will need. Make a note
- here of the number we used and the segment we chose
- to hold these headers, so that we can adjust the
- offset when we know the correct value. */
- phdr_adjust_num = iehdr->e_phnum;
- phdr_adjust_seg = map;
+ /* iehdr->e_phnum is just an estimate of the number
+ of program headers that we will need. Make a note
+ here of the number we used and the segment we chose
+ to hold these headers, so that we can adjust the
+ offset when we know the correct value. */
+ phdr_adjust_num = iehdr->e_phnum;
+ phdr_adjust_seg = map;
+ }
+ else
+ map->includes_phdrs = FALSE;
}
}
--
Alan Modra
Australia Development Lab, IBM