From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2059.outbound.protection.outlook.com [40.107.105.59]) by sourceware.org (Postfix) with ESMTPS id A9AC03858428 for ; Fri, 3 Nov 2023 13:15:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9AC03858428 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A9AC03858428 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.105.59 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1699017365; cv=pass; b=i+X1oy/HnRlbJ/HFg8PbtXb9hUs9ul+kTdKo7GHSh/L2qEuIibG082dVlRLEdxNi5Vu3gNHEFcQpcDf8fPBCI3CLTgQSalmoZ25zVROSwvmRyaMMVcJPwvksd4sWDORPNAYwvPG2P/eauRQXFVoxcmbkZfU+0a5MRkIAhWVNyfQ= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1699017365; c=relaxed/simple; bh=72lETeW/BQpD+ZMHUgrK4A60yhYD0IWw7aDtCTkW7mk=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=t1b5Ny2aofoVx2IZjRWaw1WpVaTFSrMuBJlWIImHHWxM88s0rQ4XPB2kmSEuu2O50vjxRgoM8EjL8kBVn7LYR/OhpqZZF8zx0S6XbhtqxavWu6iUXLPeScjK9xtwUDFQall5k78Os4C8483hy2sKTVlgs7leKDJKfalPKxnKx8U= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ao08l8CidpdZ6XBDfaMjAh46AX61K0HAEqEsnhFVIEz4pB83sQrkTbHv9DeHdRyCxM4jaYVik9u0wEa0PbLf5rBgsSLoK3yY/vYf1B4jFSXxGBnGbNfz04N1nqa1NLJyX3eqTm/us1Ic8aPOwALVTO00SxNCNLV6YMZLzFOF9bSsSyyfNpMLqmLi9ZUqfJ1JOtdvkSzs0wynrpQ4L/7SNGX+ieKNXxnfWyYaI5lUZVlygzRpei9FjMwb0EniwAbtGKZ3bh72GyMH6eME3LSngI0T0dA0ttCsu69Fx6Qpl0MgxH0iZNxcmxGY2xdH26BTXijE3yk2BuIN3csDSCMiCA== ARC-Message-Signature: i=2; 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=vaF1mZLBmThr3UaqnDaYLAEUNZ6Vq5Gwmo/6jolsVpY=; b=fYm3q84WEqVtko0EQggB1Xg99rrqIbrRpgAhPCJSgmXKArx1gMdOlJkx7o+LDTbipiARgQT1wQCeaOTMalOrkZiFAVBWiyfU46P+fsSmcrsCEWtcES+2anEH52YaCCjOIEjxd5SJNLNeJwQztm9URgYL7Q7jbTGMx5FeSeqYUzao1VSgqXWumsNkcLO9AdixmeX6AnhwtufWCoxTOokT7+oZ75KU9xRi4iumOZ31oZ2gBAU52hd6LI8rld57Ga4OABK+6aD0t7NhtGCBG3LOJxJv+V22+CFBFjwLaX201QSaiWRHHfPZL6Sk6/BlEYF5fZ9ZbtlNdd9QEQp4NIhXjA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vaF1mZLBmThr3UaqnDaYLAEUNZ6Vq5Gwmo/6jolsVpY=; b=tUh8rcstWoyXKpWMGnL/zZJh6Kbdx8ETL1LvmSGdB3t0sOjrKqGxYcLHx14xDzRupYb/4cghQ+U7NpKnesNUokHGj+0VrcXZQF19eeA0hjBN555rrYhfWgA5aPES+O1DRI2WWGeKrZO6ZzuPifUDt+HBUYlHme1+CSVyB3TpnHg= Received: from AS8P189CA0041.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:458::9) by PAWPR08MB9613.eurprd08.prod.outlook.com (2603:10a6:102:2e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.21; Fri, 3 Nov 2023 13:15:51 +0000 Received: from AMS0EPF00000196.eurprd05.prod.outlook.com (2603:10a6:20b:458:cafe::d2) by AS8P189CA0041.outlook.office365.com (2603:10a6:20b:458::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.21 via Frontend Transport; Fri, 3 Nov 2023 13:15: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 AMS0EPF00000196.mail.protection.outlook.com (10.167.16.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Fri, 3 Nov 2023 13:15:50 +0000 Received: ("Tessian outbound 7671e7ddc218:v228"); Fri, 03 Nov 2023 13:15:50 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 66eaf3998d15f71c X-CR-MTA-TID: 64aa7808 Received: from b04f9c68425d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 73A61CD1-5233-4AD4-B88B-7876217EE039.1; Fri, 03 Nov 2023 13:15:42 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b04f9c68425d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 03 Nov 2023 13:15:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k0ULZqTabQvHTIAx5+9UJQTpgW11wpuF16YHXlMRrz5Z/gJlUwaSgvffilevdlYi4R9sviBt3zWm7ZgR/GMlDyhuNtGmmhd7kmC0DnbvvQVnYD9EQiDHaWw43sAWXKYIyyuQ5Wbn8aLD12+OoDc4ynE8iOuRauWeTGs0FTjrIdXp5Tq+ZjVo0OD2t637YsJvOkwpX61Z1ZJEAilVkqbVUIZZw8gIIRfyYY+GGQ+xWQMnQkCRc1i5cTusRdDNeZ2clQ5W1+1xlsk75HP5StoyVDEzT3UsG9Hv1cQfKA3AfSwPKvpK0iinTE/n4RElJSpzbRnqO/FxDb56q1LuiK7MkA== 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=vaF1mZLBmThr3UaqnDaYLAEUNZ6Vq5Gwmo/6jolsVpY=; b=BgbGwTmXni3rxjNTSXJxIPzfjC13QFloLR+dv9BD2IAW1MQkqniXHJhP1fHKTFmk0zKJ/SuQS8nqiD3jo7yy1cWS+LPHD8QO6dcv/hQ37NKEwayLZ+IuPlz8jh2gvEmHoHpsx0hsHMvAGOwODJZeno5qzIZhBOI4n5+KUYTK2rS6uakAyEuItRAE0QoYVlve52N0KhJsSgcIuA7Ik6Bxri0cHbbhTc1RoGVrJFS6/o0SXOs8Fjj3pd9mpI0KWw1FCJi5+PpE7Bp6cgYwsorZYGog1q2vFHkpYzh4LVJRUdpfPEPV69a8gNdIwQcBeWnH6cnT9e8+J09mOuQGtmyyeA== 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 (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vaF1mZLBmThr3UaqnDaYLAEUNZ6Vq5Gwmo/6jolsVpY=; b=tUh8rcstWoyXKpWMGnL/zZJh6Kbdx8ETL1LvmSGdB3t0sOjrKqGxYcLHx14xDzRupYb/4cghQ+U7NpKnesNUokHGj+0VrcXZQF19eeA0hjBN555rrYhfWgA5aPES+O1DRI2WWGeKrZO6ZzuPifUDt+HBUYlHme1+CSVyB3TpnHg= Received: from DB8PR09CA0030.eurprd09.prod.outlook.com (2603:10a6:10:a0::43) by AS8PR08MB6726.eurprd08.prod.outlook.com (2603:10a6:20b:39a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.21; Fri, 3 Nov 2023 13:15:39 +0000 Received: from DU2PEPF0001E9C2.eurprd03.prod.outlook.com (2603:10a6:10:a0:cafe::f) by DB8PR09CA0030.outlook.office365.com (2603:10a6:10:a0::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.22 via Frontend Transport; Fri, 3 Nov 2023 13:15:39 +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 DU2PEPF0001E9C2.mail.protection.outlook.com (10.167.8.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6954.19 via Frontend Transport; Fri, 3 Nov 2023 13:15:39 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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.32; Fri, 3 Nov 2023 13:15:39 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Fri, 3 Nov 2023 13:15: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.32 via Frontend Transport; Fri, 3 Nov 2023 13:15:39 +0000 From: Szabolcs Nagy To: Subject: [PATCH 2/5] bfd: aarch64: Fix broken BTI stub PR30930 Date: Fri, 3 Nov 2023 13:15:38 +0000 Message-ID: <8a36dd5ca319bd4d0fe2425bddcf4868c3426a96.1699016830.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DU2PEPF0001E9C2:EE_|AS8PR08MB6726:EE_|AMS0EPF00000196:EE_|PAWPR08MB9613:EE_ X-MS-Office365-Filtering-Correlation-Id: e2417159-32e1-4599-4fe3-08dbdc6f0060 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: UEALdW4A/lnssrM52EZahn5GhUN7mh9oLqql11E37gZbSNNJwOMYBwtIBAA+v8YG4GN1YqS4atQTcqWVE5B31KcXBhGXKFGLeRzkrhzhdjXP+5mNrghzaFv0hQf+eVb4aTog2e5yy1z0am7ZEogWjW2MAbJT/ox1RVZClvhHWAjBIZSbHxDw1FE9XuBclqGFGUiaWcyxCWmZxng9QVqwsPNT9JemnCVtYEAKr939Me17smqr33LVyb6MgWuEuON1jkzFZ6v1O68T9b92wYm4ptlJlZIa0qjkM3EGTe2tvduYl8UloR8MtpaiUKONFRYp9eV4PLAggUILa0+nX7ZL8gZif6teAnefl+/6vrQ4vUe35guQ+nbOkRDGErCoO1M81hPCT0FHdgtJwD2LOmD0HB4YWxIB90yBW6BVnRDGOpNgkI6/VlTg5JWP+z2TAD6ZI2lake+p+TJUbTL8vLgnwNUVTpG8ip2tFG7DYcfApp1bNxTlfDYAB5nktzjS+2bvUvPkrFD+UXwg4XCTVbt1WGDIifky/KKqBo2zhN5Hg4umdfubdxxCBfwjUb9kQ4bKgVLDr0Qi+DTRlxhRUgUuUUqUOG+XgQqw0tCtSvvWGYGpgiAM4Tr2JBqm5Os/lO/u5NSGOpuQMgdW1fky7fa4PREleX3WsOH6IvmEPzt1k/3I1Yvq26HHLZW60v7eWyb5Ox1Lr9jSsubqfyMigLHH5APMrPckbKXGwhFZyVFzcZt7uFTFYEvv0RkYN8/C3suSnGrp+WD91Xa8QCGfS/Zhrw== 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:(13230031)(4636009)(376002)(346002)(136003)(396003)(39860400002)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(82310400011)(40470700004)(46966006)(36840700001)(7696005)(40460700003)(40480700001)(26005)(336012)(426003)(82740400003)(83380400001)(86362001)(81166007)(356005)(2616005)(36756003)(47076005)(36860700001)(8936002)(70586007)(41300700001)(316002)(6916009)(44832011)(70206006)(5660300002)(8676002)(478600001)(2906002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6726 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS0EPF00000196.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7755b5c3-fd7e-49d6-7624-08dbdc6ef9b8 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +OggETco7lm7rEoCpuerqer3syf3TciHqnQVZkPkoj8lGwCnz5OdUdiznSICetSyxjC6YXq7T4IAp3p9i0DHK8FkJ55c/VX5W7FioH3vlQvjJ67sBT1wGnpOxg6KmdQorFY8QA4TzOTZxPglQP4woAO79zyn5xNQ+BPIuKOB4fcUkPRRoOsAy8cY/voocH2lEuvkQ62+4oM+2j43/MdXiv6f874Npjx2SaeHsBYsPNRuJavbosS+FYi6b5vh1WRZUp2KdEF+f6nfswhHFOgMd5m3T3n/rv6JPaRvPH/9kdOAHbwDVM33oGTZgqo1RAbUAeANOcBBbefgXHksWavPWklAOp4WM7y1P1B4LPQmizidg6joD7T/Hn+r7UflldTMKQzYACV5v8au8UaoOmUwHV+yCDvGzbfLLGxbpZ4PuIykmiRRgIWQqeoQscxJHkqcjKtmdbPJcb013wDxLWN81N73oXmU/QmhAkHiTewjC9pdQPRxLGVllIIMcEJDuTEFQV8BtUm/AR17ITewck3+GbbzBFdPZ54Y35a6onQNKnlRA0DpdWbcUYuFKWz/Jr45IUV/7kLL0SSj7T5P4HyhliBSFXKPpybatVFvOKyf6G2uKsYt5gPDk9JsphgOddwT8gTFWgu4WRrmPJH0+hpyhP88HWsul5BpJe5vz8xiJ5pkR1m/B5/D5tPynjNnx2dJRMzMdrKT02tY6icEjzQ5h+jKA78sGB49vM+GU9LZ0wtUpyDA2BB0X9qFuAew5scb 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:(13230031)(4636009)(396003)(39860400002)(346002)(136003)(376002)(230922051799003)(451199024)(82310400011)(1800799009)(186009)(64100799003)(46966006)(40470700004)(36840700001)(40480700001)(26005)(2616005)(40460700003)(86362001)(36756003)(81166007)(82740400003)(2906002)(83380400001)(336012)(426003)(5660300002)(7696005)(478600001)(47076005)(36860700001)(8676002)(8936002)(316002)(70206006)(70586007)(6916009)(41300700001)(44832011);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2023 13:15:50.8380 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2417159-32e1-4599-4fe3-08dbdc6f0060 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: AMS0EPF00000196.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9613 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,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 List-Id: Input sections are grouped together that can use the same stub area (within reach) and these groups have a stable id. Stubs have a name generated from the stub group id and target symbol. When a relocation requires a stub with a name that already exists, the stub is reused instead of adding a new one. For an indirect branch stub another BTI stub may be inserted near the target to provide a BTI landing pad. The BTI stub can end up with the same stub group id and thus the same name as the indirect stub. This happens if the target symbol is within reach of the indirect branch stub. Then, due to the name collision, only a single stub was emmitted which branched to itself causing an infinite loop at runtime. A possible solution is to just name the BTI stubs differently, but since in the problematic case the indirect and BTI stub are in the same stub area, a better solution is to emit a single stub with a direct branch. The stub is still needed since the caller cannot reach the target directly and we also want a BTI landing pad in the stub in case other indirect stubs target the same symbol and thus need a BTI stub. In short we convert an indirect branch stub into a BTI stub when the target is within reach and has no BTI. It is a hassle to change the symbol of the stub so a BTI stub may end up with *_veneer instead of *_bti_veneer after the conversion, but this should not matter much. (Refactoring some of _bfd_aarch64_add_call_stub_entries would be useful but too much for this bug fix patch.) The same conversion to direct branch could be done even if the target did not need a BTI. The stub groups are fixed in the current logic so linking can fail if too many stubs are inserted and the section layout is changed too much, but this only happens in extreme cases that can be reasonably ignored. Because of this the target cannot go out of reach during stub insertion so the optimization is valid, but not implemented by this patch for the non-BTI case. Fixes bug 30930. --- bfd/elfnn-aarch64.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index a0dd17faa7e..798643ade7c 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -4638,9 +4638,22 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd, insert another stub with direct jump near the target then. */ if (need_bti && !aarch64_bti_stub_p (stub_entry)) { + id_sec_bti = htab->stub_group[sym_sec->id].link_sec; + + /* If the stub with indirect jump and the BTI stub are in + the same stub group: change the indirect jump stub into + a BTI stub since a direct branch can reach the target. + The BTI landing pad is still needed in case another + stub indirectly jumps to it. */ + if (id_sec_bti == id_sec) + { + stub_entry->stub_type = aarch64_stub_bti_direct_branch; + goto skip_double_stub; + } + stub_entry->double_stub = true; htab->has_double_stub = true; - id_sec_bti = htab->stub_group[sym_sec->id].link_sec; + stub_name_bti = elfNN_aarch64_stub_name (id_sec_bti, sym_sec, hash, irela); if (!stub_name_bti) @@ -4687,7 +4700,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd, stub_entry->h = NULL; stub_entry->st_type = STT_FUNC; } - +skip_double_stub: *stub_changed = true; } -- 2.25.1