Fix ARm assembler so that it rejects invalid immediate values for the Thumb ORR instr...
authorNick Clifton <nickc@redhat.com>
Tue, 13 Feb 2018 16:50:04 +0000 (16:50 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 13 Feb 2018 16:50:04 +0000 (16:50 +0000)
PR 22773
* config/tc-arm.c (md_apply_fix): Test Rn field of Thumb ORR
instruction before assuming that it is a MOV instruction.
* testsuite/gas/arm/pr22773.s: New test.
* testsuite/gas/arm/pr22773.d: New test driver.
* testsuite/gas/arm/pr22773.l: New expected output.

gas/ChangeLog
gas/config/tc-arm.c
gas/testsuite/gas/arm/pr22773.d [new file with mode: 0644]
gas/testsuite/gas/arm/pr22773.l [new file with mode: 0644]
gas/testsuite/gas/arm/pr22773.s [new file with mode: 0644]

index e66e8cee68cc44ec4c3b6a256d721fa43fbb7f9f..adf45692eb693b76699b7808f889856fcec7cbbb 100644 (file)
@@ -1,3 +1,12 @@
+2018-02-13  Nick Clifton  <nickc@redhat.com>
+
+       PR 22773
+       * config/tc-arm.c (md_apply_fix): Test Rn field of Thumb ORR
+       instruction before assuming that it is a MOV instruction.
+       * testsuite/gas/arm/pr22773.s: New test.
+       * testsuite/gas/arm/pr22773.d: New test driver.
+       * testsuite/gas/arm/pr22773.l: New expected output.
+
 2018-02-13  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/22791
index 9786f14762f441f9688e305cf2f4d74097df1923..7a5c02b2bb872453c87b33308c1bda8819c7bafa 100644 (file)
@@ -23596,12 +23596,14 @@ md_apply_fix (fixS *  fixP,
              /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
                 UINT16 (T3 encoding), MOVW only accepts UINT16.  When
                 disassembling, MOV is preferred when there is no encoding
-                overlap.
-                NOTE: MOV is using ORR opcode under Thumb 2 mode.  */
+                overlap.  */
              if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
+                 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
+                    but with the Rn field [19:16] set to 1111.  */
+                 && (((newval >> 16) & 0xf) == 0xf)
                  && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
                  && !((newval >> T2_SBIT_SHIFT) & 0x1)
-                 && value >= 0 && value <=0xffff)
+                 && value >= 0 && value <= 0xffff)
                {
                  /* Toggle bit[25] to change encoding from T2 to T3.  */
                  newval ^= 1 << 25;
diff --git a/gas/testsuite/gas/arm/pr22773.d b/gas/testsuite/gas/arm/pr22773.d
new file mode 100644 (file)
index 0000000..adb9681
--- /dev/null
@@ -0,0 +1,2 @@
+# name: PR 22773: Invalid immediate constants produce incorrect instruction
+# error-output: pr22773.l
diff --git a/gas/testsuite/gas/arm/pr22773.l b/gas/testsuite/gas/arm/pr22773.l
new file mode 100644 (file)
index 0000000..587c8a8
--- /dev/null
@@ -0,0 +1,3 @@
+[^:]*: Assembler messages:
+[^:]*:8: Error: invalid constant \(3201\) after fixup
+#pass
diff --git a/gas/testsuite/gas/arm/pr22773.s b/gas/testsuite/gas/arm/pr22773.s
new file mode 100644 (file)
index 0000000..011ecfd
--- /dev/null
@@ -0,0 +1,9 @@
+       .syntax unified
+       .cpu cortex-m4
+       .thumb
+
+       .section  .text
+
+       orr r1, #12800          /* This is OK.  */
+       orr r1, #12801          /* This cannot be encoded in Thumb mode.  */
+       /* GAS used to accept it though, and produce a MOV instruction instead.  */