2011-06-27 Doug Kwan <dougkwan@google.com>
authorDoug Kwan <dougkwan@google.com>
Mon, 27 Jun 2011 17:53:32 +0000 (17:53 +0000)
committerDoug Kwan <dougkwan@google.com>
Mon, 27 Jun 2011 17:53:32 +0000 (17:53 +0000)
* arm.cc (Arm_relocate_functions::thm_jump8,
Arm_relocate_functions::thm_jump11): Use a wider signed
type to compute offset.
* testsuite/Makefile.am: Add new tests arm_thm_jump11 and
arm_thm_jump8.
* testsuite/Makefile.in: Regenerate.
* testsuite/arm_branch_in_range.sh: Check test results of
arm_thm_jump11 and arm_thm_jump8.
* testsuite/arm_thm_jump11.s: New test source file.
* testsuite/arm_thm_jump11.t: New linker script.
* testsuite/arm_thm_jump8.s: New test source file.
* testsuite/arm_thm_jump8.t: New linker script.

gold/ChangeLog
gold/arm.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/arm_branch_in_range.sh
gold/testsuite/arm_thm_jump11.s [new file with mode: 0644]
gold/testsuite/arm_thm_jump11.t [new file with mode: 0644]
gold/testsuite/arm_thm_jump8.s [new file with mode: 0644]
gold/testsuite/arm_thm_jump8.t [new file with mode: 0644]

index ff39a18f38bae62f735504dedad1851d1099774c..6400f0a9158271f0be8d5a4e4994949491374f85 100644 (file)
@@ -1,3 +1,18 @@
+2011-06-27  Doug Kwan  <dougkwan@google.com>
+
+       * arm.cc (Arm_relocate_functions::thm_jump8,
+       Arm_relocate_functions::thm_jump11): Use a wider signed
+       type to compute offset.
+       * testsuite/Makefile.am: Add new tests arm_thm_jump11 and
+       arm_thm_jump8.
+       * testsuite/Makefile.in: Regenerate.
+       * testsuite/arm_branch_in_range.sh: Check test results of
+       arm_thm_jump11 and arm_thm_jump8.
+       * testsuite/arm_thm_jump11.s: New test source file.
+       * testsuite/arm_thm_jump11.t: New linker script.
+       * testsuite/arm_thm_jump8.s: New test source file.
+       * testsuite/arm_thm_jump8.t: New linker script.
+
 2011-06-24  Ian Lance Taylor  <iant@google.com>
 
        * layout.cc: Include "object.h".
index 98e82b970e7f6281cddcc5d2d65f95bda3068186..c8732e07ee20b0d0050a2e10ad153a8c90bfb68c 100644 (file)
@@ -3356,13 +3356,14 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
            Arm_address address)
   {
     typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
-    typedef typename elfcpp::Swap<16, big_endian>::Valtype Reltype;
     Valtype* wv = reinterpret_cast<Valtype*>(view);
     Valtype val = elfcpp::Swap<16, big_endian>::readval(wv);
-    Reltype addend = utils::sign_extend<8>((val & 0x00ff) << 1);
-    Reltype x = (psymval->value(object, addend) - address);
-    elfcpp::Swap<16, big_endian>::writeval(wv, (val & 0xff00) | ((x & 0x01fe) >> 1));
-    return (utils::has_overflow<8>(x)
+    int32_t addend = utils::sign_extend<8>((val & 0x00ff) << 1);
+    int32_t x = (psymval->value(object, addend) - address);
+    elfcpp::Swap<16, big_endian>::writeval(wv, ((val & 0xff00)
+                                                | ((x & 0x01fe) >> 1)));
+    // We do a 9-bit overflow check because x is right-shifted by 1 bit.
+    return (utils::has_overflow<9>(x)
            ? This::STATUS_OVERFLOW
            : This::STATUS_OKAY);
   }
@@ -3375,13 +3376,14 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
            Arm_address address)
   {
     typedef typename elfcpp::Swap<16, big_endian>::Valtype Valtype;
-    typedef typename elfcpp::Swap<16, big_endian>::Valtype Reltype;
     Valtype* wv = reinterpret_cast<Valtype*>(view);
     Valtype val = elfcpp::Swap<16, big_endian>::readval(wv);
-    Reltype addend = utils::sign_extend<11>((val & 0x07ff) << 1);
-    Reltype x = (psymval->value(object, addend) - address);
-    elfcpp::Swap<16, big_endian>::writeval(wv, (val & 0xf800) | ((x & 0x0ffe) >> 1));
-    return (utils::has_overflow<11>(x)
+    int32_t addend = utils::sign_extend<11>((val & 0x07ff) << 1);
+    int32_t x = (psymval->value(object, addend) - address);
+    elfcpp::Swap<16, big_endian>::writeval(wv, ((val & 0xf800)
+                                                | ((x & 0x0ffe) >> 1)));
+    // We do a 12-bit overflow check because x is right-shifted by 1 bit.
+    return (utils::has_overflow<12>(x)
            ? This::STATUS_OVERFLOW
            : This::STATUS_OKAY);
   }
index d075cdc076c10b26bd1e4a678b4338f6ebd2c98c..739523ab2e34e4ec091e685da5d66569e0822e24 100644 (file)
@@ -2027,7 +2027,8 @@ check_DATA += arm_bl_in_range.stdout arm_bl_out_of_range.stdout \
        thumb2_bl_in_range.stdout thumb2_bl_out_of_range.stdout \
        thumb_blx_in_range.stdout thumb_blx_out_of_range.stdout \
        thumb2_blx_in_range.stdout thumb2_blx_out_of_range.stdout \
-       thumb_bl_out_of_range_local.stdout
+       thumb_bl_out_of_range_local.stdout arm_thm_jump11.stdout \
+       arm_thm_jump8.stdout
 
 arm_bl_in_range.stdout: arm_bl_in_range
        $(TEST_OBJDUMP) -D $< > $@
@@ -2128,10 +2129,29 @@ thumb_bl_out_of_range_local: thumb_bl_out_of_range_local.o ../ld-new
 thumb_bl_out_of_range_local.o: thumb_bl_out_of_range_local.s
        $(TEST_AS) -o $@ -march=armv5te $<
 
+arm_thm_jump11.stdout: arm_thm_jump11
+       $(TEST_OBJDUMP) -D $< > $@
+
+arm_thm_jump11: arm_thm_jump11.o ../ld-new
+       ../ld-new -T $(srcdir)/arm_thm_jump11.t -o $@ $<
+
+arm_thm_jump11.o: arm_thm_jump11.s
+       $(TEST_AS) -o $@ $<
+
+arm_thm_jump8.stdout: arm_thm_jump8
+       $(TEST_OBJDUMP) -D $< > $@
+
+arm_thm_jump8: arm_thm_jump8.o ../ld-new
+       ../ld-new -T $(srcdir)/arm_thm_jump8.t -o $@ $<
+
+arm_thm_jump8.o: arm_thm_jump8.s
+       $(TEST_AS) -o $@ $<
+
 MOSTLYCLEANFILES += arm_bl_in_range arm_bl_out_of_range thumb_bl_in_range \
        thumb_bl_out_of_range thumb2_bl_in_range thumb2_bl_out_of_range \
        thumb_blx_in_range thumb_blx_out_of_range thumb2_blx_in_range \
-       thumb2_blx_out_of_range thumb_bl_out_of_range_local
+       thumb2_blx_out_of_range thumb_bl_out_of_range_local arm_thm_jump11 \
+       arm_thm_jump8
 
 check_SCRIPTS += arm_fix_v4bx.sh
 check_DATA += arm_fix_v4bx.stdout arm_fix_v4bx_interworking.stdout \
index 10bce4e94a1a9731db116608db82de1cea6a59ab..971d8c4c21fe347c03ab06fe13e1d80e08874d26 100644 (file)
@@ -495,6 +495,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ thumb2_blx_in_range.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ thumb2_blx_out_of_range.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ thumb_bl_out_of_range_local.stdout \
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_thm_jump11.stdout \
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_thm_jump8.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_fix_v4bx.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_fix_v4bx_interworking.stdout \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_no_fix_v4bx.stdout \
@@ -521,6 +523,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ thumb2_blx_in_range \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ thumb2_blx_out_of_range \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ thumb_bl_out_of_range_local \
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_thm_jump11 \
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_thm_jump8 \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_fix_v4bx \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_fix_v4bx_interworking \
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ arm_no_fix_v4bx \
@@ -4916,6 +4920,24 @@ uninstall-am:
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@thumb_bl_out_of_range_local.o: thumb_bl_out_of_range_local.s
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -o $@ -march=armv5te $<
 
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_thm_jump11.stdout: arm_thm_jump11
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_OBJDUMP) -D $< > $@
+
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_thm_jump11: arm_thm_jump11.o ../ld-new
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new -T $(srcdir)/arm_thm_jump11.t -o $@ $<
+
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_thm_jump11.o: arm_thm_jump11.s
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -o $@ $<
+
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_thm_jump8.stdout: arm_thm_jump8
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_OBJDUMP) -D $< > $@
+
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_thm_jump8: arm_thm_jump8.o ../ld-new
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new -T $(srcdir)/arm_thm_jump8.t -o $@ $<
+
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_thm_jump8.o: arm_thm_jump8.s
+@DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -o $@ $<
+
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@arm_fix_v4bx.stdout: arm_fix_v4bx
 @DEFAULT_TARGET_ARM_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_OBJDUMP) -D -j.text $< > $@
 
index 43b50c6a1fdc691287fc70bcfb00aa3feb151273..dc6f36f39e498c461816d13d939a2333e11d7c09 100755 (executable)
@@ -61,4 +61,13 @@ check thumb2_blx_in_range.stdout \
  " 2000006:    f400 c000       blx     1000008 <_backward_target>"
 check thumb2_blx_in_range.stdout \
  " 200000c:    f3ff c7fe       blx     300000c <_forward_target>"
+check arm_thm_jump11.stdout \
+ "    8804:    e400            b.n     8008 <_backward_target>"
+check arm_thm_jump11.stdout \
+ "    8806:    e3ff            b.n     9008 <_forward_target>"
+check arm_thm_jump8.stdout \
+ "    8104:    d080            beq.n   8008 <_backward_target>"
+check arm_thm_jump8.stdout \
+ "    8106:    d07f            beq.n   8208 <_forward_target>"
+
 exit 0
diff --git a/gold/testsuite/arm_thm_jump11.s b/gold/testsuite/arm_thm_jump11.s
new file mode 100644 (file)
index 0000000..41f1ce7
--- /dev/null
@@ -0,0 +1,57 @@
+# arm_thm_jump11.s
+# Test R_ARM_THM_JUMP11 relocations just within the branch range limits.
+       .syntax unified
+       .arch   armv5te
+
+       .section        .text.pre,"x"
+
+# Add padding so that target is just in branch range. 
+       .space  8
+
+       .global _backward_target
+       .code   16
+       .thumb_func
+       .type   _backword_target, %function
+_backward_target:
+       bx      lr
+       .size   _backward_target, .-_backward_target
+       
+       .text
+
+# Define _start so that linker does not complain.
+       .global _start
+       .code   32
+       .align  2
+       .type   _start, %function
+_start:
+       bx      lr
+       .size   _start, .-_start
+
+       .global _backward_test
+       .code   16
+       .thumb_func
+       .type   _backward_test, %function
+_backward_test:
+       b.n     _backward_target
+       .size   _backward_test, .-_backward_test
+
+       .global _forward_test
+       .code   16
+       .thumb_func
+       .type   _forward_test, %function
+_forward_test:
+       b.n     _forward_target
+       .size   _forward_test, .-_forward_test
+       
+       .section        .text.post,"x"
+
+# Add padding so that target is just in branch range. 
+       .space  8
+
+       .global _forward_target
+       .code   16
+       .thumb_func
+       .type   _forward_target, %function
+_forward_target:
+       bx      lr
+       .size   _forward_target, .-_forward_target
diff --git a/gold/testsuite/arm_thm_jump11.t b/gold/testsuite/arm_thm_jump11.t
new file mode 100644 (file)
index 0000000..2ec4143
--- /dev/null
@@ -0,0 +1,36 @@
+/* arm_thm_jump11.t -- linker script to test R_ARM_THM_JUMP11 relocation.
+
+   Copyright 2011 Free Software Foundation, Inc.
+   Written by Doug Kwan <dougkwan@google.com>.
+
+   This file is part of gold.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+SECTIONS
+{
+  . = 0x8000;
+
+  .text.pre : { *(.text.pre) }
+  . = ALIGN(0x800);
+  .text : { *(.text) }
+  . = ALIGN(0x800);
+  .text.post : { *(.text.post) }
+  . += 0x1000;
+  .data : { *(.data) }
+  .bss : { *(.bss) }
+  .ARM.attributes : { *(.ARM.attributes) }
+}
diff --git a/gold/testsuite/arm_thm_jump8.s b/gold/testsuite/arm_thm_jump8.s
new file mode 100644 (file)
index 0000000..540a243
--- /dev/null
@@ -0,0 +1,57 @@
+# arm_thm_jump8.s
+# Test R_ARM_THM_JUMP8 relocations just within the branch range limits.
+       .syntax unified
+       .arch   armv5te
+
+       .section        .text.pre,"x"
+
+# Add padding so that target is just in branch range. 
+       .space  8
+
+       .global _backward_target
+       .code   16
+       .thumb_func
+       .type   _backword_target, %function
+_backward_target:
+       bx      lr
+       .size   _backward_target, .-_backward_target
+       
+       .text
+
+# Define _start so that linker does not complain.
+       .global _start
+       .code   32
+       .align  2
+       .type   _start, %function
+_start:
+       bx      lr
+       .size   _start, .-_start
+
+       .global _backward_test
+       .code   16
+       .thumb_func
+       .type   _backward_test, %function
+_backward_test:
+       beq.n   _backward_target
+       .size   _backward_test, .-_backward_test
+
+       .global _forward_test
+       .code   16
+       .thumb_func
+       .type   _forward_test, %function
+_forward_test:
+       beq.n   _forward_target
+       .size   _forward_test, .-_forward_test
+       
+       .section        .text.post,"x"
+
+# Add padding so that target is just in branch range. 
+       .space  8
+
+       .global _forward_target
+       .code   16
+       .thumb_func
+       .type   _forward_target, %function
+_forward_target:
+       bx      lr
+       .size   _forward_target, .-_forward_target
diff --git a/gold/testsuite/arm_thm_jump8.t b/gold/testsuite/arm_thm_jump8.t
new file mode 100644 (file)
index 0000000..fa674b4
--- /dev/null
@@ -0,0 +1,36 @@
+/* arm_thm_jump8.t -- linker script to test R_ARM_THM_JUMP8 relocation.
+
+   Copyright 2011 Free Software Foundation, Inc.
+   Written by Doug Kwan <dougkwan@google.com>.
+
+   This file is part of gold.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+SECTIONS
+{
+  . = 0x8000;
+
+  .text.pre : { *(.text.pre) }
+  . = ALIGN(0x100);
+  .text : { *(.text) }
+  . = ALIGN(0x100);
+  .text.post : { *(.text.post) }
+  . += 0x1000;
+  .data : { *(.data) }
+  .bss : { *(.bss) }
+  .ARM.attributes : { *(.ARM.attributes) }
+}