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