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]

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


On Mon, 5 Nov 2012, Richard Sandiford wrote:

> >  Well, not quite from 20yrs ago, the lack of an error with the former 
> > example is an unfortunate side effect of the recent %hi/%lo fix -- exactly 
> > where I noted the need for better overflow handling.  I get this:
> >
> > addiu.s: Assembler messages:
> > addiu.s:1: Error: relocation overflow
> >
> > with arbitrarily picked version 2.20.1, so I think first we can (and 
> > should) bring it back and second enforce it for LUI as well (well, with 
> > what I have in mind that'll be automatic).  Do you still think we have to 
> > avoid such checks?
> 
> Nope, thanks for correcting me.

 OK, I'll propose a separate change sometime then.

 Here's an updated version of the LUI fix that has now interestingly 
enough reduced to a one-liner.  I have adjusted the test cases accordingly 
and added some extra checks based on the case you've been concerned about.  

 While doing that I noticed my original change wasn't exactly right for 
bignums, the wrong unrelated value would be reported in the error message 
and, according to my investigation, we have no helper implemented for 
printing values of bignums in diagnostic output at all.  They are however 
caught and reported elsewhere and therefore require no special handling 
here.  I have updated one of the test cases to cover them though.

 Finally, I have added an invalid expression using symbols in an 
arbitrarily chosen division operation -- expressions of such kind are 
currently silently accepted as a LUI argument.  Interestingly enough and 
unfortunately -- as seen in the diagnostic output pattern -- the errors 
are not reported in the sequence matching the order of lines, which I find 
rather confusing and counterintuitive, but obviously this is not an issue 
related to the bug being addressed here.

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

2012-11-07  Maciej W. Rozycki  <macro@codesourcery.com>

	gas/
	* config/tc-mips.c (mips_ip) <'u'>: Default to BFD_RELOC_LO16.

	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-11-06 15:37:08.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c	2012-11-06 22:27:34.781533749 +0000
@@ -12413,6 +12413,7 @@ 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
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-11-07 11:29:29.081063232 +0000
@@ -0,0 +1,5 @@
+.*\.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: bignum invalid
+.*\.s:8: Error: register value used as expression
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-11-07 11:29:11.020952285 +0000
@@ -0,0 +1,8 @@
+# Source code used to test error diagnostics with the LUI instruction.
+
+	.text
+foo:
+	lui	$2, -1
+	lui	$2, 65536
+	lui	$2, 0x10000000000000000
+	lui	$2, $3
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-11-07 13:30:42.861186973 +0000
@@ -0,0 +1,5 @@
+.*\.s: Assembler messages:
+.*\.s:10: Error: invalid operands \(\*UND\* and \*UND\* sections\) for `/'
+.*\.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-11-07 11:28:01.280861148 +0000
@@ -0,0 +1,10 @@
+# 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
+	lui	$2, bar / 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-11-07 11:07:45.460717851 +0000
@@ -0,0 +1,25 @@
+#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
+[0-9a-f]+ <[^>]*> 3c02000c 	lui	v0,0xc
+[ 	]*[0-9a-f]+: R_MIPS_LO16	\.text
+[0-9a-f]+ <[^>]*> 3c020000 	lui	v0,0x0
+[ 	]*[0-9a-f]+: R_MIPS_LO16	ext
+[0-9a-f]+ <[^>]*> 3c020020 	lui	v0,0x20
+[ 	]*[0-9a-f]+: R_MIPS_LO16	\.text
+[0-9a-f]+ <[^>]*> 3c020028 	lui	v0,0x28
+[ 	]*[0-9a-f]+: R_MIPS_LO16	\.text
+[0-9a-f]+ <[^>]*> 3c020000 	lui	v0,0x0
+[0-9a-f]+ <[^>]*> 3c02ffff 	lui	v0,0xffff
+	\.\.\.
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-11-07 11:02:33.251200722 +0000
@@ -0,0 +1,29 @@
+# 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:
+	lui	$2, bar
+	lui	$2, ext
+3:
+	lui	$2, 3b
+	lui	$2, 4f
+4:
+	lui	$2, min + 1
+	lui	$2, max - 1
+	.eqv	min, -1
+	.eqv	max, 65536
+
+# 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-11-07 11:11:48.670715210 +0000
@@ -0,0 +1,25 @@
+#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
+[0-9a-f]+ <[^>]*> 41a2 000d 	lui	v0,0xd
+[ 	]*[0-9a-f]+: R_MICROMIPS_LO16	\.text
+[0-9a-f]+ <[^>]*> 41a2 0000 	lui	v0,0x0
+[ 	]*[0-9a-f]+: R_MICROMIPS_LO16	ext
+[0-9a-f]+ <[^>]*> 41a2 0021 	lui	v0,0x21
+[ 	]*[0-9a-f]+: R_MICROMIPS_LO16	\.text
+[0-9a-f]+ <[^>]*> 41a2 0029 	lui	v0,0x29
+[ 	]*[0-9a-f]+: R_MICROMIPS_LO16	\.text
+[0-9a-f]+ <[^>]*> 41a2 0000 	lui	v0,0x0
+[0-9a-f]+ <[^>]*> 41a2 ffff 	lui	v0,0xffff
+	\.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp	2012-11-06 15:37:08.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp	2012-11-06 15:37:15.000000000 +0000
@@ -1128,4 +1128,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]