This is the mail archive of the binutils@sourceware.cygnus.com 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]

Catch out or range ARM relocs


Hi Guys,

  I have checked in the patch below to catch bad ARM relocations and
  produce a suitable warning message.

Cheers
	Nick

1999-12-16  Nick Clifton  <nickc@cygnus.com>

	* coff-arm.c (NUM_ELEM): New macro.
	(NUM_RELOCS): New macro: The number of known ARM relocs.
	(RTYPE2HOWTO): Return NULL if the reloc type is out of range.
	(coff_arm_rtype_to_howto):  Return NULL if the reloc type is out
	of range.
	(bfd_arm_process_before_allocation): Produce a warning message if
	an out of range symbol index is encountered.

Index: coff-arm.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/coff-arm.c,v
retrieving revision 1.12
diff -w -p -r1.12 coff-arm.c
*** coff-arm.c	1999/11/25 11:52:39	1.12
--- coff-arm.c	1999/12/17 00:38:21
*************** Foundation, Inc., 59 Temple Place - Suit
*** 48,53 ****
--- 48,57 ----
  					(coff_data (abfd)->flags & ~ F_INTERWORK) \
  					 | (flg | F_INTERWORK_SET))
  
+ #ifndef NUM_ELEM
+ #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0]))
+ #endif
+      
  typedef enum {bunknown, b9, b12, b23} thumb_pcrel_branchtype;
  /* some typedefs for holding instructions */
  typedef unsigned long int insn32;
*************** static reloc_howto_type aoutarm_std_relo
*** 402,407 ****
--- 406,413 ----
  	PCRELOFFSET),
  };
  
+ #define NUM_RELOCS NUM_ELEM (aoutarm_std_reloc_howto)
+ 
  #ifdef COFF_WITH_PE
  /* Return true if this relocation should
     appear in the output .reloc section. */
*************** in_reloc_p (abfd, howto)
*** 415,423 ****
  }     
  #endif
  
- 
  #define RTYPE2HOWTO(cache_ptr, dst) \
! 	    (cache_ptr)->howto = aoutarm_std_reloc_howto + (dst)->r_type;
  
  #define coff_rtype_to_howto coff_arm_rtype_to_howto
  
--- 421,431 ----
  }     
  #endif
  
  #define RTYPE2HOWTO(cache_ptr, dst)		\
!   (cache_ptr)->howto =				\
!     (dst)->r_type < NUM_RELOCS			\
!     ? aoutarm_std_reloc_howto + (dst)->r_type	\
!     : NULL
  
  #define coff_rtype_to_howto coff_arm_rtype_to_howto
  
*************** coff_arm_rtype_to_howto (abfd, sec, rel,
*** 432,446 ****
  {
    reloc_howto_type *howto;
  
    howto = aoutarm_std_reloc_howto + rel->r_type;
  
    if (rel->r_type == ARM_RVA32)
-     {
        *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase;
-     }
  
    return howto;
- 
  }
  /* Used by the assembler. */
  
--- 440,454 ----
  {
    reloc_howto_type * howto;
  
+   if (rel->r_type >= NUM_RELOCS)
+     return NULL;
+   
    howto = aoutarm_std_reloc_howto + rel->r_type;
  
    if (rel->r_type == ARM_RVA32)
      *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase;
  
    return howto;
  }
  /* Used by the assembler. */
  
*************** coff_arm_reloc_type_lookup (abfd, code)
*** 698,704 ****
        bfd * abfd;
        bfd_reloc_code_real_type code;
  {
! #define ASTD(i,j)       case i: return &aoutarm_std_reloc_howto[j]
    if (code == BFD_RELOC_CTOR)
      switch (bfd_get_arch_info (abfd)->bits_per_address)
        {
--- 706,713 ----
        bfd * abfd;
        bfd_reloc_code_real_type code;
  {
! #define ASTD(i,j)       case i: return aoutarm_std_reloc_howto + j
!   
    if (code == BFD_RELOC_CTOR)
      switch (bfd_get_arch_info (abfd)->bits_per_address)
        {
*************** bfd_arm_process_before_allocation (abfd,
*** 1900,1906 ****
        for (rel = i; rel < i + sec->reloc_count; ++rel) 
  	{
  	  unsigned short                 r_type  = rel->r_type;
! 	  long                           symndx;
  	  struct coff_link_hash_entry *  h;
  
  	  symndx = rel->r_symndx;
--- 1909,1915 ----
        for (rel = i; rel < i + sec->reloc_count; ++rel) 
  	{
  	  unsigned short                 r_type  = rel->r_type;
! 	  unsigned long                  symndx;
  	  struct coff_link_hash_entry *  h;
  
  	  symndx = rel->r_symndx;
*************** bfd_arm_process_before_allocation (abfd,
*** 1909,1914 ****
--- 1918,1930 ----
  	  if (symndx == -1)
  	    continue;
  
+ 	  if (symndx >= obj_conv_table_size (abfd))
+ 	    {
+ 	      _bfd_error_handler (_("%s: illegal symbol index in reloc: %d"),
+ 				  bfd_get_filename (abfd), symndx);
+ 	      continue;
+ 	    }
+ 	  
  	  h = obj_coff_sym_hashes (abfd)[symndx];
  
  	  /* If the relocation is against a static symbol it must be within

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