Skip to content

Commit e5d6e09

Browse files
committed
[binutils, ARM, 5/16] BF insns infrastructure with new global reloc R_ARM_THM_BF16
This patch is part of a series of patches to add support for Armv8.1-M Mainline instructions to binutils. This adds infrastructure for the BF instructions which is one of the first instructions in Arm that have more than one relocations in them. This is the third infrastructure patch that adds a new relocation R_ARM_THM_BF16. The inconsistency between external R_ARM_THM_BF16 and internal BFD_RELOC_ARM_THUMB_BF17 is because internally we count the static bit-0 of the immediate and we don't externally. ChangeLog entries are as follows : *** bfd/ChangeLog *** 2019-04-15 Sudakshina Das <[email protected]> * reloc.c (BFD_RELOC_ARM_THUMB_BF17): New enum. * bfd-in2.h: Regenerated. * libbfd.h: Regenerated. * bfd-elf32-arm.c (elf32_arm_howto_table_1): New entry for R_ARM_THM_BF16. (elf32_arm_reloc_map elf32_arm_reloc_map): Map BFD_RELOC_ARM_THUMB_BF17 and R_ARM_THM_BF16 together. (get_value_helper): New reloc helper. (elf32_arm_final_link_relocate): New switch case for R_ARM_THM_BF16. *** elfcpp/ChangeLog *** 2019-04-15 Sudakshina Das <[email protected]> * arm.h (R_ARM_THM_BF16): New relocation code. *** gas/ChangeLog *** 2019-04-15 Sudakshina Das <[email protected]> * config/tc-arm.c (md_pcrel_from_section): New switch case for BFD_RELOC_ARM_THUMB_BF17. (md_appdy_fix): Likewise. (tc_gen_reloc): Likewise. *** include/ChangeLog *** 2019-04-15 Sudakshina Das <[email protected]> * elf/arm.h (START_RELOC_NUMBERS): New entry for R_ARM_THM_BF16. *** opcodes/ChangeLog *** 2019-04-15 Sudakshina Das <[email protected]> * arm-dis.c (print_insn_thumb32): Updated to accept new %W pattern.
1 parent e2b0ab5 commit e5d6e09

File tree

13 files changed

+211
-2
lines changed

13 files changed

+211
-2
lines changed

bfd/ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2019-04-15 Sudakshina Das <[email protected]>
2+
3+
* reloc.c (BFD_RELOC_ARM_THUMB_BF17): New enum.
4+
* bfd-in2.h: Regenerated.
5+
* libbfd.h: Regenerated.
6+
* bfd-elf32-arm.c (elf32_arm_howto_table_1): New entry for R_ARM_THM_BF16.
7+
(elf32_arm_reloc_map elf32_arm_reloc_map): Map BFD_RELOC_ARM_THUMB_BF17
8+
and R_ARM_THM_BF16 together.
9+
(get_value_helper): New reloc helper.
10+
(elf32_arm_final_link_relocate): New switch case for R_ARM_THM_BF16.
11+
112
2019-04-15 Sudakshina Das <[email protected]>
213

314
* reloc.c (BFD_RELOC_THUMB_PCREL_BRANCH5): New enum.

bfd/bfd-in2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3567,6 +3567,9 @@ field in the instruction. */
35673567
/* ARM 5-bit pc-relative branch for Branch Future instructions. */
35683568
BFD_RELOC_THUMB_PCREL_BRANCH5,
35693569

3570+
/* ARM 17-bit pc-relative branch for Branch Future instructions. */
3571+
BFD_RELOC_ARM_THUMB_BF17,
3572+
35703573
/* Thumb 7-, 9-, 12-, 20-, 23-, and 25-bit pc-relative branches.
35713574
The lowest bit must be zero and is not stored in the instruction.
35723575
Note that the corresponding ELF R_ARM_THM_JUMPnn constant has an

bfd/elf32-arm.c

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,20 @@ static reloc_howto_type elf32_arm_howto_table_1[] =
17421742
0x00000000, /* src_mask. */
17431743
0x00000000, /* dst_mask. */
17441744
FALSE), /* pcrel_offset. */
1745+
/* Relocations for Armv8.1-M Mainline. */
1746+
HOWTO (R_ARM_THM_BF16, /* type. */
1747+
0, /* rightshift. */
1748+
1, /* size (0 = byte, 1 = short, 2 = long). */
1749+
16, /* bitsize. */
1750+
TRUE, /* pc_relative. */
1751+
0, /* bitpos. */
1752+
complain_overflow_dont,/* do not complain_on_overflow. */
1753+
bfd_elf_generic_reloc, /* special_function. */
1754+
"R_ARM_THM_BF16", /* name. */
1755+
FALSE, /* partial_inplace. */
1756+
0x001f0ffe, /* src_mask. */
1757+
0x001f0ffe, /* dst_mask. */
1758+
TRUE), /* pcrel_offset. */
17451759
};
17461760

17471761
/* 160 onwards: */
@@ -2053,7 +2067,8 @@ static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
20532067
{BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC, R_ARM_THM_ALU_ABS_G3_NC},
20542068
{BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC, R_ARM_THM_ALU_ABS_G2_NC},
20552069
{BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC, R_ARM_THM_ALU_ABS_G1_NC},
2056-
{BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC, R_ARM_THM_ALU_ABS_G0_NC}
2070+
{BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC, R_ARM_THM_ALU_ABS_G0_NC},
2071+
{BFD_RELOC_ARM_THUMB_BF17, R_ARM_THM_BF16}
20572072
};
20582073

20592074
static reloc_howto_type *
@@ -10250,6 +10265,59 @@ identify_add_or_sub (bfd_vma insn)
1025010265
return 0;
1025110266
}
1025210267

10268+
/* Helper function to compute the Addend for Armv8.1-M Mainline relocations. */
10269+
static bfd_vma
10270+
get_value_helper (bfd_vma plt_offset,
10271+
asection *splt,
10272+
asection *input_section,
10273+
asection *sym_sec,
10274+
struct elf_link_hash_entry * h,
10275+
struct bfd_link_info *info,
10276+
bfd *input_bfd,
10277+
Elf_Internal_Rela *rel,
10278+
const char *sym_name,
10279+
unsigned char st_type,
10280+
struct elf32_arm_link_hash_table *globals,
10281+
bfd_boolean *unresolved_reloc_p)
10282+
{
10283+
bfd_vma value = 0;
10284+
enum arm_st_branch_type branch_type;
10285+
enum elf32_arm_stub_type stub_type = arm_stub_none;
10286+
struct elf32_arm_stub_hash_entry *stub_entry;
10287+
struct elf32_arm_link_hash_entry *hash
10288+
= (struct elf32_arm_link_hash_entry *)h;
10289+
10290+
10291+
if (plt_offset != (bfd_vma) -1)
10292+
{
10293+
value = (splt->output_section->vma
10294+
+ splt->output_offset
10295+
+ plt_offset);
10296+
value -= PLT_THUMB_STUB_SIZE;
10297+
*unresolved_reloc_p = FALSE;
10298+
}
10299+
10300+
stub_type = arm_type_of_stub (info, input_section, rel,
10301+
st_type, &branch_type,
10302+
hash, value, sym_sec,
10303+
input_bfd, sym_name);
10304+
10305+
if (stub_type != arm_stub_none)
10306+
{
10307+
stub_entry = elf32_arm_get_stub_entry (input_section,
10308+
sym_sec, h,
10309+
rel, globals,
10310+
stub_type);
10311+
if (stub_entry != NULL)
10312+
{
10313+
value = (stub_entry->stub_offset
10314+
+ stub_entry->stub_sec->output_offset
10315+
+ stub_entry->stub_sec->output_section->vma);
10316+
}
10317+
}
10318+
return value;
10319+
}
10320+
1025310321
/* Perform a relocation as part of a final link. */
1025410322

1025510323
static bfd_reloc_status_type
@@ -12856,6 +12924,51 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto,
1285612924
*unresolved_reloc_p = FALSE;
1285712925
return bfd_reloc_ok;
1285812926

12927+
case R_ARM_THM_BF16:
12928+
{
12929+
bfd_vma relocation;
12930+
bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
12931+
bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
12932+
12933+
if (globals->use_rel)
12934+
{
12935+
bfd_vma immA = (upper_insn & 0x001f);
12936+
bfd_vma immB = (lower_insn & 0x07fe) >> 1;
12937+
bfd_vma immC = (lower_insn & 0x0800) >> 11;
12938+
addend = (immA << 12);
12939+
addend |= (immB << 2);
12940+
addend |= (immC << 1);
12941+
addend |= 1;
12942+
/* Sign extend. */
12943+
addend = (addend & 0x10000) ? addend - (1 << 17) : addend;
12944+
}
12945+
12946+
value = get_value_helper (plt_offset, splt, input_section, sym_sec, h,
12947+
info, input_bfd, rel, sym_name, st_type,
12948+
globals, unresolved_reloc_p);
12949+
12950+
relocation = value + addend;
12951+
relocation -= (input_section->output_section->vma
12952+
+ input_section->output_offset
12953+
+ rel->r_offset);
12954+
12955+
/* Put RELOCATION back into the insn. */
12956+
{
12957+
bfd_vma immA = (relocation & 0x0001f000) >> 12;
12958+
bfd_vma immB = (relocation & 0x00000ffc) >> 2;
12959+
bfd_vma immC = (relocation & 0x00000002) >> 1;
12960+
12961+
upper_insn = (upper_insn & 0xffe0) | immA;
12962+
lower_insn = (lower_insn & 0xf001) | (immC << 11) | (immB << 1);
12963+
}
12964+
12965+
/* Put the relocated value back in the object file: */
12966+
bfd_put_16 (input_bfd, upper_insn, hit_data);
12967+
bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
12968+
12969+
return bfd_reloc_ok;
12970+
}
12971+
1285912972
default:
1286012973
return bfd_reloc_notsupported;
1286112974
}

bfd/libbfd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
15301530
"BFD_RELOC_ARM_PCREL_CALL",
15311531
"BFD_RELOC_ARM_PCREL_JUMP",
15321532
"BFD_RELOC_THUMB_PCREL_BRANCH5",
1533+
"BFD_RELOC_ARM_THUMB_BF17",
15331534
"BFD_RELOC_THUMB_PCREL_BRANCH7",
15341535
"BFD_RELOC_THUMB_PCREL_BRANCH9",
15351536
"BFD_RELOC_THUMB_PCREL_BRANCH12",

bfd/reloc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,6 +3019,11 @@ ENUM
30193019
ENUMDOC
30203020
ARM 5-bit pc-relative branch for Branch Future instructions.
30213021
3022+
ENUM
3023+
BFD_RELOC_ARM_THUMB_BF17
3024+
ENUMDOC
3025+
ARM 17-bit pc-relative branch for Branch Future instructions.
3026+
30223027
ENUM
30233028
BFD_RELOC_THUMB_PCREL_BRANCH7
30243029
ENUMX

elfcpp/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2019-04-15 Sudakshina Das <[email protected]>
2+
3+
* arm.h (R_ARM_THM_BF16): New relocation code.
4+
15
2018-06-24 Nick Clifton <[email protected]>
26

37
2.32 branch created.

elfcpp/arm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ enum
194194
R_ARM_ME_TOO = 128, // Obsolete
195195
R_ARM_THM_TLS_DESCSEQ16 = 129,// Static Thumb16
196196
R_ARM_THM_TLS_DESCSEQ32 = 130,// Static Thumb32
197-
// 131 - 139 Unallocated
197+
// 131 - 135 Unallocated
198+
// Relocations for Armv8.1-M Mainline (BF/BFL)
199+
R_ARM_THM_BF16 = 136, // Static Thumb32 ((S + A) | T) – P
200+
// 139 Unallocated
198201
// 140 - 159 Dynamic Reserved for future allocation
199202
R_ARM_IRELATIVE = 160, // Dynamic
200203
// 161 - 255 Unallocated

gas/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2019-04-15 Sudakshina Das <[email protected]>
2+
3+
* config/tc-arm.c (md_pcrel_from_section): New switch case for
4+
BFD_RELOC_ARM_THUMB_BF17.
5+
(md_appdy_fix): Likewise.
6+
(tc_gen_reloc): Likewise.
7+
18
2019-04-15 Sudakshina Das <[email protected]>
29

310
* config/tc-arm.c (ARM_IT_MAX_RELOCS): New macro.

gas/config/tc-arm.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22853,6 +22853,7 @@ md_pcrel_from_section (fixS * fixP, segT seg)
2285322853
case BFD_RELOC_THUMB_PCREL_BRANCH12:
2285422854
case BFD_RELOC_THUMB_PCREL_BRANCH20:
2285522855
case BFD_RELOC_THUMB_PCREL_BRANCH25:
22856+
case BFD_RELOC_ARM_THUMB_BF17:
2285622857
return base + 4;
2285722858

2285822859
case BFD_RELOC_THUMB_PCREL_BRANCH23:
@@ -24750,6 +24751,39 @@ md_apply_fix (fixS * fixP,
2475024751
}
2475124752
break;
2475224753

24754+
case BFD_RELOC_ARM_THUMB_BF17:
24755+
if (fixP->fx_addsy
24756+
&& (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24757+
&& !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24758+
&& ARM_IS_FUNC (fixP->fx_addsy)
24759+
&& ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
24760+
{
24761+
/* Force a relocation for a branch 17 bits wide. */
24762+
fixP->fx_done = 0;
24763+
}
24764+
24765+
if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
24766+
as_bad_where (fixP->fx_file, fixP->fx_line,
24767+
BAD_BRANCH_OFF);
24768+
24769+
if (fixP->fx_done || !seg->use_rela_p)
24770+
{
24771+
offsetT newval2;
24772+
addressT immA, immB, immC;
24773+
24774+
immA = (value & 0x0001f000) >> 12;
24775+
immB = (value & 0x00000ffc) >> 2;
24776+
immC = (value & 0x00000002) >> 1;
24777+
24778+
newval = md_chars_to_number (buf, THUMB_SIZE);
24779+
newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24780+
newval |= immA;
24781+
newval2 |= (immC << 11) | (immB << 1);
24782+
md_number_to_chars (buf, newval, THUMB_SIZE);
24783+
md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24784+
}
24785+
break;
24786+
2475324787
case BFD_RELOC_ARM_V4BX:
2475424788
/* This will need to go in the object file. */
2475524789
fixP->fx_done = 0;
@@ -24932,6 +24966,7 @@ tc_gen_reloc (asection *section, fixS *fixp)
2493224966
case BFD_RELOC_ARM_GOTFUNCDESC:
2493324967
case BFD_RELOC_ARM_GOTOFFFUNCDESC:
2493424968
case BFD_RELOC_ARM_FUNCDESC:
24969+
case BFD_RELOC_ARM_THUMB_BF17:
2493524970
code = fixp->fx_r_type;
2493624971
break;
2493724972

include/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2019-04-15 Sudakshina Das <[email protected]>
2+
3+
* elf/arm.h (START_RELOC_NUMBERS): New entry for R_ARM_THM_BF16.
4+
15
2019-04-15 Thomas Preud'homme <[email protected]>
26

37
* elf/arm.h (TAG_CPU_ARCH_V8_1M_MAIN): new macro.

0 commit comments

Comments
 (0)