From patchwork Tue Mar 21 14:28:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 72904 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1810898wrt; Tue, 21 Mar 2023 07:29:19 -0700 (PDT) X-Google-Smtp-Source: AK7set/DlTLvsFu1qYb+9+OXaIFSF8i0dGVRERc5M2S1r2jqusWxkdMl7OzUCst53SYGRPLhBkRB X-Received: by 2002:a17:906:560c:b0:930:6e31:3c11 with SMTP id f12-20020a170906560c00b009306e313c11mr2902184ejq.70.1679408959334; Tue, 21 Mar 2023 07:29:19 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cd2-20020a170906b34200b008dae86d0890si4237876ejb.575.2023.03.21.07.29.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 07:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=mMBwTUKZ; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56A48385B537 for ; Tue, 21 Mar 2023 14:29:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56A48385B537 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679408956; bh=degnb3q789zhRfPzC9AG4bsO+DNT0l/CBNrUFGZa3/k=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mMBwTUKZ8Kr/X/GUorVxznxDNkXcV8Iwg18Oe1hR3Ifso/k80fdR1dYU3OZV/s2LY bRiRukNgIvddt743wRFRXX6QZZDBO05EjN5hhtHV9/8Y67PUTFzGt5+DCWoa/wlwrd eFDxaWXqjLszK28kwsPHrYyv1bvpjLD7lTsFiP2g= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2052.outbound.protection.outlook.com [40.107.20.52]) by sourceware.org (Postfix) with ESMTPS id 7C4AC3858D38 for ; Tue, 21 Mar 2023 14:29:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C4AC3858D38 Received: from DUZPR01CA0006.eurprd01.prod.exchangelabs.com (2603:10a6:10:3c3::13) by AS8PR08MB6005.eurprd08.prod.outlook.com (2603:10a6:20b:298::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 14:28:52 +0000 Received: from DBAEUR03FT019.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:3c3:cafe::53) by DUZPR01CA0006.outlook.office365.com (2603:10a6:10:3c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Tue, 21 Mar 2023 14:28:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT019.mail.protection.outlook.com (100.127.142.129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.16 via Frontend Transport; Tue, 21 Mar 2023 14:28:51 +0000 Received: ("Tessian outbound b29c0599cbc9:v135"); Tue, 21 Mar 2023 14:28:51 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b68da5abfd8bc556 X-CR-MTA-TID: 64aa7808 Received: from fe21d1daadcd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 41993FA9-FC82-4031-AAEA-2CD7A4127A16.1; Tue, 21 Mar 2023 14:28:45 +0000 Received: from EUR03-AM7-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id fe21d1daadcd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 21 Mar 2023 14:28:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b2822F3qy9sT/txMQsfh0+MAeBQIAMDEZCqUtu1qCevrhKjVaBDgiC5Z2dcayWi5JsB/a/nmK0F+alxq5OO2Z499pHmTJyO0q5DAZdwCuC4mZYxDt4NoKDwYNFlCs44TPer89OyrXzdSXdtv/p3niS+0ipOgJYU+cdysccx3OoeFGSLSeKMyW2cWXDru0YB7+4t5vGEpOrUdJW/tjScR0wpG3Q4anytyXke2RXerpODLWZhDqG+KvkQ1nYbcXidJnQP65QwV+5QwEZDMBUR6MV6NCHVAFGgj6jJnESe3LzNF3Zo3gI2kdauE6ji4s6dBwNeS7YrIIsWP5C3lXk5JwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=degnb3q789zhRfPzC9AG4bsO+DNT0l/CBNrUFGZa3/k=; b=icTSRLzblx6h1CdLzKK8ijNB75+rAliS/t+Lm0/tYwX31/Ef6G/fli47BMSpvhXU1R0M7hNw6ttrwVI540sQ9refIAegpBwvnDuWnEvv3YjsrfqAvCAnE9PvvgIV8/RtQf+nykitcT0X4j872eLrfpN0SO69THqZss65z9Bso2z3nTGfDXCuJ2fbcnc1v1VPN6opHPeiJW+/iSCmZRp2xzA66FxFyJbtM4VbIZFUZuIR5qrvbHICzZ1VDE+2rsUl8IEqX6anIHXV6xohg6Np04CatbkSzYoLLoAgluX50P8z2edK7ffiFGqdcRjUYwEm89WH/Q5qljs1tJHXjoYUaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AM6PR04CA0010.eurprd04.prod.outlook.com (2603:10a6:20b:92::23) by AS8PR08MB8038.eurprd08.prod.outlook.com (2603:10a6:20b:548::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 14:28:40 +0000 Received: from AM7EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:92:cafe::d4) by AM6PR04CA0010.outlook.office365.com (2603:10a6:20b:92::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Tue, 21 Mar 2023 14:28:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT046.mail.protection.outlook.com (100.127.140.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.17 via Frontend Transport; Tue, 21 Mar 2023 14:28:40 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Tue, 21 Mar 2023 14:28:39 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.17 via Frontend Transport; Tue, 21 Mar 2023 14:28:39 +0000 To: Subject: [PATCH 1/3] bfd: aarch64: Refactor stub sizing code Date: Tue, 21 Mar 2023 14:28:39 +0000 Message-ID: <20230321142839.672428-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT046:EE_|AS8PR08MB8038:EE_|DBAEUR03FT019:EE_|AS8PR08MB6005:EE_ X-MS-Office365-Filtering-Correlation-Id: b41e11cd-9bbe-4903-6345-08db2a1897d6 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: WIatlXhEuHEK3seeh72wBXYdn46SBtAmIXYgMWUE850WTW1ntBkPRRTDr2abzt5d7eVFifd5tpkIi2h7TLSriiq7h0HS3sZDjYQLUH5b2vRHVV1XgaBUqDw6W0WMVQX3f8uWvxqbqn0KXB3+6BWPnNg8wQTj7QN3I846os1Qwa8evwgK/oiB2dFQm8StJCsxkephAtvqusxw2LM8OGNMbJq4AxboWLKWaiyl+75e46ChnSIZYA+RZPttu2dSgDtwV8u1XRgy69QUKW9p+wPDvzv2OtPYVK6a0xo3WJyOkDODdMmPSt03K7hOJjdFujSzfAubhKDCpow1aUvZLiUh/IT4y56Drk2FDK6yk8lAd7/5ubmFhg3P/+K9CtWgQvbCts9eWiLYGz/XC7AK9knSrrWdGmACsCKH5u+re/9dcad1O0z8RBcIa4M4E6YCI3BpAHHu6tHNGidf5kyf6ipPiCfa4XdKwOguvk6mj9lfuGZrNW/gdJXEO2ddu8fOYfDbLg3g8adupEhrBJpUAtpkYelcqYpwNDwTv2lFsxFt0vZkQpCR4IgbFSJ2G/wcF/2pZzVWnNGSAJbl1aLRlLUsw9x3TfPB//43XPXm3mNtaWL0+JZByqNVgr4eG/dgaSwgoNn0uFkSMjMfP8CyTxRNoF3jxjwd0yuwXLXxaeHC5+wq5Gc78CGUF7L/xpA68hhXC22wfCV+5V0+D34EsN044gFeoAnLre1aBJ21BOFeZHY= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(396003)(39860400002)(346002)(136003)(376002)(451199018)(36840700001)(46966006)(40470700004)(30864003)(2616005)(44832011)(5660300002)(8936002)(186003)(40480700001)(36860700001)(356005)(86362001)(36756003)(82310400005)(81166007)(82740400003)(40460700003)(336012)(2906002)(426003)(47076005)(83380400001)(316002)(7696005)(6916009)(8676002)(70206006)(70586007)(478600001)(1076003)(26005)(41300700001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8038 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: ec6a7984-f094-4022-34cc-08db2a18910f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hnwvXc+i4/fLn3cvemGyRdtawN4tbpx/8j9SDc4aKOpu3UNG5TT6uWORr/4a0euKrTMiJ1hNmDLVYBdKSBCekO6sw2dMkwVvv31A6UZCOs4uFp4cMbXJprwHgT0B4O9dtmPHlKaOnku/wKipV9s9Y2CHki0REDpUIM2fnC/w+bnJcgheKllggIJwdLy5aKNFNxyQcW2jDlnZQzGsFO8iAunrapRnKPYPO93+o2X7dUufM0npfxb3lnj99KTNhFFcirW9+9aGYf04K2f4um/a6/IJz/gk1jOjFwtuM6c/ZU2+r8SmgVJgB3ekX2c4aPi4Vd8PtZ95eMtD2068zfTNcRL2Yb12dVn2dFJi729H490M5M8UDs7ZhwjtG1EijMY1nFZ3E27KyN2AKslHKCw6DsFjyD/fnkD83JJA0gna+Ae2OmiPXIlNVZg1m1SQn6BfBhJOmK00i5nCtL4AzoQ3eXIJetDW7XCXBkp+8wppSOnF3EoWlR+PLIcixV1w7/OxqAL4zX7OZNB1q+Agc6TI1U8ULcve2ShYLUDq4EfMIyWokyEggAJtX5BVmnAaRE9snRH2JrW9jiJcEIMpC85S4Jxm7TasbQct936MDCV9UyGBuIQV/BLmOfrxsv3UM36WYAs74NEbDsJirHs435+sFGOaDY5IPCzcG/EucB9x7NQRw61C0AVhNEphoMx8vA6OXcwZCSp58E2PZzxPgtdGkg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230025)(4636009)(346002)(396003)(39860400002)(376002)(136003)(451199018)(46966006)(40470700004)(36840700001)(7696005)(2616005)(47076005)(426003)(186003)(83380400001)(478600001)(336012)(316002)(26005)(70586007)(6916009)(70206006)(8676002)(1076003)(36860700001)(44832011)(41300700001)(5660300002)(30864003)(8936002)(82740400003)(40460700003)(81166007)(2906002)(40480700001)(36756003)(86362001)(82310400005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 14:28:51.7892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b41e11cd-9bbe-4903-6345-08db2a1897d6 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6005 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Binutils From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760987928838567669?= X-GMAIL-MSGID: =?utf-8?q?1760987928838567669?= elfNN_aarch64_size_stubs has grown big, so factor out the call stub related code before adding new logic there. --- bfd/elfnn-aarch64.c | 552 ++++++++++++++++++++++---------------------- 1 file changed, 279 insertions(+), 273 deletions(-) diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index bf8f913a66d..f858d10c596 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -4265,12 +4265,285 @@ _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section, } -/* Determine and set the size of the stub section for a final link. +/* Add stub entries for calls. The basic idea here is to examine all the relocations looking for PC-relative calls to a target that is unreachable with a "bl" instruction. */ +static bool +_bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd, + struct bfd_link_info *info) +{ + struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); + bfd *input_bfd; + + for (input_bfd = info->input_bfds; input_bfd != NULL; + input_bfd = input_bfd->link.next) + { + Elf_Internal_Shdr *symtab_hdr; + asection *section; + Elf_Internal_Sym *local_syms = NULL; + + if (!is_aarch64_elf (input_bfd) + || (input_bfd->flags & BFD_LINKER_CREATED) != 0) + continue; + + /* We'll need the symbol table in a second. */ + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + if (symtab_hdr->sh_info == 0) + continue; + + /* Walk over each section attached to the input bfd. */ + for (section = input_bfd->sections; + section != NULL; section = section->next) + { + Elf_Internal_Rela *internal_relocs, *irelaend, *irela; + + /* If there aren't any relocs, then there's nothing more to do. */ + if ((section->flags & SEC_RELOC) == 0 + || section->reloc_count == 0 + || (section->flags & SEC_CODE) == 0) + continue; + + /* If this section is a link-once section that will be + discarded, then don't create any stubs. */ + if (section->output_section == NULL + || section->output_section->owner != output_bfd) + continue; + + /* Get the relocs. */ + internal_relocs + = _bfd_elf_link_read_relocs (input_bfd, section, NULL, + NULL, info->keep_memory); + if (internal_relocs == NULL) + goto error_ret_free_local; + + /* Now examine each relocation. */ + irela = internal_relocs; + irelaend = irela + section->reloc_count; + for (; irela < irelaend; irela++) + { + unsigned int r_type, r_indx; + enum elf_aarch64_stub_type stub_type; + struct elf_aarch64_stub_hash_entry *stub_entry; + asection *sym_sec; + bfd_vma sym_value; + bfd_vma destination; + struct elf_aarch64_link_hash_entry *hash; + const char *sym_name; + char *stub_name; + const asection *id_sec; + unsigned char st_type; + bfd_size_type len; + + r_type = ELFNN_R_TYPE (irela->r_info); + r_indx = ELFNN_R_SYM (irela->r_info); + + if (r_type >= (unsigned int) R_AARCH64_end) + { + bfd_set_error (bfd_error_bad_value); + error_ret_free_internal: + if (elf_section_data (section)->relocs == NULL) + free (internal_relocs); + goto error_ret_free_local; + } + + /* Only look for stubs on unconditional branch and + branch and link instructions. */ + if (r_type != (unsigned int) AARCH64_R (CALL26) + && r_type != (unsigned int) AARCH64_R (JUMP26)) + continue; + + /* Now determine the call target, its name, value, + section. */ + sym_sec = NULL; + sym_value = 0; + destination = 0; + hash = NULL; + sym_name = NULL; + if (r_indx < symtab_hdr->sh_info) + { + /* It's a local symbol. */ + Elf_Internal_Sym *sym; + Elf_Internal_Shdr *hdr; + + if (local_syms == NULL) + { + local_syms + = (Elf_Internal_Sym *) symtab_hdr->contents; + if (local_syms == NULL) + local_syms + = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, + symtab_hdr->sh_info, 0, + NULL, NULL, NULL); + if (local_syms == NULL) + goto error_ret_free_internal; + } + + sym = local_syms + r_indx; + hdr = elf_elfsections (input_bfd)[sym->st_shndx]; + sym_sec = hdr->bfd_section; + if (!sym_sec) + /* This is an undefined symbol. It can never + be resolved. */ + continue; + + if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) + sym_value = sym->st_value; + destination = (sym_value + irela->r_addend + + sym_sec->output_offset + + sym_sec->output_section->vma); + st_type = ELF_ST_TYPE (sym->st_info); + sym_name + = bfd_elf_string_from_elf_section (input_bfd, + symtab_hdr->sh_link, + sym->st_name); + } + else + { + int e_indx; + + e_indx = r_indx - symtab_hdr->sh_info; + hash = ((struct elf_aarch64_link_hash_entry *) + elf_sym_hashes (input_bfd)[e_indx]); + + while (hash->root.root.type == bfd_link_hash_indirect + || hash->root.root.type == bfd_link_hash_warning) + hash = ((struct elf_aarch64_link_hash_entry *) + hash->root.root.u.i.link); + + if (hash->root.root.type == bfd_link_hash_defined + || hash->root.root.type == bfd_link_hash_defweak) + { + struct elf_aarch64_link_hash_table *globals = + elf_aarch64_hash_table (info); + sym_sec = hash->root.root.u.def.section; + sym_value = hash->root.root.u.def.value; + /* For a destination in a shared library, + use the PLT stub as target address to + decide whether a branch stub is + needed. */ + if (globals->root.splt != NULL && hash != NULL + && hash->root.plt.offset != (bfd_vma) - 1) + { + sym_sec = globals->root.splt; + sym_value = hash->root.plt.offset; + if (sym_sec->output_section != NULL) + destination = (sym_value + + sym_sec->output_offset + + sym_sec->output_section->vma); + } + else if (sym_sec->output_section != NULL) + destination = (sym_value + irela->r_addend + + sym_sec->output_offset + + sym_sec->output_section->vma); + } + else if (hash->root.root.type == bfd_link_hash_undefined + || (hash->root.root.type + == bfd_link_hash_undefweak)) + { + /* For a shared library, use the PLT stub as + target address to decide whether a long + branch stub is needed. + For absolute code, they cannot be handled. */ + struct elf_aarch64_link_hash_table *globals = + elf_aarch64_hash_table (info); + + if (globals->root.splt != NULL && hash != NULL + && hash->root.plt.offset != (bfd_vma) - 1) + { + sym_sec = globals->root.splt; + sym_value = hash->root.plt.offset; + if (sym_sec->output_section != NULL) + destination = (sym_value + + sym_sec->output_offset + + sym_sec->output_section->vma); + } + else + continue; + } + else + { + bfd_set_error (bfd_error_bad_value); + goto error_ret_free_internal; + } + st_type = ELF_ST_TYPE (hash->root.type); + sym_name = hash->root.root.root.string; + } + + /* Determine what (if any) linker stub is needed. */ + stub_type = aarch64_type_of_stub (section, irela, sym_sec, + st_type, destination); + if (stub_type == aarch64_stub_none) + continue; + + /* Support for grouping stub sections. */ + id_sec = htab->stub_group[section->id].link_sec; + + /* Get the name of this stub. */ + stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash, + irela); + if (!stub_name) + goto error_ret_free_internal; + + stub_entry = + aarch64_stub_hash_lookup (&htab->stub_hash_table, + stub_name, false, false); + if (stub_entry != NULL) + { + /* The proper stub has already been created. */ + free (stub_name); + + /* Always update this stub's target since it may have + changed after layout. */ + stub_entry->target_value = sym_value + irela->r_addend; + continue; + } + + stub_entry = _bfd_aarch64_add_stub_entry_in_group + (stub_name, section, htab); + if (stub_entry == NULL) + { + free (stub_name); + goto error_ret_free_internal; + } + + stub_entry->target_value = sym_value + irela->r_addend; + stub_entry->target_section = sym_sec; + stub_entry->stub_type = stub_type; + stub_entry->h = hash; + stub_entry->st_type = st_type; + + if (sym_name == NULL) + sym_name = "unnamed"; + len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name); + stub_entry->output_name = bfd_alloc (htab->stub_bfd, len); + if (stub_entry->output_name == NULL) + { + free (stub_name); + goto error_ret_free_internal; + } + + snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME, + sym_name); + + *stub_changed = true; + } + + /* We're done with the internal relocs, free them. */ + if (elf_section_data (section)->relocs == NULL) + free (internal_relocs); + } + } + return true; + error_ret_free_local: + return false; +} + + +/* Determine and set the size of the stub section for a final link. */ + bool elfNN_aarch64_size_stubs (bfd *output_bfd, bfd *stub_bfd, @@ -4282,7 +4555,6 @@ elfNN_aarch64_size_stubs (bfd *output_bfd, { bfd_size_type stub_group_size; bool stubs_always_before_branch; - bool stub_changed = false; struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); unsigned int num_erratum_835769_fixes = 0; @@ -4357,285 +4629,19 @@ elfNN_aarch64_size_stubs (bfd *output_bfd, (*htab->layout_sections_again) (); } - while (1) + for (;;) { - bfd *input_bfd; - - for (input_bfd = info->input_bfds; - input_bfd != NULL; input_bfd = input_bfd->link.next) - { - Elf_Internal_Shdr *symtab_hdr; - asection *section; - Elf_Internal_Sym *local_syms = NULL; - - if (!is_aarch64_elf (input_bfd) - || (input_bfd->flags & BFD_LINKER_CREATED) != 0) - continue; - - /* We'll need the symbol table in a second. */ - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; - if (symtab_hdr->sh_info == 0) - continue; - - /* Walk over each section attached to the input bfd. */ - for (section = input_bfd->sections; - section != NULL; section = section->next) - { - Elf_Internal_Rela *internal_relocs, *irelaend, *irela; - - /* If there aren't any relocs, then there's nothing more - to do. */ - if ((section->flags & SEC_RELOC) == 0 - || section->reloc_count == 0 - || (section->flags & SEC_CODE) == 0) - continue; - - /* If this section is a link-once section that will be - discarded, then don't create any stubs. */ - if (section->output_section == NULL - || section->output_section->owner != output_bfd) - continue; - - /* Get the relocs. */ - internal_relocs - = _bfd_elf_link_read_relocs (input_bfd, section, NULL, - NULL, info->keep_memory); - if (internal_relocs == NULL) - goto error_ret_free_local; - - /* Now examine each relocation. */ - irela = internal_relocs; - irelaend = irela + section->reloc_count; - for (; irela < irelaend; irela++) - { - unsigned int r_type, r_indx; - enum elf_aarch64_stub_type stub_type; - struct elf_aarch64_stub_hash_entry *stub_entry; - asection *sym_sec; - bfd_vma sym_value; - bfd_vma destination; - struct elf_aarch64_link_hash_entry *hash; - const char *sym_name; - char *stub_name; - const asection *id_sec; - unsigned char st_type; - bfd_size_type len; - - r_type = ELFNN_R_TYPE (irela->r_info); - r_indx = ELFNN_R_SYM (irela->r_info); - - if (r_type >= (unsigned int) R_AARCH64_end) - { - bfd_set_error (bfd_error_bad_value); - error_ret_free_internal: - if (elf_section_data (section)->relocs == NULL) - free (internal_relocs); - goto error_ret_free_local; - } - - /* Only look for stubs on unconditional branch and - branch and link instructions. */ - if (r_type != (unsigned int) AARCH64_R (CALL26) - && r_type != (unsigned int) AARCH64_R (JUMP26)) - continue; - - /* Now determine the call target, its name, value, - section. */ - sym_sec = NULL; - sym_value = 0; - destination = 0; - hash = NULL; - sym_name = NULL; - if (r_indx < symtab_hdr->sh_info) - { - /* It's a local symbol. */ - Elf_Internal_Sym *sym; - Elf_Internal_Shdr *hdr; - - if (local_syms == NULL) - { - local_syms - = (Elf_Internal_Sym *) symtab_hdr->contents; - if (local_syms == NULL) - local_syms - = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, - symtab_hdr->sh_info, 0, - NULL, NULL, NULL); - if (local_syms == NULL) - goto error_ret_free_internal; - } - - sym = local_syms + r_indx; - hdr = elf_elfsections (input_bfd)[sym->st_shndx]; - sym_sec = hdr->bfd_section; - if (!sym_sec) - /* This is an undefined symbol. It can never - be resolved. */ - continue; - - if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) - sym_value = sym->st_value; - destination = (sym_value + irela->r_addend - + sym_sec->output_offset - + sym_sec->output_section->vma); - st_type = ELF_ST_TYPE (sym->st_info); - sym_name - = bfd_elf_string_from_elf_section (input_bfd, - symtab_hdr->sh_link, - sym->st_name); - } - else - { - int e_indx; + bool stub_changed = false; - e_indx = r_indx - symtab_hdr->sh_info; - hash = ((struct elf_aarch64_link_hash_entry *) - elf_sym_hashes (input_bfd)[e_indx]); - - while (hash->root.root.type == bfd_link_hash_indirect - || hash->root.root.type == bfd_link_hash_warning) - hash = ((struct elf_aarch64_link_hash_entry *) - hash->root.root.u.i.link); - - if (hash->root.root.type == bfd_link_hash_defined - || hash->root.root.type == bfd_link_hash_defweak) - { - struct elf_aarch64_link_hash_table *globals = - elf_aarch64_hash_table (info); - sym_sec = hash->root.root.u.def.section; - sym_value = hash->root.root.u.def.value; - /* For a destination in a shared library, - use the PLT stub as target address to - decide whether a branch stub is - needed. */ - if (globals->root.splt != NULL && hash != NULL - && hash->root.plt.offset != (bfd_vma) - 1) - { - sym_sec = globals->root.splt; - sym_value = hash->root.plt.offset; - if (sym_sec->output_section != NULL) - destination = (sym_value - + sym_sec->output_offset - + - sym_sec->output_section->vma); - } - else if (sym_sec->output_section != NULL) - destination = (sym_value + irela->r_addend - + sym_sec->output_offset - + sym_sec->output_section->vma); - } - else if (hash->root.root.type == bfd_link_hash_undefined - || (hash->root.root.type - == bfd_link_hash_undefweak)) - { - /* For a shared library, use the PLT stub as - target address to decide whether a long - branch stub is needed. - For absolute code, they cannot be handled. */ - struct elf_aarch64_link_hash_table *globals = - elf_aarch64_hash_table (info); - - if (globals->root.splt != NULL && hash != NULL - && hash->root.plt.offset != (bfd_vma) - 1) - { - sym_sec = globals->root.splt; - sym_value = hash->root.plt.offset; - if (sym_sec->output_section != NULL) - destination = (sym_value - + sym_sec->output_offset - + - sym_sec->output_section->vma); - } - else - continue; - } - else - { - bfd_set_error (bfd_error_bad_value); - goto error_ret_free_internal; - } - st_type = ELF_ST_TYPE (hash->root.type); - sym_name = hash->root.root.root.string; - } - - /* Determine what (if any) linker stub is needed. */ - stub_type = aarch64_type_of_stub (section, irela, sym_sec, - st_type, destination); - if (stub_type == aarch64_stub_none) - continue; - - /* Support for grouping stub sections. */ - id_sec = htab->stub_group[section->id].link_sec; - - /* Get the name of this stub. */ - stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash, - irela); - if (!stub_name) - goto error_ret_free_internal; - - stub_entry = - aarch64_stub_hash_lookup (&htab->stub_hash_table, - stub_name, false, false); - if (stub_entry != NULL) - { - /* The proper stub has already been created. */ - free (stub_name); - /* Always update this stub's target since it may have - changed after layout. */ - stub_entry->target_value = sym_value + irela->r_addend; - continue; - } - - stub_entry = _bfd_aarch64_add_stub_entry_in_group - (stub_name, section, htab); - if (stub_entry == NULL) - { - free (stub_name); - goto error_ret_free_internal; - } - - stub_entry->target_value = sym_value + irela->r_addend; - stub_entry->target_section = sym_sec; - stub_entry->stub_type = stub_type; - stub_entry->h = hash; - stub_entry->st_type = st_type; - - if (sym_name == NULL) - sym_name = "unnamed"; - len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name); - stub_entry->output_name = bfd_alloc (htab->stub_bfd, len); - if (stub_entry->output_name == NULL) - { - free (stub_name); - goto error_ret_free_internal; - } - - snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME, - sym_name); - - stub_changed = true; - } - - /* We're done with the internal relocs, free them. */ - if (elf_section_data (section)->relocs == NULL) - free (internal_relocs); - } - } + if (!_bfd_aarch64_add_call_stub_entries (&stub_changed, output_bfd, info)) + return false; if (!stub_changed) - break; + return true; _bfd_aarch64_resize_stubs (htab); - - /* Ask the linker to do its stuff. */ (*htab->layout_sections_again) (); - stub_changed = false; } - - return true; - - error_ret_free_local: - return false; } /* Build all the stubs associated with the current output file. The From patchwork Tue Mar 21 14:28:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 72903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1810852wrt; Tue, 21 Mar 2023 07:29:14 -0700 (PDT) X-Google-Smtp-Source: AK7set+E6x7wewZGI+CaCXxDmhfyXkUtE/H/kNdqaoDF0jkcLzbmOZteI2e80W5fx8O0UfBe7Z9o X-Received: by 2002:aa7:d38b:0:b0:4ad:7056:23a5 with SMTP id x11-20020aa7d38b000000b004ad705623a5mr3656539edq.14.1679408954405; Tue, 21 Mar 2023 07:29:14 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d22-20020aa7d5d6000000b00501d9f51adcsi2488067eds.533.2023.03.21.07.29.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 07:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=PbAzWZ8r; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D75AD3858031 for ; Tue, 21 Mar 2023 14:29:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D75AD3858031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679408952; bh=J7RNfej3wwdwhDoQUnxfk4mnIJ9esPi3rwvLbnjfRmE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PbAzWZ8rss4TPD8yF57WUAaXVKDypFl7cFftRgRB7cj0jD0P8e9CnOKu5JYJtWL0v 39cr2YEN1zoxMtD+HCTFpJoAHUW3dm5/lp4ggdazN6GmdwhY0VooRBEzEmaUtRXOYg B0PX2fhkUmuRFamaOOxSkM1H64+9pf/SxgaXNt9U= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2062a.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::62a]) by sourceware.org (Postfix) with ESMTPS id B90803858D37 for ; Tue, 21 Mar 2023 14:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B90803858D37 Received: from DB7PR03CA0087.eurprd03.prod.outlook.com (2603:10a6:10:72::28) by AS8PR08MB9118.eurprd08.prod.outlook.com (2603:10a6:20b:5b6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 14:28:58 +0000 Received: from DBAEUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:72:cafe::61) by DB7PR03CA0087.outlook.office365.com (2603:10a6:10:72::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Tue, 21 Mar 2023 14:28:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT039.mail.protection.outlook.com (100.127.142.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.17 via Frontend Transport; Tue, 21 Mar 2023 14:28:58 +0000 Received: ("Tessian outbound 2ba0ed2ebb9f:v135"); Tue, 21 Mar 2023 14:28:58 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f90162249637cc13 X-CR-MTA-TID: 64aa7808 Received: from 6485e75d73e0.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4DD6F58A-9B82-4429-936C-E44835D3A99B.1; Tue, 21 Mar 2023 14:28:50 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 6485e75d73e0.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 21 Mar 2023 14:28:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S7ecd5G01TvpNsF2H9kWtxaRi4MFV9lzQR1kySBYT6vH9/Ty8YTUDtSk+VlofcWJPrTGunSo7Be4unAxRIUG2iOzl6qXEpfhC/mq/hfN6Xe2xaxaPZC3cdyYg89tRXRrp996HDXpdlBhpd8vrAHHlPhMLmjdklNfBGMDt3QArHq/t59z1zod+Sui9Mf5vF7lYm9WgyJsXaYPBK8Mn7lyT0VZzP3kFvJN76SwiQXz39nn0EBfjDurNhbFCdGLy/nHT1r7Vitmr1lXY3IvHENa+cwzgSIftxI0QtA/ZR2HInKxz+161cWAZl6x/yRkpUj1y9v6Q9g6Vn0ZMcdIVHh5gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J7RNfej3wwdwhDoQUnxfk4mnIJ9esPi3rwvLbnjfRmE=; b=X5eLxvzm9LInuTYIgd9vqFn8oIp1FkATYthSGo6CVEyg1eCMPLlbAyiz47UaAg2G3O8+gFYKEYok7jVr+jBbJgae2VYU5gl8a5KTXY5i/55X2KQ/N6iToNTJmql4mnuC/T3oVL8izxxrGtHxcILZ0QmG3kz+KVcEYRkkUoorM9TxNbF2as4B0RfWLre4sQiwcvXOY+8EcBVMCZPhlxshHsfM7f0zh/bKP0KO3ZsITCXzyu9X2Kepuf3FCc8lLWVJe3xeoVtRoAJzOM+eB8NmM8WBYE20Gh6gyUZUJXwzQEJC811r8Qgw1FvPbEIYHx2HCVZ+7ATwPVQINn/jD62Sjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB6PR0202CA0046.eurprd02.prod.outlook.com (2603:10a6:4:a5::32) by PA4PR08MB6317.eurprd08.prod.outlook.com (2603:10a6:102:ec::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 14:28:49 +0000 Received: from DBAEUR03FT013.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a5:cafe::a1) by DB6PR0202CA0046.outlook.office365.com (2603:10a6:4:a5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Tue, 21 Mar 2023 14:28:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT013.mail.protection.outlook.com (100.127.142.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.16 via Frontend Transport; Tue, 21 Mar 2023 14:28:49 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Tue, 21 Mar 2023 14:28:48 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.17 via Frontend Transport; Tue, 21 Mar 2023 14:28:48 +0000 To: Subject: [PATCH 2/3] bfd: aarch64: Fix stubs that may break BTI PR30076 Date: Tue, 21 Mar 2023 14:28:48 +0000 Message-ID: <20230321142848.672474-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT013:EE_|PA4PR08MB6317:EE_|DBAEUR03FT039:EE_|AS8PR08MB9118:EE_ X-MS-Office365-Filtering-Correlation-Id: ce716aea-f20e-472a-f57c-08db2a189bae x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: mI/ax1Cbc7TELh4cnrCvJeJaLJPVm4pBvXhApLA4+Urmc8aIaatG2e/C3+AsRTCbHExEckDQDzB1iS5o1bO1Gbxf9VM0FZ3NGgNb/SsJjX2yaX/3iv30S92gSGSH6j53WrNxgEfqy6GTqYC19GqRHjwKabBDo71RFBal3osZbQJPraw+B7Lf6a6QiaqzyrDtBFufNwlz+qt4BNzX86szr51uatFazz4QJaF8Fyc2RJxClFqGdPHpMvjOwJICgMDC2VF6vjy1sGr9AEYwpEZQXUSDi4j2je8t29C6RzijtQBgReAEe2yqseABtdEl5kFuiSG4ubGpC1RlLxVkFsN9rNdFCLwcrJVSfBfpSKTHNVe5YMn1ELZflmJpHnwBHE9w91Q5WaYmm6jcwg1IlXxK0WlKM3oyVzVetjxN1SacLKmFcJrcee32N4IpK3BPAUOZTGp6dEEwMAM27MJa8Z+H4vKKsreYaxw8xWfcDEaPR4hSP2EFJBhKkFdQSJMEg4dNjeExQTjyqiMePMGIlucuEOOrFLr+4BZ9lQxllbDPF1IL5Tes08G0IWEU4YUq2S82cGvsRE/oXRm3ZtkExkt2hbK3Asia3ceU9+ntu5yex41Ff2WVT74J+9UeCCX8VN8ScUR/Zxsd7QxlnpwMmFmQYAt4EcE792K8sYgNkl12zoyrgop9vlNzPBgFgymrUP5V/phpJNEvfJxug8AsuqbtaegZPI9EyTjlFdksaVqVu2w= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(136003)(376002)(39860400002)(346002)(396003)(451199018)(40470700004)(46966006)(36840700001)(7696005)(426003)(2616005)(47076005)(83380400001)(82310400005)(478600001)(316002)(1076003)(26005)(5660300002)(186003)(36860700001)(356005)(81166007)(86362001)(336012)(40460700003)(82740400003)(30864003)(2906002)(70586007)(41300700001)(40480700001)(70206006)(6916009)(44832011)(8676002)(8936002)(36756003)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6317 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 19c10a59-e8ef-4a29-f486-08db2a189640 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: er3ZMh6j00l/Ktykj8rtpmXpKDRWuyaEbcSuPSPChsmH3AS+4F6/xPfFamY17PkRxqEMRvuj9kiPcYfdy7ED4bZHv90V2eR3WNyPrwgdcDEh5huVHzweh6FzKRLFYNIerlCsCtXAla5I4CNQLzmSia37D2dlPk0td0K6ckclClB/ytAqDk7ILqWUFofyqapUOK8CCogIGRpFkV4t6a7SpTODY2Mat2z/86MQSDM+E5hjAlz5K9v1lvARv0LrUxaGEsXS8F+lHPFDX6/B8axkS2TL9xyIee445Ikcs7l8G4Vn+u+loUqezS+e28cwFs25cA3meYP6njLXZI5AoN5z1ooCYtZ3DMoNFIfWHZ0caS+eWfcTASDyoZ49E182XNvQe7EpLtRNIiNnTo7aAFueI0+UNGg+f0Lg+xvcAqd3pMnDQhq1rzmQYXQOUuIa7kGSTrlvSvPcZwPTlb4pJspOfAXQgUXTaJC28FrMg4X19Eu9c5QbAbvrldIawxWYujS/3Avr9VntLyiH1KKVM0sDzutvAFcYdWgkgNt4gviwQkyskatE8uNSbB/R5OFJ0rJ51NRT4Ytabd2Vs0r/+iyndvs24JTbfoHcqQch5DHwZrAr+aSM64hEVHhs33NQwlKva73zxEQav7RLoDrEM6H3+IOriOP0LEyiLRAhwPOe5dikXOvWBGjgqfPwY1h/HX0nfg+HWQ68Gvr5Q9L9xPKE1Q== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230025)(4636009)(396003)(346002)(39860400002)(136003)(376002)(451199018)(40470700004)(46966006)(36840700001)(316002)(82310400005)(336012)(47076005)(426003)(83380400001)(2616005)(86362001)(81166007)(44832011)(36860700001)(40460700003)(70206006)(40480700001)(2906002)(6916009)(41300700001)(8676002)(36756003)(70586007)(82740400003)(30864003)(26005)(478600001)(1076003)(5660300002)(186003)(7696005)(8936002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 14:28:58.2417 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ce716aea-f20e-472a-f57c-08db2a189bae X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9118 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_NUMSUBJECT, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Binutils From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760987923907671288?= X-GMAIL-MSGID: =?utf-8?q?1760987923907671288?= Insert two stubs in a BTI enabled binary when fixing long calls: The first is near the call site and uses an indirect jump like before, but it targets the second stub that is near the call target site and uses a direct jump. This is needed when a single stub breaks BTI compatibility. The stub layout is kept fixed between sizing and building the stubs, so the location of the second stub is known at build time, this may introduce padding between stubs when those are relaxed. Stub layout with BTI disabled is unchanged. --- bfd/elfnn-aarch64.c | 175 ++++++++++++++++++++++-- ld/testsuite/ld-aarch64/aarch64-elf.exp | 3 + ld/testsuite/ld-aarch64/bti-far-1.d | 83 +++++++++++ ld/testsuite/ld-aarch64/bti-far-2.d | 62 +++++++++ ld/testsuite/ld-aarch64/bti-far.ld | 15 ++ ld/testsuite/ld-aarch64/bti-far.s | 29 ++++ 6 files changed, 352 insertions(+), 15 deletions(-) create mode 100644 ld/testsuite/ld-aarch64/bti-far-1.d create mode 100644 ld/testsuite/ld-aarch64/bti-far-2.d create mode 100644 ld/testsuite/ld-aarch64/bti-far.ld create mode 100644 ld/testsuite/ld-aarch64/bti-far.s diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index f858d10c596..d9ebeae922c 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -2354,6 +2354,9 @@ elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, name can be changed. The only requirement is the %s be present. */ #define STUB_ENTRY_NAME "__%s_veneer" +/* Stub name for a BTI landing stub. */ +#define BTI_STUB_ENTRY_NAME "__%s_bti_veneer" + /* The name of the dynamic interpreter. This is put in the .interp section. */ #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" @@ -2406,6 +2409,12 @@ static const uint32_t aarch64_long_branch_stub[] = 0x00000000, }; +static const uint32_t aarch64_bti_direct_branch_stub[] = +{ + 0xd503245f, /* bti c */ + 0x14000000, /* b