]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
backport 2008-11-14 Nathan Sidwell <nathan@codesourcery.com>
authorAlan Modra <amodra@gmail.com>
Mon, 2 Mar 2009 13:41:07 +0000 (13:41 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 2 Mar 2009 13:41:07 +0000 (13:41 +0000)
bfd/ChangeLog
bfd/elf.c
include/elf/ChangeLog
include/elf/internal.h

index d5b365a7b2b3c6f7c8b8c014d70002a09020c7a5..268a48269751815fbfbb81d632efbd04cfd047f3 100644 (file)
@@ -1,5 +1,11 @@
 2009-03-02  Alan Modra  <amodra@bigpond.net.au>
 
+       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-13  Hans-Peter Nilsson  <hp@axis.com>
        PR ld/7028
        * elf.c (assign_file_positions_for_load_sections): Allocate phrds
index 3d52724010eb65bcbe90db4d6300c5ac87e6adcd..4525faab3b404623a7241785400caca31cc54d28 100644 (file)
--- 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)
index ba5645fbafa75b77c948aaf6833c2ac135be0ba3..cb21b49dcd047040b7c2ef80547bcdd85bf08dc8 100644 (file)
@@ -1,5 +1,8 @@
 2009-03-02  Alan Modra  <amodra@bigpond.net.au>
 
+       2008-11-14  Nathan Sidwell  <nathan@codesourcery.com>
+       * internal.h (struct elf_segment_map): Add header_size field.
        2008-10-10  Nathan Froyd  <froydnj@codesourcery.com>
        * ppc.h: Add Tag_GNU_Power_ABI_Struct_Return.
 
index 513f6763c82a299399dd7ef798f932d103e10d42..9ea175c9de05255353e29a12ec5bc820371dd11d 100644 (file)
@@ -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;