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]
Other format: [Raw text]

Re: [patch 2.13.2] Fix relaxation on h8300.


On Sun, Dec 15, 2002 at 10:22:19PM -0500, Kazu Hirata wrote:
> Hi,
> 
> Attached is a patch that is a backport of the following from the
> mainline (without formatting changes).  OK to apply?
> 
> http://sources.redhat.com/ml/binutils/2002-11/msg00417.html
> http://sources.redhat.com/ml/binutils-cvs/2002-11/msg00132.html

Please do.  Thanks for the patch.

> 
> Thanks,
> 
> Kazu Hirata
> 
> 2002-12-15  Kazu Hirata  <kazu@cs.umass.edu>
> 
> 	* coff-h8300.c (h8300_reloc16_estimate): Do not optimize away
> 	jsr after a short jump.
> 	* elf32-h8300.c (elf32_h8_relax_section): Likewise.
> 
> Index: coff-h8300.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/coff-h8300.c,v
> retrieving revision 1.12
> diff -c -r1.12 coff-h8300.c
> *** coff-h8300.c	4 Apr 2002 19:53:35 -0000	1.12
> --- coff-h8300.c	16 Dec 2002 03:06:07 -0000
> ***************
> *** 485,490 ****
> --- 485,497 ----
>   	 closer if we do relax this branch.  */
>         if ((int)gap >= -128 && (int)gap <= 128 )
>   	{
> + 	  bfd_byte code;
> + 
> + 	  if (!bfd_get_section_contents (abfd, input_section, & code,
> + 					 reloc->address, 1))
> + 	    break;
> + 	  code = bfd_get_8 (abfd, & code);
> + 
>   	  /* It's possible we may be able to eliminate this branch entirely;
>   	     if the previous instruction is a branch around this instruction,
>   	     and there's no label at this instruction, then we can reverse
> ***************
> *** 496,504 ****
>   		lab1:				lab1:
>   
>   	     This saves 4 bytes instead of two, and should be relatively
> ! 	     common.  */
>   
> ! 	  if (gap <= 126
>   	      && last_reloc
>   	      && last_reloc->howto->type == R_PCRBYTE)
>   	    {
> --- 503,527 ----
>   		lab1:				lab1:
>   
>   	     This saves 4 bytes instead of two, and should be relatively
> ! 	     common.
> ! 
> ! 	     Only perform this optimisation for jumps (code 0x5a) not
> ! 	     subroutine calls, as otherwise it could transform:
> ! 
> ! 	     	             mov.w   r0,r0
> ! 	     	             beq     .L1
> ! 	           	     jsr     @_bar
> ! 	              .L1:   rts
> ! 	              _bar:  rts
> ! 	     into:
> ! 	     	             mov.w   r0,r0
> ! 	     	             bne     _bar
> ! 	     	             rts
> ! 	     	      _bar:  rts
>   
> ! 	     which changes the call (jsr) into a branch (bne).  */
> ! 	  if (code == 0x5a
> ! 	      && gap <= 126
>   	      && last_reloc
>   	      && last_reloc->howto->type == R_PCRBYTE)
>   	    {
> Index: elf32-h8300.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elf32-h8300.c,v
> retrieving revision 1.14.2.1
> diff -c -r1.14.2.1 elf32-h8300.c
> *** elf32-h8300.c	23 Sep 2002 22:12:39 -0000	1.14.2.1
> --- elf32-h8300.c	16 Dec 2002 03:06:09 -0000
> ***************
> *** 847,860 ****
>   		elf_section_data (sec)->this_hdr.contents = contents;
>   		symtab_hdr->contents = (unsigned char *) isymbuf;
>   
>   		/* If the previous instruction conditionally jumped around
>   		   this instruction, we may be able to reverse the condition
>   		   and redirect the previous instruction to the target of
>   		   this instruction.
>   
>   		   Such sequences are used by the compiler to deal with
> ! 		   long conditional branches.  */
> ! 		if ((int) gap <= 130
>   		    && (int) gap >= -128
>   		    && last_reloc
>   		    && ELF32_R_TYPE (last_reloc->r_info) == R_H8_PCREL8
> --- 847,880 ----
>   		elf_section_data (sec)->this_hdr.contents = contents;
>   		symtab_hdr->contents = (unsigned char *) isymbuf;
>   
> + 		/* Get the instruction code being relaxed.  */
> + 		code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
> + 
>   		/* If the previous instruction conditionally jumped around
>   		   this instruction, we may be able to reverse the condition
>   		   and redirect the previous instruction to the target of
>   		   this instruction.
>   
>   		   Such sequences are used by the compiler to deal with
> ! 		   long conditional branches.
> ! 
> ! 		   Only perform this optimisation for jumps (code 0x5a) not
> ! 		   subroutine calls, as otherwise it could transform:
> ! 
> ! 		   	             mov.w   r0,r0
> ! 		   	             beq     .L1
> ! 		         	     jsr     @_bar
> ! 		              .L1:   rts
> ! 		              _bar:  rts
> ! 		   into:
> ! 		   	             mov.w   r0,r0
> ! 			             bne     _bar
> ! 			             rts
> ! 			      _bar:  rts
> ! 
> ! 		   which changes the call (jsr) into a branch (bne).  */
> ! 		if (code == 0x5a
> ! 		    && (int) gap <= 130
>   		    && (int) gap >= -128
>   		    && last_reloc
>   		    && ELF32_R_TYPE (last_reloc->r_info) == R_H8_PCREL8
> ***************
> *** 910,918 ****
>   			break;
>   		      }
>   		  }
> - 
> - 		/* We could not eliminate this jump, so just shorten it.  */
> - 		code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
>   
>   		if (code == 0x5e)
>   		  bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 1);
> --- 930,935 ----
> 

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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