From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 96132385E017; Wed, 20 Dec 2023 15:59:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96132385E017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Szabolcs Nagy To: bfd-cvs@sourceware.org Subject: [binutils-gdb/binutils-2_41-branch] bfd: aarch64: Fix BTI stub optimization PR30957 X-Act-Checkin: binutils-gdb X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/binutils-2_41-branch X-Git-Oldrev: ad9049e6da186e8317916dc2d0c89002d6a5e0f9 X-Git-Newrev: 8b9de994244a85f6d87564a798e00d5acefa75b7 Message-Id: <20231220155954.96132385E017@sourceware.org> Date: Wed, 20 Dec 2023 15:59:54 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Dec 2023 15:59:54 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8b9de994244a= 85f6d87564a798e00d5acefa75b7 commit 8b9de994244a85f6d87564a798e00d5acefa75b7 Author: Szabolcs Nagy Date: Fri Oct 13 17:51:15 2023 +0100 bfd: aarch64: Fix BTI stub optimization PR30957 =20 The instruction was looked up in the wrong input file (file of branch source instead of branch target) when optimizing away BTI stubs in =20 commit 5834f36d93cabf1a8bcc7dd7654141aed3d296bc bfd: aarch64: Optimize BTI stubs PR30076 =20 This can cause adding BTI stubs when they are not necessary or removing them when they are (the latter is a correctness issue but it is very unlikely in practice). =20 Fixes bug 30957. =20 (cherry picked from commit 98b94ebb3ffe715fddde762bb3ee7fd6d972f233) Diff: --- bfd/elfnn-aarch64.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 4592bd6da27..a0dd17faa7e 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -3675,8 +3675,7 @@ group_sections (struct elf_aarch64_link_hash_table *h= tab, /* True if the inserted stub does not break BTI compatibility. */ =20 static bool -aarch64_bti_stub_p (bfd *input_bfd, - struct elf_aarch64_stub_hash_entry *stub_entry) +aarch64_bti_stub_p (struct elf_aarch64_stub_hash_entry *stub_entry) { /* Stubs without indirect branch are BTI compatible. */ if (stub_entry->stub_type !=3D aarch64_stub_adrp_branch @@ -3690,7 +3689,7 @@ aarch64_bti_stub_p (bfd *input_bfd, file_ptr off =3D stub_entry->target_value; bfd_size_type count =3D sizeof (loc); =20 - if (!bfd_get_section_contents (input_bfd, section, loc, off, count)) + if (!bfd_get_section_contents (section->owner, section, loc, off, count)) return false; =20 uint32_t insn =3D bfd_getl32 (loc); @@ -4637,7 +4636,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_change= d, bfd *output_bfd, =20 /* A stub with indirect jump may break BTI compatibility, so insert another stub with direct jump near the target then. */ - if (need_bti && !aarch64_bti_stub_p (input_bfd, stub_entry)) + if (need_bti && !aarch64_bti_stub_p (stub_entry)) { stub_entry->double_stub =3D true; htab->has_double_stub =3D true;