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]

Fix crash in strip


This fixes a crash in strip.  The problem is that the PT_GNU_RELRO
segment only covers part of a single section, so its section mapping is
empty.

Andreas.

2008-11-07  Andreas Schwab  <schwab@suse.de>

	PR 7011
	* elf.c (assign_file_positions_for_non_load_sections): Handle
	PT_GNU_RELRO that covers only a part of a single section.

--- bfd/elf.c.~1.466.~	2008-10-09 11:07:35.000000000 +0200
+++ bfd/elf.c	2008-11-07 11:32:56.000000000 +0100
@@ -4631,7 +4631,9 @@ assign_file_positions_for_non_load_secti
        m != NULL;
        m = m->next, p++)
     {
-      if (m->count != 0)
+      if (m->count != 0
+	  /* Always handle PT_GNU_RELRO here if not linking.  */
+	  || (p->p_type == PT_GNU_RELRO && link_info == NULL))
 	{
 	  if (p->p_type != PT_LOAD
 	      && (p->p_type != PT_NOTE
@@ -4642,12 +4644,6 @@ assign_file_positions_for_non_load_secti
 
 	      BFD_ASSERT (!m->includes_filehdr && !m->includes_phdrs);
 
-	      sect = m->sections[m->count - 1];
-	      hdr = &elf_section_data (sect)->this_hdr;
-	      p->p_filesz = sect->filepos - m->sections[0]->filepos;
-	      if (hdr->sh_type != SHT_NOBITS)
-		p->p_filesz += hdr->sh_size;
-
 	      if (p->p_type == PT_GNU_RELRO)
 		{
 		  /* When we get here, we are copying executable
@@ -4680,7 +4676,14 @@ assign_file_positions_for_non_load_secti
 		    abort ();
 		}
 	      else
-		p->p_offset = m->sections[0]->filepos;
+		{
+		  sect = m->sections[m->count - 1];
+		  hdr = &elf_section_data (sect)->this_hdr;
+		  p->p_filesz = sect->filepos - m->sections[0]->filepos;
+		  if (hdr->sh_type != SHT_NOBITS)
+		    p->p_filesz += hdr->sh_size;
+		  p->p_offset = m->sections[0]->filepos;
+		}
 	    }
 	}
       else

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


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