[PATCH 1/5] MIPS/GAS: Fix o32 LD to the base register

Maciej W. Rozycki macro@linux-mips.org
Sun Oct 31 22:46:00 GMT 2010


On Mon, 18 Oct 2010, Maciej W. Rozycki wrote:

> > > Disassembly of section .text:
> > >
> > > 00000000 <.text>:
> > >    0:	00800821 	move	at,a0
> > >    4:	8c240000 	lw	a0,0(at)
> > >    8:	8c250004 	lw	a1,4(at)
> > 
> > Why are you doing it this way, rather than reversing the loads?
> 
>  Because I've got a hole in my imagination here? :/
> 
> > Seems a shame to use $at when we don't need to.
> 
>  Indeed, although we're no better elsewhere, consider e.g.:
> 
> $ cat ld-base-1.s
> 	.comm	foo, 1024
> 	ld	$4, foo
> $ as -32 -o ld-base-1.o ld-base-1.s
> $ objdump -dr ld-base-1.o
> 
> ld-base-1.o:     file format elf32-tradbigmips
> 
> 
> Disassembly of section .text:
> 
> 00000000 <.text>:
>    0:	3c010000	lui	at,0x0
> 			0: R_MIPS_HI16	foo
>    4:	8c240000	lw	a0,0(at)
> 			4: R_MIPS_LO16	foo
>    8:	8c250004	lw	a1,4(at)
> 			8: R_MIPS_LO16	foo
>    c:	00000000	nop
> 
> where $a1 could be used in place of $at, couldn't it?

 So this has evolved into a mini-batch now too.  I have verified changes 
in this series with mips-linux, mips64-linux, mipstx39-elf, mipsisa64-elf 
and mips-ecoff targets and their little-endian counterparts (including 
binutils and LD tests too :) ).

 These patches apply on top of the NewABI reloc LD/SD fix where 
applicable.

2010-10-31  Maciej W. Rozycki  <macro@linux-mips.org>

	gas/
	* config/tc-mips.c (macro)[M_LD_OB]: If the first load of the
	pair would overwrite the base register, then swap the accesses.

 OK?

binutils-2.20.51-20100925-mips-gas-ld-o-base.patch
Index: binutils-2.20.51/gas/config/tc-mips.c
===================================================================
--- binutils-2.20.51.orig/gas/config/tc-mips.c
+++ binutils-2.20.51/gas/config/tc-mips.c
@@ -7346,17 +7346,29 @@ macro (struct mips_cl_insn *ip)
 
     case M_LD_OB:
       s = HAVE_64BIT_GPRS ? "ld" : "lw";
+      off = 1;
+      /* If the first load would overwrite the base register,
+         then swap the accesses.  */
+      if (!HAVE_64BIT_GPRS && treg == breg && breg != ZERO)
+	{
+	  offset_expr.X_add_number += 4;
+	  treg += 1;
+	  off = -1;
+	}
       goto sd_ob;
+
     case M_SD_OB:
       s = HAVE_64BIT_GPRS ? "sd" : "sw";
+      off = 1;
+
     sd_ob:
       macro_build (&offset_expr, s, "t,o(b)", treg,
 		   -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
 		   breg);
       if (!HAVE_64BIT_GPRS)
 	{
-	  offset_expr.X_add_number += 4;
-	  macro_build (&offset_expr, s, "t,o(b)", treg + 1,
+	  offset_expr.X_add_number += 4 * off;
+	  macro_build (&offset_expr, s, "t,o(b)", treg + off,
 		       -1, offset_reloc[0], offset_reloc[1], offset_reloc[2],
 		       breg);
 	}



More information about the Binutils mailing list