summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Preud'homme <thomas.preudhomme@arm.com>2016-09-22 16:37:38 +0100
committerThomas Preud'homme <thomas.preudhomme@arm.com>2016-09-22 16:45:37 +0100
commit10f612b5002a9c2ecbe3ae4205d4eab413771f0a (patch)
tree1c29f4f0ae8a648a0d5234b493d2710a19fb40f6
parenta08f609340d6d2b69d981f72b7900398f3816346 (diff)
downloadbinutils-gdb-10f612b5002a9c2ecbe3ae4205d4eab413771f0a.tar.gz
Fix Thumb-2 BL detection
2016-09-22 Andre Vieira <andre.simoesdiasvieira@arm.com> Backport from mainline 2016-07-01 Thomas Preud'homme <thomas.preudhomme@arm.com> bfd/ * elf32-arm.c (using_thumb2_bl): New function. (arm_type_of_stub): Declare thumb2 variable together and change type to bfd_boolean. Use using_thumb2_bl () to determine whether THM_MAX_FWD_BRANCH_OFFSET or THM2_MAX_FWD_BRANCH_OFFSET should be checked for BL range. (elf32_arm_final_link_relocate): Use using_thumb2_bl () to determine the bit size of BL offset. ld/ * testsuite/ld-arm/arm-elf.exp (Thumb-2 BL): Assemble for ARMv7. (Thumb-2 BL on ARMv6-M): New testcase. * testsuite/ld-arm/thumb2-bl.d: Do not try to match testcase filename. * testsuite/ld-arm/thumb2-bl.s: Do not select architecture.
-rw-r--r--bfd/ChangeLog.arm13
-rw-r--r--bfd/elf32-arm.c30
-rw-r--r--ld/ChangeLog.arm10
-rw-r--r--ld/testsuite/ld-arm/arm-elf.exp5
-rw-r--r--ld/testsuite/ld-arm/thumb2-bl.d2
-rw-r--r--ld/testsuite/ld-arm/thumb2-bl.s1
6 files changed, 52 insertions, 9 deletions
diff --git a/bfd/ChangeLog.arm b/bfd/ChangeLog.arm
index e96a7f66026..b2c63d0da37 100644
--- a/bfd/ChangeLog.arm
+++ b/bfd/ChangeLog.arm
@@ -1,6 +1,19 @@
2016-09-22 Andre Vieira <andre.simoesdiasvieira@arm.com>
Backport from mainline
+ 2016-07-01 Thomas Preud'homme <thomas.preudhomme@arm.com>
+
+ * elf32-arm.c (using_thumb2_bl): New function.
+ (arm_type_of_stub): Declare thumb2 variable together and change type
+ to bfd_boolean. Use using_thumb2_bl () to determine whether
+ THM_MAX_FWD_BRANCH_OFFSET or THM2_MAX_FWD_BRANCH_OFFSET should be
+ checked for BL range.
+ (elf32_arm_final_link_relocate): Use using_thumb2_bl () to determine
+ the bit size of BL offset.
+
+2016-09-22 Andre Vieira <andre.simoesdiasvieira@arm.com>
+
+ Backport from mainline
2016-06-14 Thomas Preud'homme <thomas.preudhomme@arm.com>
* elf32-arm.c (using_thumb_only): Force review of arch check logic for
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 568889829fa..4c8c9f60b47 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -3539,6 +3539,24 @@ using_thumb2 (struct elf32_arm_link_hash_table *globals)
|| arch == TAG_CPU_ARCH_V8M_MAIN);
}
+/* Determine whether Thumb-2 BL instruction is available. */
+
+static bfd_boolean
+using_thumb2_bl (struct elf32_arm_link_hash_table *globals)
+{
+ int arch =
+ bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, Tag_CPU_arch);
+
+ /* Force return logic to be reviewed for each new architecture. */
+ BFD_ASSERT (arch <= TAG_CPU_ARCH_V8
+ || arch == TAG_CPU_ARCH_V8M_BASE
+ || arch == TAG_CPU_ARCH_V8M_MAIN);
+
+ /* Architecture was introduced after ARMv6T2 (eg. ARMv6-M). */
+ return (arch == TAG_CPU_ARCH_V6T2
+ || arch >= TAG_CPU_ARCH_V7);
+}
+
/* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
.rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
hash table. */
@@ -3791,8 +3809,7 @@ arm_type_of_stub (struct bfd_link_info *info,
bfd_signed_vma branch_offset;
unsigned int r_type;
struct elf32_arm_link_hash_table * globals;
- int thumb2;
- int thumb_only;
+ bfd_boolean thumb2, thumb2_bl, thumb_only;
enum elf32_arm_stub_type stub_type = arm_stub_none;
int use_plt = 0;
enum arm_st_branch_type branch_type = *actual_branch_type;
@@ -3807,8 +3824,8 @@ arm_type_of_stub (struct bfd_link_info *info,
return stub_type;
thumb_only = using_thumb_only (globals);
-
thumb2 = using_thumb2 (globals);
+ thumb2_bl = using_thumb2_bl (globals);
/* Determine where the call point is. */
location = (input_sec->output_offset
@@ -3875,10 +3892,10 @@ arm_type_of_stub (struct bfd_link_info *info,
but only if this call is not through a PLT entry. Indeed,
PLT stubs handle mode switching already.
*/
- if ((!thumb2
+ if ((!thumb2_bl
&& (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
|| (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
- || (thumb2
+ || (thumb2_bl
&& (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
|| (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
|| (thumb2
@@ -10444,6 +10461,7 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto,
bfd_signed_vma signed_check;
int bitsize;
const int thumb2 = using_thumb2 (globals);
+ const int thumb2_bl = using_thumb2_bl (globals);
/* A branch to an undefined weak symbol is turned into a jump to
the next instruction unless a PLT entry will be created.
@@ -10620,7 +10638,7 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto,
this relocation according to whether we're relocating for
Thumb-2 or not. */
bitsize = howto->bitsize;
- if (!thumb2)
+ if (!thumb2_bl)
bitsize -= 2;
reloc_signed_max = (1 << (bitsize - 1)) - 1;
reloc_signed_min = ~reloc_signed_max;
diff --git a/ld/ChangeLog.arm b/ld/ChangeLog.arm
index 5ed9123f59d..c4fad0f9457 100644
--- a/ld/ChangeLog.arm
+++ b/ld/ChangeLog.arm
@@ -1,3 +1,13 @@
+2016-09-22 Andre Vieira <andre.simoesdiasvieira@arm.com>
+
+ Backport from mainline
+ 2016-07-01 Thomas Preud'homme <thomas.preudhomme@arm.com>
+
+ * testsuite/ld-arm/arm-elf.exp (Thumb-2 BL): Assemble for ARMv7.
+ (Thumb-2 BL on ARMv6-M): New testcase.
+ * testsuite/ld-arm/thumb2-bl.d: Do not try to match testcase filename.
+ * testsuite/ld-arm/thumb2-bl.s: Do not select architecture.
+
2016-09-21 Andre Vieira <andre.simoesdiasvieira@arm.com>
Backport from mainline
diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
index 4227cb4f2f1..b8ece342acb 100644
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -576,9 +576,12 @@ set armeabitests_nonacl {
{{objdump -d fix-arm1176-off.d}}
"fix-arm1176-6"}
- {"Thumb-2 BL" "-Ttext 0x1000 --section-start .foo=0x1001000" "" "" {thumb2-bl.s}
+ {"Thumb-2 BL" "-Ttext 0x1000 --section-start .foo=0x1001000" "" "-march=armv7" {thumb2-bl.s}
{{objdump -dr thumb2-bl.d}}
"thumb2-bl"}
+ {"Thumb-2 BL on ARMv6-M" "-Ttext 0x1000 --section-start .foo=0x1001000" "" "-march=armv6-m" {thumb2-bl.s}
+ {{objdump -dr thumb2-bl.d}}
+ "thumb2-armv6m-bl"}
{"Thumb-2 Interworked branch" "-T arm.ld" "" "" {thumb2-b-interwork.s}
{{objdump -dr thumb2-b-interwork.d}}
"thumb2-b-interwork"}
diff --git a/ld/testsuite/ld-arm/thumb2-bl.d b/ld/testsuite/ld-arm/thumb2-bl.d
index 298a0446a0c..8dab0c048f4 100644
--- a/ld/testsuite/ld-arm/thumb2-bl.d
+++ b/ld/testsuite/ld-arm/thumb2-bl.d
@@ -1,5 +1,5 @@
-.*thumb2-bl: file format elf32-.*arm.*
+.*: file format elf32-.*arm.*
Disassembly of section .text:
diff --git a/ld/testsuite/ld-arm/thumb2-bl.s b/ld/testsuite/ld-arm/thumb2-bl.s
index ddb1cd33fcb..80af8108b8f 100644
--- a/ld/testsuite/ld-arm/thumb2-bl.s
+++ b/ld/testsuite/ld-arm/thumb2-bl.s
@@ -1,7 +1,6 @@
@ Test to ensure that a Thumb-2 BL works with an offset that is
@ not permissable for Thumb-1.
- .arch armv7
.global _start
.syntax unified