From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 28 Apr 2021 22:00:24 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1lbqMC-0000If-2i for lore@lore.pengutronix.de; Wed, 28 Apr 2021 22:00:24 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1lbqMB-0007fk-Kj; Wed, 28 Apr 2021 22:00:23 +0200 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1lbqLW-0007fd-J3 for ptxdist@pengutronix.de; Wed, 28 Apr 2021 21:59:42 +0200 From: Lucas Stach To: ptxdist@pengutronix.de Date: Wed, 28 Apr 2021 21:59:42 +0200 Message-Id: <20210428195942.30215-1-l.stach@pengutronix.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Subject: [ptxdist] [PATCH OSELAS.Toolchain] cross-binutils: fix handling of relocations in conditional branches on aarch64 X-BeenThere: ptxdist@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: PTXdist Development Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: ptxdist@pengutronix.de Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "ptxdist" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: ptxdist-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false Patch cherry-picked from the 2.36 release. Fixes: "relocation truncated to fit: R_AARCH64_CONDBR19 against symbol 'SYM' defined in .text section" This issue is a spurious link failure, which is sometimes triggered on very large binaries, depending on the section ordering. Signed-off-by: Lucas Stach --- ...n-error-on-conditional-branch-to-an-.patch | 127 ++++++++++++++++++ patches/binutils-2.35/series | 4 + 2 files changed, 131 insertions(+) create mode 100644 patches/binutils-2.35/0001-aarch64-Return-an-error-on-conditional-branch-to-an-.patch create mode 100644 patches/binutils-2.35/series diff --git a/patches/binutils-2.35/0001-aarch64-Return-an-error-on-conditional-branch-to-an-.patch b/patches/binutils-2.35/0001-aarch64-Return-an-error-on-conditional-branch-to-an-.patch new file mode 100644 index 000000000000..e4ec825ada65 --- /dev/null +++ b/patches/binutils-2.35/0001-aarch64-Return-an-error-on-conditional-branch-to-an-.patch @@ -0,0 +1,127 @@ +From: Siddhesh Poyarekar +Date: Tue, 1 Sep 2020 14:25:52 +0530 +Subject: [PATCH] aarch64: Return an error on conditional branch to an + undefined symbol + +The fix in 7e05773767820b441b23a16628b55c98cb1aef46 introduced a PLT +for conditional jumps when the target symbol is undefined. This is +incorrect because conditional branch relocations are not allowed to +clobber IP0/IP1 and hence, should not result in a dynamic relocation. + +Revert that change and in its place, issue an error when the target +symbol is undefined. + +bfd/ + + 2020-09-10 Siddhesh Poyarekar + + * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Revert + changes in 7e05773767820b441b23a16628b55c98cb1aef46. Set + error for undefined symbol in BFD_RELOC_AARCH64_BRANCH19 and + BFD_RELOC_AARCH64_TSTBR14 relocations. + +ld/ + + 2020-09-10 Siddhesh Poyarekar + + * testsuite/ld-aarch64/emit-relocs-560.d: Expect error instead + of valid output. +--- + bfd/elfnn-aarch64.c | 37 ++++++++++++++++--------------- + ld/testsuite/ld-aarch64/emit-relocs-560.d | 7 +----- + 2 files changed, 20 insertions(+), 24 deletions(-) + +diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c +index 8f1e5e1e456a..44c7c3f888d1 100644 +--- a/bfd/elfnn-aarch64.c ++++ b/bfd/elfnn-aarch64.c +@@ -5448,7 +5448,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto, + bfd_vma orig_value = value; + bfd_boolean resolved_to_zero; + bfd_boolean abs_symbol_p; +- bfd_boolean via_plt_p; + + globals = elf_aarch64_hash_table (info); + +@@ -5470,8 +5469,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto, + : bfd_is_und_section (sym_sec)); + abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root); + +- via_plt_p = (globals->root.splt != NULL && h != NULL +- && h->plt.offset != (bfd_vma) - 1); + + /* Since STT_GNU_IFUNC symbol must go through PLT, we handle + it here if it is defined in a non-shared object. */ +@@ -5807,23 +5804,12 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto, + value += signed_addend; + break; + +- case BFD_RELOC_AARCH64_BRANCH19: +- case BFD_RELOC_AARCH64_TSTBR14: +- /* A conditional branch to an undefined weak symbol is converted to a +- branch to itself. */ +- if (weak_undef_p && !via_plt_p) +- { +- value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, +- place, value, +- signed_addend, +- weak_undef_p); +- break; +- } +- /* Fall through. */ + case BFD_RELOC_AARCH64_CALL26: + case BFD_RELOC_AARCH64_JUMP26: + { + asection *splt = globals->root.splt; ++ bfd_boolean via_plt_p = ++ splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1; + + /* A call to an undefined weak symbol is converted to a jump to + the next instruction unless a PLT entry will be created. +@@ -5904,6 +5890,23 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto, + bfd_set_error (bfd_error_bad_value); + return bfd_reloc_notsupported; + } ++ value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, ++ place, value, ++ signed_addend, ++ weak_undef_p); ++ break; ++ ++ case BFD_RELOC_AARCH64_BRANCH19: ++ case BFD_RELOC_AARCH64_TSTBR14: ++ if (h && h->root.type == bfd_link_hash_undefined) ++ { ++ _bfd_error_handler ++ /* xgettext:c-format */ ++ (_("%pB: conditional branch to undefined symbol `%s' " ++ "not allowed"), input_bfd, h->root.root.string); ++ bfd_set_error (bfd_error_bad_value); ++ return bfd_reloc_notsupported; ++ } + /* Fall through. */ + + case BFD_RELOC_AARCH64_16: +@@ -7969,8 +7972,6 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info, + break; + } + +- case BFD_RELOC_AARCH64_BRANCH19: +- case BFD_RELOC_AARCH64_TSTBR14: + case BFD_RELOC_AARCH64_CALL26: + case BFD_RELOC_AARCH64_JUMP26: + /* If this is a local symbol then we resolve it +diff --git a/ld/testsuite/ld-aarch64/emit-relocs-560.d b/ld/testsuite/ld-aarch64/emit-relocs-560.d +index 153532457b4e..8751b743bd47 100644 +--- a/ld/testsuite/ld-aarch64/emit-relocs-560.d ++++ b/ld/testsuite/ld-aarch64/emit-relocs-560.d +@@ -1,8 +1,3 @@ + #source: emit-relocs-560.s + #ld: -shared +-#readelf: -r +- +-Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 2 entries: +- Offset Info Type Sym. Value Sym. Name \+ Addend +-[0-9a-f]+ 000100000402 R_AARCH64_JUMP_SL 0000000000000000 baz \+ 0 +-[0-9a-f]+ 000200000402 R_AARCH64_JUMP_SL 0000000000000000 bar \+ 0 ++#error: .*: conditional branch to undefined symbol `bar' not allowed diff --git a/patches/binutils-2.35/series b/patches/binutils-2.35/series new file mode 100644 index 000000000000..1801c88d8702 --- /dev/null +++ b/patches/binutils-2.35/series @@ -0,0 +1,4 @@ +# generated by git-ptx-patches +#tag:base --start-number 1 +0001-aarch64-Return-an-error-on-conditional-branch-to-an-.patch +# 5659eac4238ed54433b24df64ce3eed6 - git-ptx-patches magic -- 2.30.2 _______________________________________________ ptxdist mailing list ptxdist@pengutronix.de To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de