From patchwork Fri May 15 14:40:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1291241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=2B40qFVY; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=2B40qFVY; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49NrjT0YJFz9sWt for ; Sat, 16 May 2020 00:42:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53AEE398582C; Fri, 15 May 2020 14:41:34 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70079.outbound.protection.outlook.com [40.107.7.79]) by sourceware.org (Postfix) with ESMTPS id DDC1E398580B for ; Fri, 15 May 2020 14:41:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DDC1E398580B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@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=zP0gITlhrgTe2JtXUSwYKQypQfWlgnGWZA2iFY5Hbgs=; b=2B40qFVYo/1s07Z5FAETGTtl2bnTx8ANUgont0MuLl4LLBZSEontU3HRGJgjJvKqybGUF1i19E4N/wkdhbSl/goHIdHzpktj5Maj5ei9WRcSiSMGHQ31tKPzmafKIqa0MevofOJ96/2PTY7OBD/2wQy2ZnNnDuNLJpSXRTTH4Kg= Received: from DB6P193CA0021.EURP193.PROD.OUTLOOK.COM (2603:10a6:6:29::31) by DBBPR08MB5548.eurprd08.prod.outlook.com (2603:10a6:10:c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.27; Fri, 15 May 2020 14:41:12 +0000 Received: from DB5EUR03FT056.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:29:cafe::91) by DB6P193CA0021.outlook.office365.com (2603:10a6:6:29::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Fri, 15 May 2020 14:41:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT056.mail.protection.outlook.com (10.152.21.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Fri, 15 May 2020 14:41:11 +0000 Received: ("Tessian outbound b3a67fbfbb1f:v54"); Fri, 15 May 2020 14:41:11 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 98000d0552f80a64 X-CR-MTA-TID: 64aa7808 Received: from fdf193f3d1eb.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 630E041B-634A-4383-A79F-1216F959249D.1; Fri, 15 May 2020 14:41:06 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id fdf193f3d1eb.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 15 May 2020 14:41:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZguSxKBXg+31Fzc1b2jf6fDM1MCkvGUf7f+qRuC+t9Le68OyCRxcxvutov9aNmRLom7gPbJV13kil06f2MpdCM2JPMGEN94qmr30eqvq+Sl7WEVX1+ILS7kjM/gQeRZMMITkLsc3ZBsTd4o5KCAqiPhGiev/M9PfqqZ/jaWXEyuvQm1tiSfHQX91Q/4hiAn5MBMa5VTZWpJ+HpEjhdDCwo4kw+6ZqxDeohlWrBT8qBvtyZkaRIsUWawxHRLf6tpsTBsIl8Ej2+tHPouZfbSeU64hyiV7FapSJSlPSNACxRMqL7o46yCWeAC7bmI+Kueu6q1kj44f9/vAchqmG+ih+A== 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-SenderADCheck; bh=zP0gITlhrgTe2JtXUSwYKQypQfWlgnGWZA2iFY5Hbgs=; b=CbPKgeYn4oKswtUjkImiq20aHeAuVKSLQy8XxGfSbA8aIQTrFkdMy0wJ2W7CYSIQhYKSrIHan4V/zN6/fIuDFXA4NHwgYpb2Eo7Jw+PZoBFPuHG1sxFsP6s5Ztl2rHniukWqyRgX9LSV8WW28H46gSEbGO/hcax/PbqOnuTZMBrd0HSNY0ZNYU++Pl5IPuxf9qM+94XEaAfkEPvyzNwgXL+NvQkFwOSDhc1QTK76wlrfAk43V8XWXM1CkCbicDRAIkEc+LiaqA9lqhWwehXyD5DBhxIpoiAeuQSGLjRDwQP/ZcQMA3yem8hmdHqpTWgR+SoxR3XUBhBM+Kb9cGqysg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none 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=zP0gITlhrgTe2JtXUSwYKQypQfWlgnGWZA2iFY5Hbgs=; b=2B40qFVYo/1s07Z5FAETGTtl2bnTx8ANUgont0MuLl4LLBZSEontU3HRGJgjJvKqybGUF1i19E4N/wkdhbSl/goHIdHzpktj5Maj5ei9WRcSiSMGHQ31tKPzmafKIqa0MevofOJ96/2PTY7OBD/2wQy2ZnNnDuNLJpSXRTTH4Kg= Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB3528.eurprd08.prod.outlook.com (2603:10a6:20b:4b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.34; Fri, 15 May 2020 14:41:05 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862%7]) with mapi id 15.20.2979.033; Fri, 15 May 2020 14:41:05 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v3 05/13] aarch64: Add BTI support to assembly files Date: Fri, 15 May 2020 15:40:49 +0100 Message-Id: <64e9a422a1ef370334b90a591229f7f4e293bf8c.1589552054.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0309.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::33) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by LO2P265CA0309.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24 via Frontend Transport; Fri, 15 May 2020 14:41:04 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c2666207-c4ef-4f24-7cec-08d7f8de036b X-MS-TrafficTypeDiagnostic: AM6PR08MB3528:|AM6PR08MB3528:|DBBPR08MB5548: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: pY9kw2EkTXFARZUSkrBmE3ERkYhjI9cuoBlIHPiJOwKsOfy+N6Y8ZqiN5KJ7vQsBiD6Uz778chGdFkZQgsI0KAlkh5VLSGHvT84dx0y2W9BPi5Ql+7QPXMBKYmatssA7wA0FxRj7kiuuoVDCT4Sv//SBfodyqNiL2GdPxd8i/w+zCulr2FKWRD6oNXLFmYM6Fx8+BFQl4vOrI5h7mXHFXe9CWVH2SFeEXjS9VRfXzGCSzgbLIjn3jSh7LkOOAjhMfrOx6DrRaFsddjkfU0X7FA+v4eTomJcAWwh/4vdg/9IWI241Elqnre+mtL6Qaq2t4KEPTzfq6TIYDaBPqH46nllXrCJF05CIohE8KLOK6rzSg+E8ozJ/7BZ3kgNoGnQ6bGFbdtZFexEtD2cMLC+4ZAkamZyZAiG9Diw3PXR+87X46pvzp31y7N54a9noF0/YepP+XMqBCEzN+DXzLQBDu2y8XdWUUlKATPcBQ/OKQUPsm8IhLAQCkS7wnNbbB4T5nbhXE0lzEYCXS5VfIBGRicUeVv0Px2244QyZMG5hCkM= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(39860400002)(346002)(366004)(396003)(86362001)(6506007)(4326008)(69590400007)(52116002)(478600001)(316002)(6666004)(6916009)(6486002)(66556008)(44832011)(6512007)(5660300002)(2906002)(956004)(66476007)(8936002)(66946007)(36756003)(186003)(26005)(2616005)(8676002)(16526019)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: F5tQWL37qi+13pZyO3UJdW8c7ne3ec4PbqTO7ei+GQrhyDqoWyIKwAymlotjmTI9QFrlXCC4NLkEXhy2rAxuiAwM6VW11LUqkKzEMIg+eCvk1s5JRgCx6TE/QSo9BN3PSOpsnOrdh3qCTK4ggT+z0CTJUKvyGcm9xY53YV/9JC47Hbftvdtj6gi0hO+g+ZMXeoqZgwqnsz1FUXkktkN7YXjjFgdq7iqtVqZvhJ3UNXa2oEdQpOhbEeFH3YIiZTCFO7efsePdlBbVEKRAZFNZAVxSxd7ydkcJ8+vMfVhXWPAfPpQ55tz3WIPg6Lf/QInPTwle7GAR+jrgzdUzBvO49Zn+3mDcX1Usn/7aJy+5WKyaL5ritqkOtx3srO88buUqkafPKcE9ZyeoVF6vw4dmJdvyoZooIHYjndK85NyhzBa47NcISCCfn1tUf2aG6unp3lrlzVoHU+vKmMVQ6iVwTTJReMQy4u41bZbGCK2m558Bdw4fPu7tZ5E5h2PJpgai X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3528 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT056.eop-EUR03.prod.protection.outlook.com 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; SFTY:; SFS:(4636009)(346002)(376002)(136003)(39860400002)(396003)(46966005)(956004)(6916009)(8676002)(8936002)(6666004)(47076004)(81166007)(69590400007)(478600001)(336012)(316002)(356005)(36756003)(82310400002)(82740400003)(86362001)(16526019)(6506007)(2616005)(70586007)(5660300002)(70206006)(6486002)(4326008)(6512007)(44832011)(26005)(2906002)(186003)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: df60ef3b-cf2c-40c2-3d63-08d7f8ddff35 X-Forefront-PRVS: 04041A2886 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ORMrtvAUio3Z7iYHH1I21117wXZxnWBu5q7Y9a+KpE3kahq7W3J3XcyQw7ThRP/RFlDnKOLGZLHseraQsP+Z63zTcWRXSwC0sYREEISY6ninNo1TUm9iqle7vglWdezv+EAXaUenYUFjwUXI6puyDjGywUSkmAUsj5MjXWpqsTjnxouduBM0KEP6j3IXwTlJ0MPpjgMnZNaeg3JfYwyyFOEsGsCkKBaQfBCRAuxQkdbZR3XKqhiKT0RCktr5Czellam3vKMXeBioQgzZxmPv9xsZpwJ73RfcFOxquRCUrquh6ATnzYkOzro+ElIv5l9b8XXSqruoJwGNZ5ZULrkVfqNYhinb8uM7Pp8CQCc4OLWi6SD+DUAwqWSRG838L+jypHTQlrd7CQuMKLKZx0DIenNqzd3gIR49J+jNQgW5tJQIee9cXp2xQTvW37x2AdclQSqO21LEIeBzK1IW0j1AJbmBVlIIopproXgtNJ6PSZcSApE2GdZo7Cea9fE+7+5a4SQPIEY5okQQVETEQo91lcHZOt0XyPPxguCcRl30p7B/UETwhmxU40Uuk796xjp7BmGwpmanIer0OHEvQJlZtg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 14:41:11.9938 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2666207-c4ef-4f24-7cec-08d7f8de036b 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-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5548 X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_STOCKGEN, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sudakshina Das Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Sudakshina Das To enable building glibc with branch protection, assembly code needs BTI landing pads and ELF object file markings in the form of a GNU property note. The landing pads are unconditionally added to all functions that may be indirectly called. When the code segment is not mapped with PROT_BTI these instructions are nops. They are kept in the code when BTI is not supported so that the layout of performance critical code is unchanged across configurations. The GNU property notes are only added when there is support for BTI in the toolchain, because old binutils does not handle the notes right. (Does not know how to merge them nor to put them in PT_GNU_PROPERTY segment instead of PT_NOTE, and some versions of binutils emit warnings about the unknown GNU property. In such cases the produced libc binaries would not have valid ELF marking so BTI would not be enabled.) Note: functions using ENTRY or ENTRY_ALIGN now start with an additional BTI c, so alignment of the following code changes, but ENTRY_ALIGN_AND_PAD was fixed so there is no change to the existing code layout. Some string functions may need to be tuned for optimal performance after this commit. Co-authored-by: Szabolcs Nagy Reviewed-by: Adhemerval Zanella --- sysdeps/aarch64/crti.S | 2 ++ sysdeps/aarch64/crtn.S | 2 ++ sysdeps/aarch64/dl-tlsdesc.S | 3 +++ sysdeps/aarch64/dl-trampoline.S | 2 ++ sysdeps/aarch64/start.S | 1 + sysdeps/aarch64/sysdep.h | 34 ++++++++++++++++++++++++++++++++- 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/sysdeps/aarch64/crti.S b/sysdeps/aarch64/crti.S index 1728eac37a..c346bcad72 100644 --- a/sysdeps/aarch64/crti.S +++ b/sysdeps/aarch64/crti.S @@ -75,6 +75,7 @@ call_weak_fn: .hidden _init .type _init, %function _init: + BTI_C stp x29, x30, [sp, -16]! mov x29, sp #if PREINIT_FUNCTION_WEAK @@ -89,5 +90,6 @@ _init: .hidden _fini .type _fini, %function _fini: + BTI_C stp x29, x30, [sp, -16]! mov x29, sp diff --git a/sysdeps/aarch64/crtn.S b/sysdeps/aarch64/crtn.S index c3e97cc449..0c1ef112c2 100644 --- a/sysdeps/aarch64/crtn.S +++ b/sysdeps/aarch64/crtn.S @@ -37,6 +37,8 @@ /* crtn.S puts function epilogues in the .init and .fini sections corresponding to the prologues in crti.S. */ +#include + .section .init,"ax",%progbits ldp x29, x30, [sp], 16 RET diff --git a/sysdeps/aarch64/dl-tlsdesc.S b/sysdeps/aarch64/dl-tlsdesc.S index 557ad1d505..9d96c8632a 100644 --- a/sysdeps/aarch64/dl-tlsdesc.S +++ b/sysdeps/aarch64/dl-tlsdesc.S @@ -74,6 +74,7 @@ cfi_startproc .align 2 _dl_tlsdesc_return: + BTI_C DELOUSE (0) ldr PTR_REG (0), [x0, #PTR_SIZE] RET @@ -95,6 +96,7 @@ _dl_tlsdesc_return: cfi_startproc .align 2 _dl_tlsdesc_undefweak: + BTI_C str x1, [sp, #-16]! cfi_adjust_cfa_offset (16) DELOUSE (0) @@ -142,6 +144,7 @@ _dl_tlsdesc_undefweak: cfi_startproc .align 2 _dl_tlsdesc_dynamic: + BTI_C DELOUSE (0) /* Save just enough registers to support fast path, if we fall diff --git a/sysdeps/aarch64/dl-trampoline.S b/sysdeps/aarch64/dl-trampoline.S index 94e965c096..2cbfa81434 100644 --- a/sysdeps/aarch64/dl-trampoline.S +++ b/sysdeps/aarch64/dl-trampoline.S @@ -35,6 +35,7 @@ cfi_startproc .align 2 _dl_runtime_resolve: + BTI_C /* AArch64 we get called with: ip0 &PLTGOT[2] ip1 temp(dl resolver entry point) @@ -126,6 +127,7 @@ _dl_runtime_resolve: cfi_startproc .align 2 _dl_runtime_profile: + BTI_C /* AArch64 we get called with: ip0 &PLTGOT[2] ip1 temp(dl resolver entry point) diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S index d96cf57e2d..75393e1c18 100644 --- a/sysdeps/aarch64/start.S +++ b/sysdeps/aarch64/start.S @@ -46,6 +46,7 @@ .globl _start .type _start,#function _start: + BTI_C /* Create an initial frame with 0 LR and FP */ mov x29, #0 mov x30, #0 diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h index 604c489170..086fc84b53 100644 --- a/sysdeps/aarch64/sysdep.h +++ b/sysdeps/aarch64/sysdep.h @@ -41,12 +41,42 @@ #define ASM_SIZE_DIRECTIVE(name) .size name,.-name +/* Branch Target Identitication support. */ +#define BTI_C hint 34 +#define BTI_J hint 36 + +/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ +#define FEATURE_1_AND 0xc0000000 +#define FEATURE_1_BTI 1 +#define FEATURE_1_PAC 2 + +/* Add a NT_GNU_PROPERTY_TYPE_0 note. */ +#define GNU_PROPERTY(type, value) \ + .section .note.gnu.property, "a"; \ + .p2align 3; \ + .word 4; \ + .word 16; \ + .word 5; \ + .asciz "GNU"; \ + .word type; \ + .word 4; \ + .word value; \ + .word 0; \ + .text + +/* Add GNU property note with the supported features to all asm code + where sysdep.h is included. */ +#if defined HAVE_AARCH64_BTI +GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI) +#endif + /* Define an entry point visible from C. */ #define ENTRY(name) \ .globl C_SYMBOL_NAME(name); \ .type C_SYMBOL_NAME(name),%function; \ .align 4; \ C_LABEL(name) \ + BTI_C; \ cfi_startproc; \ CALL_MCOUNT @@ -56,6 +86,7 @@ .type C_SYMBOL_NAME(name),%function; \ .p2align align; \ C_LABEL(name) \ + BTI_C; \ cfi_startproc; \ CALL_MCOUNT @@ -68,10 +99,11 @@ .globl C_SYMBOL_NAME(name); \ .type C_SYMBOL_NAME(name),%function; \ .p2align align; \ - .rep padding; \ + .rep padding - 1; /* -1 for bti c. */ \ nop; \ .endr; \ C_LABEL(name) \ + BTI_C; \ cfi_startproc; \ CALL_MCOUNT