PR ld/14207
authorAlan Modra <amodra@gmail.com>
Tue, 12 Jun 2012 06:31:06 +0000 (06:31 +0000)
committerAlan Modra <amodra@gmail.com>
Tue, 12 Jun 2012 06:31:06 +0000 (06:31 +0000)
* elf.c (_bfd_elf_map_sections_to_segments): Disregard bss type
sections at end of PT_LOAD segment when searching for segment
that contains end of relro extent.

bfd/ChangeLog
bfd/elf.c

index 220afe3a4fc0b168b2e101548d97ae75fd36a8b8..5c5c07c1b1c0d8f3c296fcd055a7bba18c9e4c75 100644 (file)
@@ -1,3 +1,10 @@
+2012-06-12  Alan Modra  <amodra@gmail.com>
+
+       PR ld/14207
+       * elf.c (_bfd_elf_map_sections_to_segments): Disregard bss type
+       sections at end of PT_LOAD segment when searching for segment
+       that contains end of relro extent.
+
 2012-06-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elf.c (assign_file_positions_for_non_load_sections): Reindent.
index 6de314bebd770f3184a6c3c1f519ac8acd8fe522..6755a4e3090242a3813c8813066151e6681a0be0 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4152,15 +4152,22 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
        {
          for (m = mfirst; m != NULL; m = m->next)
            {
-             if (m->p_type == PT_LOAD)
+             if (m->p_type == PT_LOAD
+                 && m->count != 0
+                 && m->sections[0]->vma >= info->relro_start
+                 && m->sections[0]->vma < info->relro_end)
                {
-                 asection *last = m->sections[m->count - 1];
-                 bfd_vma vaddr = m->sections[0]->vma;
-                 bfd_vma filesz = last->vma - vaddr + last->size;
+                 i = m->count;
+                 while (--i != (unsigned) -1)
+                   if ((m->sections[i]->flags & (SEC_LOAD | SEC_HAS_CONTENTS))
+                       == (SEC_LOAD | SEC_HAS_CONTENTS))
+                     break;
+
+                 if (i == (unsigned) -1)
+                   continue;
 
-                 if (vaddr < info->relro_end
-                     && vaddr >= info->relro_start
-                     && (vaddr + filesz) >= info->relro_end)
+                 if (m->sections[i]->vma + m->sections[i]->size
+                     >= info->relro_end)
                    break;
                }
            }