+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".
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);
}
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);
}
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 $< > $@
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 \
@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 \
@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 \
@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 $< > $@
" 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
--- /dev/null
+# 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
--- /dev/null
+/* 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) }
+}
--- /dev/null
+# 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
--- /dev/null
+/* 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) }
+}