1 From c7cd291722779c9d4703ed0010388fe394c644c8 Mon Sep 17 00:00:00 2001
2 From: Siddhesh Poyarekar <siddesh.poyarekar@arm.com>
3 Date: Tue, 1 Sep 2020 14:25:52 +0530
4 Subject: [PATCH] aarch64: Return an error on conditional branch to an undefined symbol
6 The fix in 7e05773767820b441b23a16628b55c98cb1aef46 introduced a PLT
7 for conditional jumps when the target symbol is undefined. This is
8 incorrect because conditional branch relocations are not allowed to
9 clobber IP0/IP1 and hence, should not result in a dynamic relocation.
11 Revert that change and in its place, issue an error when the target
16 2020-09-10 Siddhesh Poyarekar <siddesh.poyarekar@arm.com>
18 * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Revert
19 changes in 7e05773767820b441b23a16628b55c98cb1aef46. Set
20 error for undefined symbol in BFD_RELOC_AARCH64_BRANCH19 and
21 BFD_RELOC_AARCH64_TSTBR14 relocations.
25 2020-09-10 Siddhesh Poyarekar <siddesh.poyarekar@arm.com>
27 * testsuite/ld-aarch64/emit-relocs-560.d: Expect error instead
30 Upstream-Status: Backport [https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=c7cd291722779c9d4703ed0010388fe394c644c8]
31 Signed-off-by: Khem Raj <raj.khem@gmail.com>
33 bfd/ChangeLog | 7 +++++
34 bfd/elfnn-aarch64.c | 37 ++++++++++++-----------
36 ld/testsuite/ld-aarch64/emit-relocs-560.d | 7 +----
37 4 files changed, 32 insertions(+), 24 deletions(-)
39 diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
40 index 5b4c189b593..a9924e7ec56 100644
41 --- a/bfd/elfnn-aarch64.c
42 +++ b/bfd/elfnn-aarch64.c
43 @@ -5447,7 +5447,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
44 bfd_vma orig_value = value;
45 bfd_boolean resolved_to_zero;
46 bfd_boolean abs_symbol_p;
47 - bfd_boolean via_plt_p;
49 globals = elf_aarch64_hash_table (info);
51 @@ -5469,8 +5468,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
52 : bfd_is_und_section (sym_sec));
53 abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root);
55 - via_plt_p = (globals->root.splt != NULL && h != NULL
56 - && h->plt.offset != (bfd_vma) - 1);
58 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
59 it here if it is defined in a non-shared object. */
60 @@ -5806,23 +5803,12 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
61 value += signed_addend;
64 - case BFD_RELOC_AARCH64_BRANCH19:
65 - case BFD_RELOC_AARCH64_TSTBR14:
66 - /* A conditional branch to an undefined weak symbol is converted to a
67 - branch to itself. */
68 - if (weak_undef_p && !via_plt_p)
70 - value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type,
77 case BFD_RELOC_AARCH64_CALL26:
78 case BFD_RELOC_AARCH64_JUMP26:
80 asection *splt = globals->root.splt;
81 + bfd_boolean via_plt_p =
82 + splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
84 /* A call to an undefined weak symbol is converted to a jump to
85 the next instruction unless a PLT entry will be created.
86 @@ -5903,6 +5889,23 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
87 bfd_set_error (bfd_error_bad_value);
88 return bfd_reloc_notsupported;
90 + value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type,
96 + case BFD_RELOC_AARCH64_BRANCH19:
97 + case BFD_RELOC_AARCH64_TSTBR14:
98 + if (h && h->root.type == bfd_link_hash_undefined)
101 + /* xgettext:c-format */
102 + (_("%pB: conditional branch to undefined symbol `%s' "
103 + "not allowed"), input_bfd, h->root.root.string);
104 + bfd_set_error (bfd_error_bad_value);
105 + return bfd_reloc_notsupported;
109 case BFD_RELOC_AARCH64_16:
110 @@ -7968,8 +7971,6 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
114 - case BFD_RELOC_AARCH64_BRANCH19:
115 - case BFD_RELOC_AARCH64_TSTBR14:
116 case BFD_RELOC_AARCH64_CALL26:
117 case BFD_RELOC_AARCH64_JUMP26:
118 /* If this is a local symbol then we resolve it
119 diff --git a/ld/testsuite/ld-aarch64/emit-relocs-560.d b/ld/testsuite/ld-aarch64/emit-relocs-560.d
120 index 153532457b4..8751b743bd4 100644
121 --- a/ld/testsuite/ld-aarch64/emit-relocs-560.d
122 +++ b/ld/testsuite/ld-aarch64/emit-relocs-560.d
124 #source: emit-relocs-560.s
128 -Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 2 entries:
129 - Offset Info Type Sym. Value Sym. Name \+ Addend
130 -[0-9a-f]+ 000100000402 R_AARCH64_JUMP_SL 0000000000000000 baz \+ 0
131 -[0-9a-f]+ 000200000402 R_AARCH64_JUMP_SL 0000000000000000 bar \+ 0
132 +#error: .*: conditional branch to undefined symbol `bar' not allowed