summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@bigpond.net.au>2008-08-01 06:39:04 +0000
committerAlan Modra <amodra@bigpond.net.au>2008-08-01 06:39:04 +0000
commit85ac20d14d44b9203c6b4150c25e0f8a5016af58 (patch)
treeb872fa0b5a7d66d0a5255884dc412c3a6a22e8e3
parent80d404690aecf894f61460b4ad76a30392fd7af7 (diff)
downloadbinutils-redhat-85ac20d14d44b9203c6b4150c25e0f8a5016af58.tar.gz
* elf.c (rewrite_elf_program_header): Don't wrap p_paddr to
include file or program headers.
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/elf.c33
2 files changed, 28 insertions, 10 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 6f2c8824f2..30b06335db 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2008-08-01 Alan Modra <amodra@bigpond.net.au>
+
+ * elf.c (rewrite_elf_program_header): Don't wrap p_paddr to
+ include file or program headers.
+
2008-07-30 Alan Modra <amodra@bigpond.net.au>
* coff-ppc.c, coffgen.c, ecoff.c, ecofflink.c, elf.c, elf32-frv.c,
diff --git a/bfd/elf.c b/bfd/elf.c
index c1517ba8b7..6b67e16fd4 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5559,19 +5559,32 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
/* 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;
-
- /* 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;
+ 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;
+ }
+ else
+ map->includes_phdrs = FALSE;
}
}