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

Fix PR gas/10623 and several related bugs


PR gas/10623 was really about erroring out for register operands
to SWYM, which was handled by Knuth's mmixal; an unwanted
inconsistency.

While fixing that, I noticed several bugs for this case of
operands when adding test-cases for complete code coverage.
Luckily, operands for these insns are not expected to be other
than simple literals, e.g. "trap 99".  Committed to trunk.  Will
commit to the 2.20 branch as well.

gas:
2009-09-11  Hans-Peter Nilsson  <hp@bitrange.com>

	PR gas/10623
	* config/tc-mmix.c (md_assemble) <case mmix_operands_xyz_opt>:
	Allow register operands for SWYM as for TRIP and TRAP.  Correct
	operand handling and error checking.  Never emit
	BFD_RELOC_MMIX_REG_OR_BYTE for operands to these insns.

gas/testsuite:
2009-09-11  Hans-Peter Nilsson  <hp@bitrange.com>

	PR gas/10623
	* gas/mmix/err-swym1.s, gas/mmix/swym-opreg1.d,
	gas/mmix/swym-opreg1.s, gas/mmix/swym-opreg2.d,
	gas/mmix/swym-opreg2.s: New tests.
	* gas/mmix/odd-1.d: Adjust for reloc change.

Index: gas/config/tc-mmix.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mmix.c,v
retrieving revision 1.33
diff -p -u -r1.33 tc-mmix.c
--- gas/config/tc-mmix.c	2 Sep 2009 07:24:20 -0000	1.33
+++ gas/config/tc-mmix.c	10 Sep 2009 22:23:22 -0000
@@ -1673,7 +1673,10 @@ md_assemble (char *str)
       break;

     case mmix_operands_xyz_opt:
-      /* SWYM, TRIP, TRAP: zero, one, two or three operands.  */
+      /* SWYM, TRIP, TRAP: zero, one, two or three operands.  It's
+	 unspecified whether operands are registers or constants, but
+	 when we find register syntax, we require operands to be literal and
+	 within 0..255.  */
       if (n_operands == 0 && ! mmix_gnu_syntax)
 	/* Zeros are in place - nothing needs to be done for zero
 	   operands.  We don't allow this in GNU syntax mode, because it
@@ -1684,7 +1687,7 @@ md_assemble (char *str)
 	{
 	  if (exp[0].X_op == O_constant)
 	    {
-	      if (exp[0].X_add_number > 255*255*255
+	      if (exp[0].X_add_number > 255*256*256
 		  || exp[0].X_add_number < 0)
 		{
 		  as_bad (_("invalid operands to opcode %s: `%s'"),
@@ -1726,7 +1729,7 @@ md_assemble (char *str)

 	  if (exp[1].X_op == O_constant)
 	    {
-	      if (exp[1].X_add_number > 255*255
+	      if (exp[1].X_add_number > 255*256
 		  || exp[1].X_add_number < 0)
 		{
 		  as_bad (_("invalid operands to opcode %s: `%s'"),
@@ -1798,12 +1801,15 @@ md_assemble (char *str)
 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
 			 1, exp + 2, 0, BFD_RELOC_8);
 	}
-      else if (n_operands <= 3
-	       && (strcmp (instruction->name, "trip") == 0
-		   || strcmp (instruction->name, "trap") == 0))
+      else
 	{
-	  /* The meaning of operands to TRIP and TRAP are not defined, so
-	     we add combinations not handled above here as we find them.  */
+	  /* We can't get here for other cases.  */
+	  gas_assert (n_operands <= 3);
+
+	  /* The meaning of operands to TRIP and TRAP is not defined (and
+	     SWYM operands aren't enforced in mmixal, so let's avoid
+	     that).  We add combinations not handled above here as we find
+	     them and as they're reported.  */
 	  if (n_operands == 3)
 	    {
 	      /* Don't require non-register operands.  Always generate
@@ -1811,49 +1817,48 @@ md_assemble (char *str)
 		 maintenance problems.  TRIP is supposed to be a rare
 		 instruction, so the overhead should not matter.  We
 		 aren't allowed to fix_new_exp for an expression which is
-		 an  O_register at this point, however.  */
+		 an O_register at this point, however.
+
+		 Don't use BFD_RELOC_MMIX_REG_OR_BYTE as that modifies
+		 the insn for a register in the Z field and we want
+		 consistency.  */
 	      if (exp[0].X_op == O_register)
 		opcodep[1] = exp[0].X_add_number;
 	      else
 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
-			     1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+			     1, exp, 0, BFD_RELOC_8);
 	      if (exp[1].X_op == O_register)
 		opcodep[2] = exp[1].X_add_number;
 	      else
 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
-			     1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+			     1, exp + 1, 0, BFD_RELOC_8);
 	      if (exp[2].X_op == O_register)
 		opcodep[3] = exp[2].X_add_number;
 	      else
 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
-			     1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+			     1, exp + 2, 0, BFD_RELOC_8);
 	    }
 	  else if (n_operands == 2)
 	    {
 	      if (exp[0].X_op == O_register)
-		opcodep[2] = exp[0].X_add_number;
+		opcodep[1] = exp[0].X_add_number;
 	      else
-		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
-			     1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
+			     1, exp, 0, BFD_RELOC_8);
 	      if (exp[1].X_op == O_register)
 		opcodep[3] = exp[1].X_add_number;
 	      else
-		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
-			     1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
+			     2, exp + 1, 0, BFD_RELOC_16);
 	    }
 	  else
 	    {
-	      as_bad (_("unsupported operands to %s: `%s'"),
-		      instruction->name, operands);
-	      return;
+	      /* We can't get here for other cases.  */
+	      gas_assert (n_operands == 1 && exp[0].X_op == O_register);
+
+	      opcodep[3] = exp[0].X_add_number;
 	    }
 	}
-      else
-	{
-	  as_bad (_("invalid operands to opcode %s: `%s'"),
-		  instruction->name, operands);
-	  return;
-	}
       break;

     case mmix_operands_resume:

Index: gas/testsuite/gas/mmix/err-swym1.s
===================================================================
RCS file: gas/testsuite/gas/mmix/err-swym1.s
diff -N gas/testsuite/gas/mmix/err-swym1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/mmix/err-swym1.s	10 Sep 2009 22:31:31 -0000
@@ -0,0 +1,15 @@
+% { dg-do assemble { target mmix-*-* } }
+ SWYM 256*256*256	% { dg-error "invalid operands" "" }
+ SWYM -1		% { dg-error "invalid operands" "" }
+ SWYM 99,256*256	% { dg-error "invalid operands" "" }
+ SWYM 99,-1		% { dg-error "invalid operands" "" }
+ SWYM 256,1,2		% { dg-error "invalid operands" "" }
+ SWYM 1,256,2		% { dg-error "invalid operands" "" }
+ SWYM 1,2,256		% { dg-error "invalid operands" "" }
+ SWYM -1,1,2		% { dg-error "invalid operands" "" }
+ SWYM 1,-1,2		% { dg-error "invalid operands" "" }
+ SWYM 1,2,-1		% { dg-error "invalid operands" "" }
+ SWYM 256,1		% { dg-error "invalid operands" "" }
+ SWYM -1,1		% { dg-error "invalid operands" "" }
+ SWYM 1,2,3,4		% { dg-error "invalid operands" "" }
+ SWYM 1,2,3,4,5		% { dg-error "invalid operands" "" }
Index: gas/testsuite/gas/mmix/odd-1.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mmix/odd-1.d,v
retrieving revision 1.3
diff -p -u -r1.3 odd-1.d
--- gas/testsuite/gas/mmix/odd-1.d	11 Dec 2004 04:32:36 -0000	1.3
+++ gas/testsuite/gas/mmix/odd-1.d	10 Sep 2009 22:31:31 -0000
@@ -15,7 +15,7 @@ SYMBOL TABLE:

 RELOCATION RECORDS FOR \[\.text\]:
 OFFSET           TYPE              VALUE
-0+7 R_MMIX_REG_OR_BYTE  \.MMIX\.reg_contents
+0+7 R_MMIX_8          \.MMIX\.reg_contents
 0+f R_MMIX_REG        \.MMIX\.reg_contents
 0+15 R_MMIX_REG        \.MMIX\.reg_contents
 0+19 R_MMIX_REG        \.MMIX\.reg_contents
Index: gas/testsuite/gas/mmix/swym-opreg1.d
===================================================================
RCS file: gas/testsuite/gas/mmix/swym-opreg1.d
diff -N gas/testsuite/gas/mmix/swym-opreg1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/mmix/swym-opreg1.d	10 Sep 2009 22:31:31 -0000
@@ -0,0 +1,31 @@
+# objdump: -dr
+.*:     file format elf64-mmix
+
+Disassembly of section \.text:
+
+0+ <Main>:
+   0:	fd000005 	swym 0,0,5
+   4:	fd000005 	swym 0,0,5
+   8:	fd020005 	swym 2,0,5
+   c:	fd020005 	swym 2,0,5
+  10:	fd010203 	swym 1,2,3
+  14:	fd010203 	swym 1,2,3
+  18:	fd010203 	swym 1,2,3
+  1c:	fd010203 	swym 1,2,3
+  20:	00000005 	trap 0,0,5
+  24:	00000005 	trap 0,0,5
+  28:	00020005 	trap 2,0,5
+  2c:	00020005 	trap 2,0,5
+  30:	00010203 	trap 1,2,3
+  34:	00010203 	trap 1,2,3
+  38:	00010203 	trap 1,2,3
+  3c:	00010203 	trap 1,2,3
+  40:	ff0b1621 	trip 11,22,33
+  44:	fd00007b 	swym 0,0,123
+  48:	fd7bb26e 	swym 123,178,110
+  4c:	ff12d687 	trip 18,214,135
+  50:	007b002d 	trap 123,0,45
+  54:	007bb26e 	trap 123,178,110
+  58:	fffeff01 	trip 254,255,1
+  5c:	fd63ff00 	swym 99,255,0
+
Index: gas/testsuite/gas/mmix/swym-opreg1.s
===================================================================
RCS file: gas/testsuite/gas/mmix/swym-opreg1.s
diff -N gas/testsuite/gas/mmix/swym-opreg1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/mmix/swym-opreg1.s	10 Sep 2009 22:31:31 -0000
@@ -0,0 +1,24 @@
+Main	SWYM 0,5
+	SWYM $0,5
+	SWYM $2,5
+	SWYM $2,0,5
+	SWYM 1,2,3
+	SWYM $1,$2,3
+	SWYM $1,$2,$3
+	SWYM 1,2,$3
+	TRAP 0,5
+	TRAP $0,5
+	TRAP $2,5
+	TRAP $2,0,5
+	TRAP 1,2,3
+	TRAP $1,$2,3
+	TRAP $1,$2,$3
+	TRAP 1,2,$3
+	TRIP $11,22,$33
+	SWYM $123
+	SWYM $123,45678
+	TRIP 1234567
+	TRAP 123,$45
+	TRAP 123,45678
+	TRIP 255*255*257
+	SWYM 99,255*256
Index: gas/testsuite/gas/mmix/swym-opreg2.d
===================================================================
RCS file: gas/testsuite/gas/mmix/swym-opreg2.d
diff -N gas/testsuite/gas/mmix/swym-opreg2.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/mmix/swym-opreg2.d	10 Sep 2009 22:31:31 -0000
@@ -0,0 +1,8 @@
+# objdump: -dr
+.*:     file format elf64-mmix
+
+Disassembly of section \.text:
+
+0+ <Main>:
+   0:	00000000 	trap 0,0,0
+			1: R_MMIX_24	foo\+0x237
Index: gas/testsuite/gas/mmix/swym-opreg2.s
===================================================================
RCS file: gas/testsuite/gas/mmix/swym-opreg2.s
diff -N gas/testsuite/gas/mmix/swym-opreg2.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/mmix/swym-opreg2.s	10 Sep 2009 22:31:31 -0000
@@ -0,0 +1 @@
+Main	TRAP foo+567

brgds, H-P


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