From patchwork Wed Jul 1 14:38:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39864 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF39F3861812; Wed, 1 Jul 2020 14:38:51 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140055.outbound.protection.outlook.com [40.107.14.55]) by sourceware.org (Postfix) with ESMTPS id 5DD913857007 for ; Wed, 1 Jul 2020 14:38:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5DD913857007 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=udWIBWqCP7In1BA5q84afMPWwqHCmqXW/Cac04rTBGg=; b=ofUeIfsAreV3v2SfDMrMQM+RymNarqmBR02UEyJtG3lgCHCq1sEw0dUJIIWTvtzKH+3Lq5PBfcED6BISKuStuxhp68rfQWx6YaT2fxd4LD7ptcQ5ThjqweHf0pWAkHV7CcZAnkL14XPcLrxTp20Qt22dly9vnNQuT1fEUaqh0Z4= Received: from AM6P195CA0016.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:81::29) by AM4PR0802MB2225.eurprd08.prod.outlook.com (2603:10a6:200:61::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20; Wed, 1 Jul 2020 14:38:46 +0000 Received: from AM5EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:81:cafe::1e) by AM6P195CA0016.outlook.office365.com (2603:10a6:209:81::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.21 via Frontend Transport; Wed, 1 Jul 2020 14:38:46 +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 AM5EUR03FT046.mail.protection.outlook.com (10.152.16.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 1 Jul 2020 14:38:46 +0000 Received: ("Tessian outbound b8ad5ab47c8c:v62"); Wed, 01 Jul 2020 14:38:46 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 7079544fdad90299 X-CR-MTA-TID: 64aa7808 Received: from c95468a44173.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8518B6D6-091A-46E7-84F6-CF0915C4D8C6.1; Wed, 01 Jul 2020 14:38:40 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c95468a44173.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 01 Jul 2020 14:38:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gVffhcCAiePz/V/pjNBr0aESWSx8xg7G5Sd9n2cASYb9vYFmMH+XAqSgOO+F5Z2woCq20dlRhquZqe7WFntxkhpHrXqiBmTgvLpi7puJBfkPIbLLlMM+zkdflD+uEbifYs+i4noNdvGR7ObFUADoWwAxoZZ7rDqpa4eqLEp8yAcLZ8I9Sj9BqLKs0lJr/0XbGRUiaLAcBPwoqSRe5Qx+/iBQoyyKMmHN33ANdmztESxlp4OTMBlHNQJsplxU10en7mnvPSm1VPoq28015Reb8NhiMWzRwRJzSWFqhkkoYoNuL6xa7L8q2/OltmWphItb/zGyf/IZdY0V7UaK4xUxag== 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=udWIBWqCP7In1BA5q84afMPWwqHCmqXW/Cac04rTBGg=; b=DJxxbZjRTOdg/DPCshS6IPvBo7Txg7v6XAW9Y8MBc2fSb5tYS/iIBDpr4QqmDFWaCM2CXRJh358ncxGwPU0l3SxabWJWJHT8BqihqBa3gpkDZTsUTjq4h5lhJYvnz6J85eE0K13XOEBVQBc2p8R/ieBTNBBU7iUZiu/uPZprvpK6JxJO9p3iHn9vECxPO8WzOmFK9JI0UNHE6sxduJmrzBgwpc1g4+nGmWjN+vpwyuGJkqvW7gb8sCNtFZxnfGNnW3fdQjFsZdeqszKLWlUOU1OGX+opZD61QDSyS4qzvtDIZDdcsCxbQ4sTzIAZK8oqfqFJAsmX4eXqOCyYeO+pEQ== 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=udWIBWqCP7In1BA5q84afMPWwqHCmqXW/Cac04rTBGg=; b=ofUeIfsAreV3v2SfDMrMQM+RymNarqmBR02UEyJtG3lgCHCq1sEw0dUJIIWTvtzKH+3Lq5PBfcED6BISKuStuxhp68rfQWx6YaT2fxd4LD7ptcQ5ThjqweHf0pWAkHV7CcZAnkL14XPcLrxTp20Qt22dly9vnNQuT1fEUaqh0Z4= 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 AM6PR08MB3813.eurprd08.prod.outlook.com (2603:10a6:20b:85::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.22; Wed, 1 Jul 2020 14:38:39 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c%6]) with mapi id 15.20.3131.033; Wed, 1 Jul 2020 14:38:39 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v6 04/14] aarch64: Add BTI support to assembly files Date: Wed, 1 Jul 2020 15:38:33 +0100 Message-Id: <538d810c304243abab025415ad4f37c29ac1b4b5.1593612309.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0066.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::30) 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.53) by LO2P265CA0066.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21 via Frontend Transport; Wed, 1 Jul 2020 14:38:38 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.53] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b7034c88-07d8-4701-fdd9-08d81dcc75e8 X-MS-TrafficTypeDiagnostic: AM6PR08MB3813:|AM4PR0802MB2225: 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: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: iK/KYAz4s380ve9ZeN4snwinXBjFjGil2JFzavRHnbW4XeKvVbICG50QEzPgcXOofr5B5EHuihluMkUoKx6E1lGR3cedQJvFmygnACV4xh2XEITzufKJRKVViqjR0PWTKPwnThNyFCe37YpuCkNd/AhZI0HTCdHpWKDqtamp3sFpC+XUQipZD7uJ2XBdaw88FRnfpinkdReXQf1qbt1AUCKAnm9q3a4x8ih0Io3xJF6xABziPHfph+IvNcEBoj9o2ecIizaPDcjDG7sa/MfduskZ6mRpE2Ier0nye64RYCY7xZQ8LI6HxgGFnVTNDagcqbcXb2y204vMwWvV+/yA1mCWS9X8i0+K3YflzFnX1mfoFBHAXWq9m+tWqRoTyRQiGDDqglICmbufU0h3pAvrtRnNBXjcLjHlfEnVtad/k7ikchXpYBKuG8WRxW+KxLbup8YrLafBtfHF7MavpPPzfeWGMjfW/3kAuXLoSeXUGlZA3GPbbNSGVh80nHVTlMj+ 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)(396003)(136003)(39860400002)(376002)(346002)(366004)(5660300002)(956004)(4326008)(6512007)(8936002)(69590400007)(66946007)(66556008)(66476007)(6506007)(52116002)(44832011)(478600001)(316002)(6916009)(86362001)(6666004)(26005)(8676002)(2616005)(6486002)(16526019)(186003)(83380400001)(36756003)(2906002)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7PVcS0dhZf40EfFh+0ldF0pwKSKB5S8OHzkM2MKrQV9994FCG5ngJvkYXn6B/Wcl76sDhTAP3vqS6yTaefuHwAoxf83ibLMjgetYK1migBkNMfN+EN8mtZlnSwN5yRrSbQs5O4dUBHjv+1cAXHRh4UVUENwA3MQVel+T5HP/bmp0PXQKfa5axdvuhvoIpeX0oZ5Mqc1/qa8PTKTTKLo+N8VtpQ+vmb9vAiqSM8x25OH3qOl1xfxixJOh+F4+XgxkCDiMFvg2xdOOBU0zYjxqT6D/2TjjZXquMmJ5JpurfOydDidJnOILiRYbAutx2kxtdK9qsYXC2npHSJ2KUU61L+1FfGPSnYTM77yUadT5qqSMxSxDlMwAer/W1vWDMw3VU0BugSfLzXGwZ2BBesqExmxz3UEANBcVyFTvWzjEamh4WXrQtoUVFWygM5R+yQO3cwJlp3asWhir2LqzOkppDUyHzLdCamq2nHh+fTVCdHfYKq5OaurDqQHzIdNiCcCk X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3813 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: AM5EUR03FT046.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)(396003)(39860400002)(346002)(136003)(376002)(46966005)(82310400002)(356005)(8676002)(2616005)(956004)(6486002)(2906002)(70586007)(81166007)(70206006)(36756003)(83380400001)(336012)(26005)(44832011)(8936002)(478600001)(6666004)(6512007)(82740400003)(6506007)(36906005)(47076004)(69590400007)(5660300002)(316002)(4326008)(186003)(6916009)(86362001)(16526019)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 171a1a96-6597-451e-270c-08d81dcc71a4 X-Forefront-PRVS: 04519BA941 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TfaBjMH8qJewlnp+I/daGQXJjBks83EjsFnIyORT9UplKeNsBhYD540tG+Wit4IcIT2ve32Ri4Y7Yzn9osmrJrWlSp4hYDuS3fT1axU73rMADJCFlLOrtnGScU+HPI4c1EjJbPZBXruXCy2TbKITo2+lHFmPC5Kg5Y2PxJt/LrMAxYmBXUu8yIESW245HpRRUb+lsrR25O8qbqstG1eqV5NJf7cC5Elzq4nJCQsAIaAZFkrZzMspwdME9a0TW4pcagEKHS4LmcsFqt2uZjmqRHFb2gNMOjk4k7jic6LK7TZUPezTpwn1gHdhTBYC/FtjtPN/8wVZDhnvEvR+KDwdn5EfXbpb/jsr0P2iG/66vsLsgPc9b2kM/Y3y5pIx4fg/hRRcPPpQJI2MjaJrM2QMQ6H3Wqwi5B4EVIn8lwmVQGvkoF0R3vC1WLOlXCsY3evdUkVUMn+cNmMM2tqQ+TUTd6cZ3Y0YzArYd1gpaK6IUTLsAuLpVd0RT3rJTO9oprAUejPfkd4UhUySI6NZjV51rMFAil27C5JD4MxmSSw55Kw= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2020 14:38:46.1132 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b7034c88-07d8-4701-fdd9-08d81dcc75e8 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: AM5EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2225 X-Spam-Status: No, score=-15.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, 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/multiarch/memset_emag.S | 2 ++ sysdeps/aarch64/multiarch/memset_falkor.S | 1 + sysdeps/aarch64/multiarch/memset_generic.S | 2 ++ sysdeps/aarch64/multiarch/rtld-memset.S | 2 ++ sysdeps/aarch64/start.S | 1 + sysdeps/aarch64/sysdep.h | 34 +++++++++++++++++++++- 10 files changed, 50 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/multiarch/memset_emag.S b/sysdeps/aarch64/multiarch/memset_emag.S index c4d3533c14..3c2e9d2903 100644 --- a/sysdeps/aarch64/multiarch/memset_emag.S +++ b/sysdeps/aarch64/multiarch/memset_emag.S @@ -17,6 +17,8 @@ License along with the GNU C Library. If not, see . */ +#include + #if IS_IN (libc) # define MEMSET __memset_emag diff --git a/sysdeps/aarch64/multiarch/memset_falkor.S b/sysdeps/aarch64/multiarch/memset_falkor.S index 54fd5abffb..154527398f 100644 --- a/sysdeps/aarch64/multiarch/memset_falkor.S +++ b/sysdeps/aarch64/multiarch/memset_falkor.S @@ -17,6 +17,7 @@ License along with the GNU C Library. If not, see . */ +#include #include /* Reading dczid_el0 is expensive on falkor so move it into the ifunc diff --git a/sysdeps/aarch64/multiarch/memset_generic.S b/sysdeps/aarch64/multiarch/memset_generic.S index 46c5329cdf..d746d1d00c 100644 --- a/sysdeps/aarch64/multiarch/memset_generic.S +++ b/sysdeps/aarch64/multiarch/memset_generic.S @@ -17,6 +17,8 @@ License along with the GNU C Library. If not, see . */ +#include + #if IS_IN (libc) # define MEMSET __memset_generic /* Add a hidden definition for use within libc.so. */ diff --git a/sysdeps/aarch64/multiarch/rtld-memset.S b/sysdeps/aarch64/multiarch/rtld-memset.S index 44bc479411..f9845bdd62 100644 --- a/sysdeps/aarch64/multiarch/rtld-memset.S +++ b/sysdeps/aarch64/multiarch/rtld-memset.S @@ -17,6 +17,8 @@ License along with the GNU C Library. If not, see . */ +#include + #if IS_IN (rtld) # define MEMSET memset # include 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..4664329d3a 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 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