aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2008-11-14 14:44:09 +0000
committerNick Clifton <nickc@redhat.com>2008-11-14 14:44:09 +0000
commit2b0bc0884c18624ca338cc984cff5f0a0c0ca9cd (patch)
treee818e0cb8aa9f6c1a34211e4c9b5f52047d7bdbe
parent4bc251014580513b8b4e3e4a5d1547ca2442644e (diff)
downloadgdb-2b0bc0884c18624ca338cc984cff5f0a0c0ca9cd.zip
gdb-2b0bc0884c18624ca338cc984cff5f0a0c0ca9cd.tar.gz
gdb-2b0bc0884c18624ca338cc984cff5f0a0c0ca9cd.tar.bz2
bfd/
* elf.c (assign_file_positions_for_load_sections): Use header_size to avoid moving the load address of file headers. (assign_file_positions_for_load_sections): Set header_size for segments containing the file header. include/elf/ * internal.h (struct elf_segment_map): Add header_size field.
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/elf.c21
-rw-r--r--include/elf/ChangeLog4
-rw-r--r--include/elf/internal.h2
4 files changed, 33 insertions, 1 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 60f7718..4535bfe 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2008-11-14 Nathan Sidwell <nathan@codesourcery.com>
+
+ * elf.c (assign_file_positions_for_load_sections): Use header_size
+ to avoid moving the load address of file headers.
+ (assign_file_positions_for_load_sections): Set header_size for
+ segments containing the file header.
+
2008-11-14 Tristan Gingold <gingold@adacore.com>
* configure.com: Handle bfd_default_target_size, BFD_HOST_LONG_LONG,
diff --git a/bfd/elf.c b/bfd/elf.c
index 3d52724..4525faa 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4158,6 +4158,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
bfd_size_type maxpagesize;
unsigned int alloc;
unsigned int i, j;
+ bfd_vma header_pad = 0;
if (link_info == NULL
&& !_bfd_elf_map_sections_to_segments (abfd, link_info))
@@ -4165,7 +4166,11 @@ assign_file_positions_for_load_sections (bfd *abfd,
alloc = 0;
for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
- ++alloc;
+ {
+ ++alloc;
+ if (m->header_size)
+ header_pad = m->header_size;
+ }
elf_elfheader (abfd)->e_phoff = bed->s->sizeof_ehdr;
elf_elfheader (abfd)->e_phentsize = bed->s->sizeof_phdr;
@@ -4208,6 +4213,11 @@ assign_file_positions_for_load_sections (bfd *abfd,
off = bed->s->sizeof_ehdr;
off += alloc * bed->s->sizeof_phdr;
+ if (header_pad < (bfd_vma) off)
+ header_pad = 0;
+ else
+ header_pad -= off;
+ off += header_pad;
for (m = elf_tdata (abfd)->segment_map, p = phdrs, j = 0;
m != NULL;
@@ -4395,6 +4405,11 @@ assign_file_positions_for_load_sections (bfd *abfd,
p->p_filesz += alloc * bed->s->sizeof_phdr;
p->p_memsz += alloc * bed->s->sizeof_phdr;
+ if (m->count)
+ {
+ p->p_filesz += header_pad;
+ p->p_memsz += header_pad;
+ }
}
if (p->p_type == PT_LOAD
@@ -5877,6 +5892,10 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd)
phdr_included = TRUE;
}
+ if (map->includes_filehdr && first_section)
+ /* We need to keep the space used by the headers fixed. */
+ map->header_size = first_section->vma - segment->p_vaddr;
+
if (!map->includes_phdrs
&& !map->includes_filehdr
&& map->p_paddr_valid)
diff --git a/include/elf/ChangeLog b/include/elf/ChangeLog
index 2699b03..3cfc24f 100644
--- a/include/elf/ChangeLog
+++ b/include/elf/ChangeLog
@@ -1,3 +1,7 @@
+2008-11-14 Nathan Sidwell <nathan@codesourcery.com>
+
+ * internal.h (struct elf_segment_map): Add header_size field.
+
2008-10-13 Ulrich Weigand <uweigand@de.ibm.com>
* common.h (AT_BASE_PLATFORM, AT_EXECFN): Define.
diff --git a/include/elf/internal.h b/include/elf/internal.h
index 513f676..9ea175c 100644
--- a/include/elf/internal.h
+++ b/include/elf/internal.h
@@ -266,6 +266,8 @@ struct elf_segment_map
bfd_vma p_align;
/* Segment size in file and memory */
bfd_vma p_size;
+ /* Required size of filehdr + phdrs, if non-zero */
+ bfd_vma header_size;
/* Whether the p_flags field is valid; if not, the flags are based
on the section flags. */
unsigned int p_flags_valid : 1;