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]

[PATCH] Fix seg fault in mn10300_elf_relax_delete_bytes


Hi Guys,

  My recent improvements to the MN10300's linker relaxation code
  introduced a bug whereby the linker would seg-fault when it was
  relaxing a section with no relocs attached to it.  The code just
  blindly assumed that there would be relocs.  Anyway I am applying
  the patch below to fix this situation.

Cheers
  Nick

bfd/ChangeLog
2007-10-31  Nick Clifton  <nickc@redhat.com>

	* elf-m10300.c (mn10300_elf_relax_delete_bytes): Do not look for
	align relocs when there are no relocs attached to the section.

Index: bfd/elf-m10300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-m10300.c,v
retrieving revision 1.88
diff -c -3 -p -r1.88 elf-m10300.c
*** bfd/elf-m10300.c	30 Oct 2007 15:18:29 -0000	1.88
--- bfd/elf-m10300.c	31 Oct 2007 11:29:52 -0000
*************** mn10300_elf_relax_delete_bytes (bfd *abf
*** 1847,1870 ****
    irel = elf_section_data (sec)->relocs;
    irelend = irel + sec->reloc_count;
  
!   /* If there is an align reloc at the end of the section ignore it.
!      GAS creates these relocs for reasons of its own, and they just
!      serve to keep the section artifically inflated.  */
!   if (ELF32_R_TYPE ((irelend - 1)->r_info) == (int) R_MN10300_ALIGN)
!     --irelend;
        
!   /* The deletion must stop at the next ALIGN reloc for an aligment
!      power larger than the number of bytes we are deleting.  */
!   for (; irel < irelend; irel++)
!     if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
! 	&& irel->r_offset > addr
! 	&& irel->r_offset < toaddr
! 	&& count < (1 << irel->r_addend))
!       {
! 	irelalign = irel;
! 	toaddr = irel->r_offset;
! 	break;
!       }
  
    /* Actually delete the bytes.  */
    memmove (contents + addr, contents + addr + count,
--- 1847,1873 ----
    irel = elf_section_data (sec)->relocs;
    irelend = irel + sec->reloc_count;
  
!   if (sec->reloc_count > 0)
!     {
!       /* If there is an align reloc at the end of the section ignore it.
! 	 GAS creates these relocs for reasons of its own, and they just
! 	 serve to keep the section artifically inflated.  */
!       if (ELF32_R_TYPE ((irelend - 1)->r_info) == (int) R_MN10300_ALIGN)
! 	--irelend;
        
!       /* The deletion must stop at the next ALIGN reloc for an aligment
! 	 power larger than the number of bytes we are deleting.  */
!       for (; irel < irelend; irel++)
! 	if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
! 	    && irel->r_offset > addr
! 	    && irel->r_offset < toaddr
! 	    && count < (1 << irel->r_addend))
! 	  {
! 	    irelalign = irel;
! 	    toaddr = irel->r_offset;
! 	    break;
! 	  }
!     }
  
    /* Actually delete the bytes.  */
    memmove (contents + addr, contents + addr + count,


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