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: segfault in bfd with large static binary


Hi Mike,

i was building statically the latest busybox binary on amd64 and when i went to strip it, strip segfaulted on me

normally i use binutils 2.16.1, but i found 2.16.91.0.5 and the 060131 snapshot bombed out the same way

This is a bad assumption in assign_file_positions_for_segments() which believes that it will always be passed a non-NULL link_info pointer. Please could you try the attached patch which should fix the problem.


Cheers
  Nick
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.325
diff -c -3 -p -r1.325 elf.c
*** bfd/elf.c	17 Jan 2006 11:09:56 -0000	1.325
--- bfd/elf.c	1 Feb 2006 11:37:26 -0000
*************** assign_file_positions_for_segments (bfd 
*** 4494,4519 ****
  	    {
  	      Elf_Internal_Phdr *lp;
  
! 	      for (lp = phdrs; lp < phdrs + count; ++lp)
  		{
! 		  if (lp->p_type == PT_LOAD
! 		      && lp->p_vaddr <= link_info->relro_end
! 		      && lp->p_vaddr >= link_info->relro_start
! 		      && lp->p_vaddr + lp->p_filesz
! 			 >= link_info->relro_end)
! 		    break;
! 		}
  
! 	      if (lp < phdrs + count
! 		  && link_info->relro_end > lp->p_vaddr)
! 		{
! 		  p->p_vaddr = lp->p_vaddr;
! 		  p->p_paddr = lp->p_paddr;
! 		  p->p_offset = lp->p_offset;
! 		  p->p_filesz = link_info->relro_end - lp->p_vaddr;
! 		  p->p_memsz = p->p_filesz;
! 		  p->p_align = 1;
! 		  p->p_flags = (lp->p_flags & ~PF_W);
  		}
  	      else
  		{
--- 4494,4527 ----
  	    {
  	      Elf_Internal_Phdr *lp;
  
! 	      if (link_info != NULL)
  		{
! 		  for (lp = phdrs; lp < phdrs + count; ++lp)
! 		    {
! 		      if (lp->p_type == PT_LOAD
! 			  && lp->p_vaddr <= link_info->relro_end
! 			  && lp->p_vaddr >= link_info->relro_start
! 			  && lp->p_vaddr + lp->p_filesz
! 			  >= link_info->relro_end)
! 			break;
! 		    }
  
! 		  if (lp < phdrs + count
! 		      && link_info->relro_end > lp->p_vaddr)
! 		    {
! 		      p->p_vaddr = lp->p_vaddr;
! 		      p->p_paddr = lp->p_paddr;
! 		      p->p_offset = lp->p_offset;
! 		      p->p_filesz = link_info->relro_end - lp->p_vaddr;
! 		      p->p_memsz = p->p_filesz;
! 		      p->p_align = 1;
! 		      p->p_flags = (lp->p_flags & ~PF_W);
! 		    }
! 		  else
! 		    {
! 		      memset (p, 0, sizeof *p);
! 		      p->p_type = PT_NULL;
! 		    }
  		}
  	      else
  		{

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