OSDN Git Service

* elf.c (elf_modify_segment_map): Delete empty PT_LOAD segments.
authoramodra <amodra>
Wed, 26 Jul 2006 12:32:27 +0000 (12:32 +0000)
committeramodra <amodra>
Wed, 26 Jul 2006 12:32:27 +0000 (12:32 +0000)
* elf32-xtensa.c (elf_xtensa_modify_segment_map): Delete.
(define elf_backend_modify_segment_map): Don't define.

bfd/ChangeLog
bfd/elf.c
bfd/elf32-xtensa.c

index 3d76b52..c8400e7 100644 (file)
@@ -1,3 +1,9 @@
+2006-07-26  Alan Modra  <amodra@bigpond.net.au>
+
+       * elf.c (elf_modify_segment_map): Delete empty PT_LOAD segments.
+       * elf32-xtensa.c (elf_xtensa_modify_segment_map): Delete.
+       (define elf_backend_modify_segment_map): Don't define.
+
 2006-07-25  Thiemo Seufer  <ths@networkno.de>
 
        * elfxx-mips.c (_bfd_mips_elf_merge_private_bfd_data): Allow
index b900613..1db6239 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3736,41 +3736,41 @@ _bfd_elf_make_dynamic_segment (bfd *abfd, asection *dynsec)
 static bfd_boolean
 elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
 {
-  struct elf_segment_map *m;
+  struct elf_segment_map **m;
   const struct elf_backend_data *bed;
 
   /* The placement algorithm assumes that non allocated sections are
      not in PT_LOAD segments.  We ensure this here by removing such
      sections from the segment map.  We also remove excluded
-     sections.  */
-  for (m = elf_tdata (abfd)->segment_map;
-       m != NULL;
-       m = m->next)
+     sections.  Finally, any PT_LOAD segment without sections is
+     removed.  */
+  m = &elf_tdata (abfd)->segment_map;
+  while (*m)
     {
       unsigned int i, new_count;
 
-      new_count = 0;
-      for (i = 0; i < m->count; i ++)
+      for (new_count = 0, i = 0; i < (*m)->count; i++)
        {
-         if ((m->sections[i]->flags & SEC_EXCLUDE) == 0
-             && ((m->sections[i]->flags & SEC_ALLOC) != 0
-                 || m->p_type != PT_LOAD))
+         if (((*m)->sections[i]->flags & SEC_EXCLUDE) == 0
+             && (((*m)->sections[i]->flags & SEC_ALLOC) != 0
+                 || (*m)->p_type != PT_LOAD))
            {
-             if (i != new_count)
-               m->sections[new_count] = m->sections[i];
-
-             new_count ++;
+             (*m)->sections[new_count] = (*m)->sections[i];
+             new_count++;
            }
        }
+      (*m)->count = new_count;
 
-      if (new_count != m->count)
-       m->count = new_count;
+      if ((*m)->p_type == PT_LOAD && (*m)->count == 0)
+       *m = (*m)->next;
+      else
+       m = &(*m)->next;
     }
 
   bed = get_elf_backend_data (abfd);
   if (bed->elf_backend_modify_segment_map != NULL)
     {
-      if (! (*bed->elf_backend_modify_segment_map) (abfd, info))
+      if (!(*bed->elf_backend_modify_segment_map) (abfd, info))
        return FALSE;
     }
 
@@ -4379,7 +4379,8 @@ assign_file_positions_for_load_sections (bfd *abfd,
                 .tbss, we need to look at the next section to decide
                 whether the segment has any loadable sections.  */
              i = 0;
-             while ((m->sections[i]->flags & SEC_LOAD) == 0)
+             while ((m->sections[i]->flags & SEC_LOAD) == 0
+                    && (m->sections[i]->flags & SEC_HAS_CONTENTS) == 0)
                {
                  if ((m->sections[i]->flags & SEC_THREAD_LOCAL) == 0
                      || ++i >= m->count)
@@ -4548,7 +4549,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
            {
              if (p->p_type == PT_LOAD)
                {
-                 sec->filepos = off;
+                 sec->filepos = off + voff;
                  /* FIXME: The SEC_HAS_CONTENTS test here dates back to
                     1997, and the exact reason for it isn't clear.  One
                     plausible explanation is that it is to work around
@@ -4640,7 +4641,9 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
 
       hdr = *hdrpp;
       if (hdr->bfd_section != NULL
-         && hdr->bfd_section->filepos != 0)
+         && (hdr->bfd_section->filepos != 0
+             || (hdr->sh_type == SHT_NOBITS
+                 && hdr->contents == NULL)))
        hdr->sh_offset = hdr->bfd_section->filepos;
       else if ((hdr->sh_flags & SHF_ALLOC) != 0)
        {
index 542b3a4..5efdcba 100644 (file)
@@ -1525,31 +1525,6 @@ elf_xtensa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 }
 
 \f
-/* Remove any PT_LOAD segments with no allocated sections.  Prior to
-   binutils 2.13, this function used to remove the non-SEC_ALLOC
-   sections from PT_LOAD segments, but that task has now been moved
-   into elf.c.  We still need this function to remove any empty
-   segments that result, but there's nothing Xtensa-specific about
-   this and it probably ought to be moved into elf.c as well.  */
-
-static bfd_boolean
-elf_xtensa_modify_segment_map (bfd *abfd,
-                              struct bfd_link_info *info ATTRIBUTE_UNUSED)
-{
-  struct elf_segment_map **m_p;
-
-  m_p = &elf_tdata (abfd)->segment_map;
-  while (*m_p)
-    {
-      if ((*m_p)->p_type == PT_LOAD && (*m_p)->count == 0)
-       *m_p = (*m_p)->next;
-      else
-       m_p = &(*m_p)->next;
-    }
-  return TRUE;
-}
-
-\f
 /* Perform the specified relocation.  The instruction at (contents + address)
    is modified to set one operand to represent the value in "relocation".  The
    operand position is determined by the relocation type recorded in the
@@ -9823,7 +9798,6 @@ static const struct bfd_elf_special_section elf_xtensa_special_sections[] =
 #define elf_backend_grok_prstatus           elf_xtensa_grok_prstatus
 #define elf_backend_grok_psinfo                     elf_xtensa_grok_psinfo
 #define elf_backend_hide_symbol                     elf_xtensa_hide_symbol
-#define elf_backend_modify_segment_map      elf_xtensa_modify_segment_map
 #define elf_backend_object_p                elf_xtensa_object_p
 #define elf_backend_reloc_type_class        elf_xtensa_reloc_type_class
 #define elf_backend_relocate_section        elf_xtensa_relocate_section