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 bfd/14207: linker can produce a NULL GNU_RELRO segment


On Mon, Jun 11, 2012 at 10:26:39AM -0700, H.J. Lu wrote:
> The real bug is in _bfd_elf_map_sections_to_segments.  It

Agreed.

> 	* elf.c (_bfd_elf_map_sections_to_segments): Properly compute
> 	file size for PT_GNU_RELRO segment.

While I think this part of your patch is correct, it is doing quite a
lot of unnecessary work.  How about this instead?

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.558
diff -u -p -r1.558 elf.c
--- bfd/elf.c	4 Jun 2012 14:35:21 -0000	1.558
+++ bfd/elf.c	12 Jun 2012 01:46:19 -0000
@@ -4152,18 +4152,25 @@ _bfd_elf_map_sections_to_segments (bfd *
 	{
 	  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;
-
-		  if (vaddr < info->relro_end
-		      && vaddr >= info->relro_start
-		      && (vaddr + filesz) >= info->relro_end)
+		  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 (m->sections[i]->vma + m->sections[i]->size
+		      >= info->relro_end)
 		    break;
 		}
-	      }
+	    }
 
 	  /* Make a PT_GNU_RELRO segment only when it isn't empty.  */
 	  if (m != NULL)

-- 
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]