[patch] rl78: fix OPsub math

DJ Delorie dj@redhat.com
Tue Jun 11 19:45:00 GMT 2013


Committed.

	* elf32-rl78.c (rl78_elf_relocate_section): Fix OPsub math.
 
Index: bfd/elf32-rl78.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-rl78.c,v
retrieving revision 1.15
diff -p -U 5 -r1.15  bfd/elf32-rl78.c
--- bfd/elf32-rl78.c	11 Jun 2013 07:21:40 -0000	1.15
+++ bfd/elf32-rl78.c	11 Jun 2013 19:14:44 -0000
@@ -808,14 +808,17 @@ rl78_elf_relocate_section
 
 	case R_RL78_OPsub:
 	  {
 	    int32_t tmp1, tmp2;
 
-	    RL78_STACK_POP (tmp2);
-	    RL78_STACK_POP (tmp1);
-	    tmp2 -= tmp1;
-	    RL78_STACK_PUSH (tmp2);
+	    /* For the expression "A - B", the assembler pushes A,
+	       then B, then OPSUB.  So the first op we pop is B, not
+	       A.  */
+	    RL78_STACK_POP (tmp2);	/* B */
+	    RL78_STACK_POP (tmp1);	/* A */
+	    tmp1 -= tmp2;		/* A - B */
+	    RL78_STACK_PUSH (tmp1);
 	  }
 	  break;
 
 	case R_RL78_OPmul:
 	  {



More information about the Binutils mailing list