2007-01-30 H.J. Lu <hongjiu.lu@intel.com>
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 30 Jan 2007 15:47:19 +0000 (15:47 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 30 Jan 2007 15:47:19 +0000 (15:47 +0000)
* elf.c (copy_elf_program_header): Start from the first section
in a segment and stop when all sections in a segment are
accounted for.

bfd/ChangeLog
bfd/elf.c

index 07460d4..f8dcc99 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-30  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf.c (copy_elf_program_header): Start from the first section
+       in a segment and stop when all sections in a segment are
+       accounted for.
+
 2007-01-29  Julian Brown  <julian@codesourcery.com>
 
        * bfd-in2.h: Regenerate.
index faeb145..61e6103 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5814,7 +5814,7 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd)
       unsigned int section_count;
       bfd_size_type amt;
       Elf_Internal_Shdr *this_hdr;
-      bfd_vma first_lma = 0;
+      asection *first_section = NULL;
 
       /* FIXME: Do we need to copy PT_NULL segment?  */
       if (segment->p_type == PT_NULL)
@@ -5828,8 +5828,8 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd)
          this_hdr = &(elf_section_data(section)->this_hdr);
          if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment))
            {
-             if (!section_count || section->lma < first_lma)
-               first_lma = section->lma;
+             if (!first_section)
+               first_section = section;
              section_count++;
            }
        }
@@ -5875,19 +5875,24 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd)
 
       if (!map->includes_phdrs && !map->includes_filehdr)
        /* There is some other padding before the first section.  */
-       map->p_vaddr_offset = first_lma - segment->p_paddr;
+       map->p_vaddr_offset = ((first_section ? first_section->lma : 0)
+                              - segment->p_paddr);
       
       if (section_count != 0)
        {
          unsigned int isec = 0;
 
-         for (section = ibfd->sections;
+         for (section = first_section;
               section != NULL;
               section = section->next)
            {
              this_hdr = &(elf_section_data(section)->this_hdr);
              if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment))
-               map->sections[isec++] = section->output_section;
+               {
+                 map->sections[isec++] = section->output_section;
+                 if (isec == section_count)
+                   break;
+               }
            }
        }