PR gas/19744: Thumb-1 pcrop relocations don't work on Thumb-2 targets
authorMickael Guene <mickael.guene@st.com>
Thu, 10 Mar 2016 16:05:29 +0000 (17:05 +0100)
committerChristophe Lyon <christophe.lyon@linaro.org>
Thu, 10 Mar 2016 16:06:35 +0000 (17:06 +0100)
gas/
* config/tc-arm.c (do_arit): Protect against bad relocations usage.
(do_mov): Likewise.
(do_t_add_sub): Allow pcrop relocations for Thumb-2 targets.
(do_t_mov_cmp): Likewise.
(do_t_add_sub): Protect against bad relocations usage.
(do_t_mov_cmp): Likewise.

gas/testsuite/
* gas/arm/adds-thumb1-reloc-local-armv7-m.s: New.
* gas/arm/adds-thumb1-reloc-local-armv7-m.d: New.
* gas/arm/movs-thumb1-reloc-local-armv7-m.s: New.
* gas/arm/movs-thumb1-reloc-local-armv7-m.d: New.

ld/
* testsuite/ld-arm/arm-elf.exp: New tests.
* testsuite/ld-arm/thumb1-adds-armv7-m.s: New.
* testsuite/ld-arm/thumb1-movs-armv7-m.s: New.

gas/ChangeLog
gas/config/tc-arm.c
gas/testsuite/ChangeLog
gas/testsuite/gas/arm/adds-thumb1-reloc-local-armv7-m.d [new file with mode: 0644]
gas/testsuite/gas/arm/adds-thumb1-reloc-local-armv7-m.s [new file with mode: 0644]
gas/testsuite/gas/arm/movs-thumb1-reloc-local-armv7-m.d [new file with mode: 0644]
gas/testsuite/gas/arm/movs-thumb1-reloc-local-armv7-m.s [new file with mode: 0644]
ld/ChangeLog
ld/testsuite/ld-arm/arm-elf.exp
ld/testsuite/ld-arm/thumb1-adds-armv7-m.s [new file with mode: 0644]
ld/testsuite/ld-arm/thumb1-movs-armv7-m.s [new file with mode: 0644]

index c9c82acd2c8fa06d583d4b086a4ed5d8b4c9451b..cbce6a5dc3843f3c42125fa736621b2b722f7f75 100644 (file)
@@ -1,3 +1,13 @@
+2016-03-10  Mickael Guene  <mickael.guene@st.com>
+
+       PR gas/19744
+       * config/tc-arm.c (do_arit): Protect against bad relocations usage.
+       (do_mov): Likewise.
+       (do_t_add_sub): Allow pcrop relocations for Thumb-2 targets.
+       (do_t_mov_cmp): Likewise.
+       (do_t_add_sub): Protect against bad relocations usage.
+       (do_t_mov_cmp): Likewise.
+
 2016-03-09  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>
 
        * config/tc-arm.c (neon_alignment_bit): Rename do_align to
index fa0651f7e4d7c3fa29ef6b6129c216149763b585..16426b7462b929bfcd137d5d961e0f1650d2ea09 100644 (file)
@@ -787,6 +787,7 @@ struct asm_opcode
 #define BAD_RANGE      _("branch out of range")
 #define BAD_FP16       _("selected processor does not support fp16 instruction")
 #define UNPRED_REG(R)  _("using " R " results in unpredictable behaviour")
+#define THUMB1_RELOC_ONLY  _("relocation valid in thumb1 code only")
 
 static struct hash_control * arm_ops_hsh;
 static struct hash_control * arm_cond_hsh;
@@ -8315,6 +8316,9 @@ do_adrl (void)
 static void
 do_arit (void)
 {
+  constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
+             && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
+             THUMB1_RELOC_ONLY);
   if (!inst.operands[1].present)
     inst.operands[1].reg = inst.operands[0].reg;
   inst.instruction |= inst.operands[0].reg << 12;
@@ -8972,6 +8976,9 @@ do_mlas (void)
 static void
 do_mov (void)
 {
+  constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
+             && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
+             THUMB1_RELOC_ONLY);
   inst.instruction |= inst.operands[0].reg << 12;
   encode_arm_shifter_operand (1);
 }
@@ -10472,9 +10479,12 @@ do_t_add_sub (void)
                  inst.instruction |= (Rd << 4) | Rs;
                  if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
                      || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
-                   inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
-                 if (inst.size_req != 2)
-                   inst.relax = opcode;
+                 {
+                   if (inst.size_req == 2)
+                     inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
+                   else
+                     inst.relax = opcode;
+                 }
                }
              else
                constraint (inst.size_req == 2, BAD_HIREG);
@@ -10482,6 +10492,9 @@ do_t_add_sub (void)
          if (inst.size_req == 4
              || (inst.size_req != 2 && !opcode))
            {
+             constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
+                         && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
+                         THUMB1_RELOC_ONLY);
              if (Rd == REG_PC)
                {
                  constraint (add, BAD_PC);
@@ -11826,17 +11839,21 @@ do_t_mov_cmp (void)
            {
              inst.instruction = THUMB_OP16 (opcode);
              inst.instruction |= Rn << 8;
-             if (inst.size_req == 2)
+             if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
+                 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
                {
-                 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
-                     || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
+                 if (inst.size_req == 2)
                    inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
+                 else
+                   inst.relax = opcode;
                }
-             else
-                 inst.relax = opcode;
            }
          else
            {
+             constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
+                         && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
+                         THUMB1_RELOC_ONLY);
+
              inst.instruction = THUMB_OP32 (inst.instruction);
              inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
              inst.instruction |= Rn << r0off;
index e9652f8f63e4d47c21716fa4aa9370b5fda98dbf..b94efeed553c17e7931e1a113f9833123ae09b80 100644 (file)
@@ -1,3 +1,11 @@
+2016-03-10  Mickael Guene  <mickael.guene@st.com>
+
+       PR gas/19744
+       * gas/arm/adds-thumb1-reloc-local-armv7-m.s: New.
+       * gas/arm/adds-thumb1-reloc-local-armv7-m.d: New.
+       * gas/arm/movs-thumb1-reloc-local-armv7-m.s: New.
+       * gas/arm/movs-thumb1-reloc-local-armv7-m.d: New.
+
 2016-02-16  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * gas/cfi/cfi-arc-1.d: New file.
diff --git a/gas/testsuite/gas/arm/adds-thumb1-reloc-local-armv7-m.d b/gas/testsuite/gas/arm/adds-thumb1-reloc-local-armv7-m.d
new file mode 100644 (file)
index 0000000..1bab56d
--- /dev/null
@@ -0,0 +1,16 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#skip: *-*-*coff *-*-pe *-*-wince *-*-*aout* *-*-netbsd *-*-riscix*
+#name: ADDS relocations against local symbols for armv7-m
+
+.*: +file format .*arm.*
+
+Disassembly of section .text:
+0[0-9a-f]+ <[^>]+> 3000        adds    r0, #0
+                       0: R_ARM_THM_ALU_ABS_G3_NC      bar
+0[0-9a-f]+ <[^>]+> 3000        adds    r0, #0
+                       2: R_ARM_THM_ALU_ABS_G2_NC      bar
+0[0-9a-f]+ <[^>]+> 3000        adds    r0, #0
+                       4: R_ARM_THM_ALU_ABS_G1_NC      bar
+0[0-9a-f]+ <[^>]+> 3000        adds    r0, #0
+                       6: R_ARM_THM_ALU_ABS_G0_NC      bar
+#...
diff --git a/gas/testsuite/gas/arm/adds-thumb1-reloc-local-armv7-m.s b/gas/testsuite/gas/arm/adds-thumb1-reloc-local-armv7-m.s
new file mode 100644 (file)
index 0000000..c5d95fc
--- /dev/null
@@ -0,0 +1,13 @@
+.arch armv7-m
+.text
+.syntax unified
+.thumb
+foo:
+adds r0, #:upper8_15:#bar
+adds r0, #:upper0_7:#bar
+adds r0, #:lower8_15:#bar
+adds r0, #:lower0_7:#bar
+
+.space 0x10000
+
+bar:
diff --git a/gas/testsuite/gas/arm/movs-thumb1-reloc-local-armv7-m.d b/gas/testsuite/gas/arm/movs-thumb1-reloc-local-armv7-m.d
new file mode 100644 (file)
index 0000000..1e94394
--- /dev/null
@@ -0,0 +1,16 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#skip: *-*-*coff *-*-pe *-*-wince *-*-*aout* *-*-netbsd *-*-riscix*
+#name: MOVS relocations against local symbols for armv7-m
+
+.*: +file format .*arm.*
+
+Disassembly of section .text:
+0[0-9a-f]+ <[^>]+> 2000        movs    r0, #0
+                       0: R_ARM_THM_ALU_ABS_G3_NC      bar
+0[0-9a-f]+ <[^>]+> 2000        movs    r0, #0
+                       2: R_ARM_THM_ALU_ABS_G2_NC      bar
+0[0-9a-f]+ <[^>]+> 2000        movs    r0, #0
+                       4: R_ARM_THM_ALU_ABS_G1_NC      bar
+0[0-9a-f]+ <[^>]+> 2000        movs    r0, #0
+                       6: R_ARM_THM_ALU_ABS_G0_NC      bar
+#...
diff --git a/gas/testsuite/gas/arm/movs-thumb1-reloc-local-armv7-m.s b/gas/testsuite/gas/arm/movs-thumb1-reloc-local-armv7-m.s
new file mode 100644 (file)
index 0000000..6699fc7
--- /dev/null
@@ -0,0 +1,13 @@
+.arch armv7-m
+.text
+.syntax unified
+.thumb
+foo:
+movs r0, #:upper8_15:#bar
+movs r0, #:upper0_7:#bar
+movs r0, #:lower8_15:#bar
+movs r0, #:lower0_7:#bar
+
+.space 0x10000
+
+bar:
index a9869f173dd8b3ca1d5064c4b4b9285ac105c022..4890e430dc61d016288e6af55b1e526e374be5ad 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-10  Mickael Guene  <mickael.guene@st.com>
+
+       PR gas/19744
+       * testsuite/ld-arm/arm-elf.exp: New tests.
+       * testsuite/ld-arm/thumb1-adds-armv7-m.s: New.
+       * testsuite/ld-arm/thumb1-movs-armv7-m.s: New.
+
 2016-03-10  Nick Clifton  <nickc@redhat.com>
 
        * scripttempl/elf32msp430.sc (.rodata): Remove spurious LONG(0).
index a2082a8dbc025f2e220b5c431ca9d20de8916593..0af32c09e3d612326c557433db3a3a8e111bb6e6 100644 (file)
@@ -235,6 +235,12 @@ set armelftests_common_3 {
     {"ADDS thumb1 relocations" "-static -T arm.ld" "" "" {thumb1-adds.s}
      {{objdump -dw thumb1-adds.d}}
      "thumb1-adds"}
+    {"MOVS thumb1 relocations for armv7-m target" "-static -T arm.ld" "" "" {thumb1-movs-armv7-m.s}
+     {{objdump -dw thumb1-movs.d}}
+     "thumb1-movs"}
+    {"ADDS thumb1 relocations for armv7-m target" "-static -T arm.ld" "" "" {thumb1-adds-armv7-m.s}
+     {{objdump -dw thumb1-adds.d}}
+     "thumb1-adds"}
 }
 
 run_ld_link_tests $armelftests_common_1
diff --git a/ld/testsuite/ld-arm/thumb1-adds-armv7-m.s b/ld/testsuite/ld-arm/thumb1-adds-armv7-m.s
new file mode 100644 (file)
index 0000000..9640072
--- /dev/null
@@ -0,0 +1,43 @@
+       .text
+       .arch armv7-m
+       .syntax unified
+       .global _start
+       .thumb_func
+       .type   _start, %function
+_start:
+       .thumb_func
+       .type   thumb1, %function
+thumb1:
+       adds r0, #:upper8_15:#thumb3
+       adds r1, #:upper0_7:#thumb3
+       adds r2, #:lower8_15:#thumb1
+       adds r3, #:lower0_7:#thumb1
+       adds r4, #:lower0_7:#thumb3
+       adds r5, #:lower8_15:#thumb3
+       adds r6, #:upper0_7:#thumb1
+       adds r7, #:upper8_15:#thumb1
+       .thumb_func
+       .type   thumb2, %function
+thumb2:
+       adds r0, #:upper8_15:#thumb3
+       adds r1, #:upper0_7:#(var2 + 1)
+       adds r2, #:lower8_15:#(thumb3 + 255)
+       adds r3, #:lower0_7:#(var1 + 0xaa)
+       adds r7, #:upper8_15:#var1 + 4
+       adds r6, #:upper0_7:#thumb3
+       adds r5, #:lower8_15:#var2 + 0xff
+       adds r4, #:lower0_7:#var2 - (-2)
+var1:
+       .byte 1
+var2:
+       .byte 2
+
+       .section .far, "ax", %progbits
+       .thumb_func
+       .type   thumb3, %function
+thumb3:
+       adds r0, #:upper8_15:#thumb1
+       adds r1, #:upper0_7:#thumb2
+       adds r2, #:lower8_15:#thumb3
+       adds r3, #:lower0_7:#thumb1
+
diff --git a/ld/testsuite/ld-arm/thumb1-movs-armv7-m.s b/ld/testsuite/ld-arm/thumb1-movs-armv7-m.s
new file mode 100644 (file)
index 0000000..ffb8273
--- /dev/null
@@ -0,0 +1,43 @@
+       .text
+       .arch armv7-m
+       .syntax unified
+       .global _start
+       .thumb_func
+       .type   _start, %function
+_start:
+       .thumb_func
+       .type   thumb1, %function
+thumb1:
+       movs r0, #:upper8_15:#thumb3
+       movs r1, #:upper0_7:#thumb3
+       movs r2, #:lower8_15:#thumb1
+       movs r3, #:lower0_7:#thumb1
+       movs r4, #:lower0_7:#thumb3
+       movs r5, #:lower8_15:#thumb3
+       movs r6, #:upper0_7:#thumb1
+       movs r7, #:upper8_15:#thumb1
+       .thumb_func
+       .type   thumb2, %function
+thumb2:
+       movs r0, #:upper8_15:#(thumb3 + 0)
+       movs r1, #:upper0_7:#(thumb2 + 1)
+       movs r2, #:lower8_15:#(var1 + 255)
+       movs r3, #:lower0_7:#var1
+       movs r7, #:upper8_15:#var1 + 4
+       movs r6, #:upper0_7:#var2
+       movs r5, #:lower8_15:#var2 + 0xff
+       movs r4, #:lower0_7:#var2 - (-1)
+var1:
+       .byte 1
+var2:
+       .byte 2
+
+       .section .far, "ax", %progbits
+       .thumb_func
+       .type   thumb3, %function
+thumb3:
+       movs r0, #:upper8_15:#thumb1
+       movs r1, #:upper0_7:#thumb2
+       movs r2, #:lower8_15:#thumb3
+       movs r3, #:lower0_7:#thumb1
+
This page took 0.047069 seconds and 4 git commands to generate.