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]

[ping][PATCH] MIPS/GAS: LUI operand handling bug fixes


Richard,

 Would you please find a spare moment to have a look at the change below?  
Thanks.

  Maciej

---------- Forwarded message ----------
Message-ID: <alpine.DEB.1.10.1210242310030.9406@tp.orcam.me.uk>
Date: Wed, 24 Oct 2012 23:25:08 +0100
From: Maciej W. Rozycki <macro@codesourcery.com>
To: binutils@sourceware.org
Subject: [PATCH] MIPS/GAS: LUI operand handling bug fixes

Hi,

 The change below fixes a problem with the LUI immediate (second) operand.  
In the absence of relocation operators any incorrect non-constant 
expressions used for that operand, e.g. a register or a symbol reference 
were silently accepted and some immediate value assumed -- generally zero, 
although for offset symbols that would presumably be that symbol's offset.  
Furthermore some legitimate expressions such as unresolved yet local 
symbol differences were similarly ignored and likewise expanded to zero.  
This is illustrated by the test cases provided.

 No regressions in testing across the usual MIPS targets.  OK to apply?

2012-10-24  Maciej W. Rozycki  <macro@codesourcery.com>

	gas/
	* config/tc-mips.c (mips_ip) <'u'>: Only accept O_subtract and 
	in-range O_constant expressions.

	gas/testsuite/
	* gas/mips/lui.d: New test.
	* gas/mips/micromips@lui.d: New test.
	* gas/mips/lui-1.l: New list test.
	* gas/mips/lui-2.l: New list test.
	* gas/mips/lui.s: New test source.
	* gas/mips/lui-1.s: New test source.
	* gas/mips/lui-2.s: New test source.
	* gas/mips/mips.exp: Run the new tests.

  Maciej

binutils-mips-gas-lui-err.diff
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c	2012-10-23 15:21:54.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c	2012-10-24 23:11:48.110668814 +0100
@@ -12392,12 +12392,19 @@ mips_ip (char *str, struct mips_cl_insn 
 	      continue;
 
 	    case 'u':		/* Upper 16 bits.  */
+	      *imm_reloc = BFD_RELOC_LO16;
 	      if (my_getSmallExpression (&imm_expr, imm_reloc, s) == 0
-		  && imm_expr.X_op == O_constant
-		  && (imm_expr.X_add_number < 0
-		      || imm_expr.X_add_number >= 0x10000))
-		as_bad (_("lui expression (%lu) not in range 0..65535"),
-			(unsigned long) imm_expr.X_add_number);
+		  && (imm_expr.X_op != O_constant
+		      || imm_expr.X_add_number < 0
+		      || imm_expr.X_add_number >= 0x10000)
+		  && imm_expr.X_op != O_subtract)
+		{
+		  if (imm_expr.X_op == O_constant || imm_expr.X_op == O_big)
+		    as_bad (_("lui expression (%lu) not in range 0..65535"),
+			    (unsigned long) imm_expr.X_add_number);
+		  else
+		    insn_error = _("Absolute expression required");
+		}
 	      s = expr_end;
 	      continue;
 
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-1.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-1.l	2012-10-23 15:21:57.440584272 +0100
@@ -0,0 +1,8 @@
+.*\.s: Assembler messages:
+.*\.s:5: Error: lui expression \((18446744073709551615|4294967295)\) not in range 0\.\.65535
+.*\.s:6: Error: lui expression \(65536\) not in range 0\.\.65535
+.*\.s:7: Error: Absolute expression required `lui \$2,\$3'
+.*\.s:9: Error: Absolute expression required `lui \$2,0b'
+.*\.s:10: Error: Absolute expression required `lui \$2,1f'
+.*\.s:12: Error: Absolute expression required `lui \$2,foo'
+.*\.s:13: Error: Absolute expression required `lui \$2,bar'
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-1.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-1.s	2012-10-23 15:21:57.451371585 +0100
@@ -0,0 +1,13 @@
+# Source code used to test error diagnostics with the LUI instruction.
+
+	.text
+foo:
+	lui	$2, -1
+	lui	$2, 65536
+	lui	$2, $3
+0:
+	lui	$2, 0b
+	lui	$2, 1f
+1:
+	lui	$2, foo
+	lui	$2, bar
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-2.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-2.l	2012-10-23 15:21:57.451371585 +0100
@@ -0,0 +1,4 @@
+.*\.s: Assembler messages:
+.*\.s:7: Error: can't resolve `bar' {\*UND\* section} - `foo' {\.text section}
+.*\.s:8: Error: can't resolve `baz' {\*UND\* section} - `bar' {\*UND\* section}
+.*\.s:9: Error: can't resolve `\.text' {\.text section} - `baz' {\*UND\* section}
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-2.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui-2.s	2012-10-23 15:21:57.451371585 +0100
@@ -0,0 +1,9 @@
+# Source code used to test error diagnostics with the LUI instruction.
+# These need to be separate from lui-1.s as they are reported at a later
+# stage in assembly.
+
+	.text
+foo:
+	lui	$2, bar - foo
+	lui	$2, baz - bar
+	lui	$2, foo - baz
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui.d	2012-10-23 15:21:57.451371585 +0100
@@ -0,0 +1,15 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS lui
+#as: -32
+#source: lui.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 3c020000 	lui	v0,0x0
+[0-9a-f]+ <[^>]*> 3c02ffff 	lui	v0,0xffff
+[0-9a-f]+ <[^>]*> 3c020008 	lui	v0,0x8
+[0-9a-f]+ <[^>]*> 3c020008 	lui	v0,0x8
+[0-9a-f]+ <[^>]*> 3c02000c 	lui	v0,0xc
+[0-9a-f]+ <[^>]*> 3c02000c 	lui	v0,0xc
+	\.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/lui.s	2012-10-23 15:21:57.451371585 +0100
@@ -0,0 +1,20 @@
+# Source code used to test the LUI instruction with some expressions.
+
+	.text
+foo:
+0:
+	lui	$2, 0
+	lui	$2, 65535
+1:
+	lui	$2, 1b - 0b
+bar:
+	lui	$2, 2f - 1b
+2:
+	lui	$2, bar - foo
+	lui	$2, baz - bar
+baz:
+	sll	$0, $0, 0
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips@lui.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips@lui.d	2012-10-23 15:21:57.451371585 +0100
@@ -0,0 +1,15 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS lui
+#as: -32
+#source: lui.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 41a2 0000 	lui	v0,0x0
+[0-9a-f]+ <[^>]*> 41a2 ffff 	lui	v0,0xffff
+[0-9a-f]+ <[^>]*> 41a2 0008 	lui	v0,0x8
+[0-9a-f]+ <[^>]*> 41a2 0008 	lui	v0,0x8
+[0-9a-f]+ <[^>]*> 41a2 000c 	lui	v0,0xc
+[0-9a-f]+ <[^>]*> 41a2 000c 	lui	v0,0xc
+	\.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp	2012-10-23 15:21:54.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp	2012-10-24 23:11:48.110668814 +0100
@@ -1125,4 +1125,7 @@ if { [istarget mips*-*-vxworks*] } {
 	run_dump_test_arches "hilo-diff-eb-n64" [mips_arch_list_matching mips3]
 	run_dump_test_arches "hilo-diff-el-n64" [mips_arch_list_matching mips3]
     }
+    run_dump_test_arches "lui"		[mips_arch_list_matching mips1]
+    run_list_test_arches "lui-1" "-32"	[mips_arch_list_matching mips1]
+    run_list_test_arches "lui-2" "-32"	[mips_arch_list_matching mips1]
 }


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