This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR ld/16322: ld fails to generate GNU_RELRO segment


On Thu, Jan 09, 2014 at 09:07:43AM -0800, H.J. Lu wrote:
> It is OK to have another PT_LOAD segment.

Not when the second PT_LOAD segment is also in relro area.

But let's leave that aside for the moment.  Why is it necessary to
adjust the PT_LOAD segment in assign_file_positions_for_load_sections?
It seems to me this is quite bogus.  The end of the loaded part or the
alloced part of the PT_LOAD segment really has nothing to do with the
PT_GNU_RELRO segment end.

I think what we should do instead is fix Jakub's original code setting
up the PR_GNU_RELRO segment from the PT_LOAD segment..  I'm testing
the following along with the ldlang.c changes.

bfd/
	PR ld/14207
	PR ld/16322
	PR binutils/16323
	* elf.c (assign_file_positions_for_load_sections): Revert last change.
	(assign_file_positions_for_non_load_sections): When setting up
	PT_GNU_RELRO header, don't require a corresponding PT_LOAD
	header that completely covers the relro region.
ld/testsuite/
	* ld-x86-64/pr14207.d: Adjust.

diff --git a/bfd/elf.c b/bfd/elf.c
index 870e281..3815e32 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4376,7 +4376,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
   unsigned int alloc;
   unsigned int i, j;
   bfd_vma header_pad = 0;
-  bfd_vma relro_start = 0, relro_end = 0;
 
   if (link_info == NULL
       && !_bfd_elf_map_sections_to_segments (abfd, link_info))
@@ -4447,23 +4446,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
     header_pad -= off;
   off += header_pad;
 
-  /* Get start and end of PT_GNU_RELRO segment.  */
-  if (link_info != NULL)
-    {
-      relro_start = link_info->relro_start;
-      relro_end = link_info->relro_end;
-    }
-  else
-    {
-      for (m = elf_seg_map (abfd); m != NULL; m = m->next)
-	if (m->p_type == PT_GNU_RELRO)
-	  {
-	    relro_start = m->p_paddr;
-	    relro_end = relro_start + m->p_size;
-	    break;
-	  }
-    }
-
   for (m = elf_seg_map (abfd), p = phdrs, j = 0;
        m != NULL;
        m = m->next, p++, j++)
@@ -4807,22 +4789,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
 	    }
 	}
 
-      if (relro_start != 0
-	  && p->p_type == PT_LOAD
-	  && p->p_vaddr >= relro_start)
-	{
-	  /* If PT_LOAD segment doesn't fit PT_GNU_RELRO segment,
-	     adjust its p_filesz and p_memsz.  */
-	  if (p->p_vaddr + p->p_filesz < relro_end)
-	    {
-	      bfd_vma adjust = relro_end - (p->p_vaddr + p->p_filesz);
-	      p->p_filesz += adjust;
-	      off += adjust;
-	    }
-	  if (p->p_vaddr + p->p_memsz < relro_end)
-	    p->p_memsz += relro_end - (p->p_vaddr + p->p_memsz);
-	}
-
       off -= off_adjust;
 
       /* Check that all sections are in a PT_LOAD segment.
@@ -5024,14 +4990,11 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
 		{
 		  if (lp->p_type == PT_LOAD
 		      && lp->p_vaddr < link_info->relro_end
-		      && lp->p_vaddr + lp->p_filesz >= link_info->relro_end
 		      && lm->count != 0
 		      && lm->sections[0]->vma >= link_info->relro_start)
 		    break;
 		}
 
-	      /* PR ld/14207.  If the RELRO segment doesn't fit in the
-		 LOAD segment, it should be removed.  */
 	      BFD_ASSERT (lm != NULL);
 	    }
 	  else
diff --git a/ld/testsuite/ld-x86-64/pr14207.d b/ld/testsuite/ld-x86-64/pr14207.d
index b1e2d5a..d4e22a1 100644
--- a/ld/testsuite/ld-x86-64/pr14207.d
+++ b/ld/testsuite/ld-x86-64/pr14207.d
@@ -11,7 +11,7 @@ There are 4 program headers, starting at offset 64
 Program Headers:
   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
   LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x0001e0 0x0001e0 R   0x200000
-  LOAD           0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b8 0x000cf8 RW  0x200000
+  LOAD           0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b0 0x000cf8 RW  0x200000
   DYNAMIC        0x000b90 0x0000000000200b90 0x0000000000200b90 0x0001c0 0x0001c0 RW  0x8
   GNU_RELRO      0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b8 0x0004b8 R   0x1
 

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]