This is the mail archive of the binutils@sources.redhat.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]

Fix ARM .p2align implementation


Hi Guys,

  Oops - just discovered a bug in my recent implementation of no-op
  padding for the .p2align directive.  I was not checking to see how
  many padding bytes needed to be inserted, and it was possible to
  overrun the buffer in the frag.  The patch below fixes this, and
  also switches the use of 'fragp' to 'fragP' to match the convention
  use din the rest of the file.

Cheers
        Nick


2001-05-06  Nick Clifton  <nickc@cambridge.redhat.com>

	* config/tc-arm.h (MAX_MEM_FOR_RS_ALIGN_CODE): Define.
	* config/tc-arm.c (arm_handle_align): Do not insert more than
	MAX_MEM_FOR_RS_ALIGN_CODE bytes.
	(arm_frag_align_code): Use MAX_MEM_FOR_RS_ALIGN_CODE.

Index: config/tc-arm.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.h,v
retrieving revision 1.13
diff -p -r1.13 tc-arm.h
*** tc-arm.h	2001/04/26 15:19:21	1.13
--- tc-arm.h	2001/05/06 10:08:38
*************** void armelf_frob_symbol PARAMS ((symbolS
*** 215,220 ****
--- 215,222 ----
  #define DWARF2_LINE_MIN_INSN_LENGTH 2
  #endif
  
+ #define MAX_MEM_FOR_RS_ALIGN_CODE 31
+ 
  /* For frags in code sections we need to record whether they contain
     ARM code or THUMB code.  This is that if they have to be aligned,
     they can contain the correct type of no-op instruction.  */

Index: config/tc-arm.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.c,v
retrieving revision 1.81
diff -p -r1.81 tc-arm.c
*** tc-arm.c	2001/05/02 18:40:10	1.81
--- tc-arm.c	2001/05/06 10:08:38
*************** s_arm_elf_cons (nbytes)
*** 8796,8803 ****
     of an rs_align_code fragment.  */
  
  void
! arm_handle_align (fragp)
!      fragS *fragp;
  {
    static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
    static char const thumb_noop[2] = { 0xc0, 0x46 };
--- 8796,8803 ----
     of an rs_align_code fragment.  */
  
  void
! arm_handle_align (fragP)
!      fragS *fragP;
  {
    static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
    static char const thumb_noop[2] = { 0xc0, 0x46 };
*************** arm_handle_align (fragp)
*** 8808,8821 ****
    char * p;
    const char * noop;
    
!   if (fragp->fr_type != rs_align_code)
      return;
  
!   bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
!   p = fragp->fr_literal + fragp->fr_fix;
    fix = 0;
    
!   if (fragp->tc_frag_data)
      {
        if (target_big_endian)
  	noop = thumb_bigend_noop;
--- 8808,8824 ----
    char * p;
    const char * noop;
    
!   if (fragP->fr_type != rs_align_code)
      return;
  
!   bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
!   p = fragP->fr_literal + fragP->fr_fix;
    fix = 0;
    
!   if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
!     bytes = MAX_MEM_FOR_RS_ALIGN_CODE;
!   
!   if (fragP->tc_frag_data)
      {
        if (target_big_endian)
  	noop = thumb_bigend_noop;
*************** arm_handle_align (fragp)
*** 8848,8855 ****
        fix += noop_size;
      }
    
!   fragp->fr_fix += fix;
!   fragp->fr_var = noop_size;
  }
  
  /* Called from md_do_align.  Used to create an alignment
--- 8851,8858 ----
        fix += noop_size;
      }
    
!   fragP->fr_fix += fix;
!   fragP->fr_var = noop_size;
  }
  
  /* Called from md_do_align.  Used to create an alignment
*************** arm_frag_align_code (n, max)
*** 8864,8874 ****
  
    /* We assume that there will never be a requirment
       to support alignments greater than 32 bytes.  */
!   if (max > 31)
      as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
    
    p = frag_var (rs_align_code,
! 		31,
  		1,
  		(relax_substateT) max,
  		(symbolS *) NULL,
--- 8867,8877 ----
  
    /* We assume that there will never be a requirment
       to support alignments greater than 32 bytes.  */
!   if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
      as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
    
    p = frag_var (rs_align_code,
! 		MAX_MEM_FOR_RS_ALIGN_CODE,
  		1,
  		(relax_substateT) max,
  		(symbolS *) NULL,
*************** arm_frag_align_code (n, max)
*** 8881,8889 ****
  /* Perform target specific initialisation of a frag.  */
  
  void
! arm_init_frag (fragp)
!      fragS *fragp;
  {
    /* Record whether this frag is in an ARM or a THUMB area.  */
!   fragp->tc_frag_data = thumb_mode;
  }
--- 8884,8892 ----
  /* Perform target specific initialisation of a frag.  */
  
  void
! arm_init_frag (fragP)
!      fragS *fragP;
  {
    /* Record whether this frag is in an ARM or a THUMB area.  */
!   fragP->tc_frag_data = thumb_mode;
  }


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