From patchwork Thu Dec 9 17:36:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Corallo X-Patchwork-Id: 48717 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 230603858436 for ; Thu, 9 Dec 2021 17:37:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 230603858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639071420; bh=ohBayzqCDE4N5IVFDaAyC7ApPASHLW1k5GstAnuPcQs=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ADmEThCwrfc5uKA1CvGmYzHGstNc0PCJPyLnvgRyuSbzAqv/LmSqHa0mSswJy7A6w uNOF8ua/c+3CjqAb2htpUm7GPTArECM4S5yIKBTT0vSKbGmdNnl9M3qP1PeHGLnFJn UuyLqCiJSNzuZI8j3f+fKOWvvdOY/8a6vXtbz4AQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2040.outbound.protection.outlook.com [40.107.20.40]) by sourceware.org (Postfix) with ESMTPS id B38003858C3A for ; Thu, 9 Dec 2021 17:36:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B38003858C3A Received: from AS9PR0301CA0050.eurprd03.prod.outlook.com (2603:10a6:20b:469::19) by VI1PR08MB3773.eurprd08.prod.outlook.com (2603:10a6:803:bb::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.16; Thu, 9 Dec 2021 17:36:24 +0000 Received: from VE1EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:469:cafe::5a) by AS9PR0301CA0050.outlook.office365.com (2603:10a6:20b:469::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13 via Frontend Transport; Thu, 9 Dec 2021 17:36:23 +0000 X-MS-Exchange-Authentication-Results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT027.mail.protection.outlook.com (10.152.18.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12 via Frontend Transport; Thu, 9 Dec 2021 17:36:22 +0000 Received: ("Tessian outbound dbb52aec1fa6:v110"); Thu, 09 Dec 2021 17:36:22 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3b226be37aae3b08 X-CR-MTA-TID: 64aa7808 Received: from 22bf9366ee4c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 51C1112F-6EFD-47C4-A478-101FE9A19A4B.1; Thu, 09 Dec 2021 17:36:12 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 22bf9366ee4c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 09 Dec 2021 17:36:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z2ufwA+vGaAU6oDX08G0ZDqptfDKORB1N8ywiGqvKQzgO/Za9oGpy5LqRXXgloXWnQyQtb3gDDpAYz84Ba3x9WIZ7yZmTn92MagBDVAtAhVKSTbF0deJwCiAkKDN+ObrYC9qfcOVwv9efiDarOv6llSrnySjfUU77NupMJOvQScV9oiF8Z/Te8TO8cIf/bwIezSfcvw+lBoMwkayqJMiAZsbox6D0dEtz7kPvrXDId4BbuVsXfrNgDhuXqboZFsPD1GFGTFzEwiOf88OzKG/bODlvxaZ4dyrYzxqp/davFPHkGlmiNyFebKuq3dPclnA8FVowM5LpMQEd4mTb9nrgg== 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=ohBayzqCDE4N5IVFDaAyC7ApPASHLW1k5GstAnuPcQs=; b=GpBVc78SamUbYSv8ejkeWazhh20qrbvkBdu4TTqd3etxw/zGqxbR2x6n5yS90CMkCLrMYiCnEUDiY19g9Br3ZgJV16xGX4fvCCl6ZAB9RxbbKZ+wKatbCePrn/T1P1Nfr4n6w8A9Eq5/e+ZtunU+ogUHDO/81TMYbFPsRu5oyYb6wvg3nq0E1lEsNGU/KIJIyCHlP4mJOMtMvHGXMMAdLF3QBr3dJtZpKeeSfX8GGCkMYH+KxpLClHa6Hq7bWTNymXs/93NLE50xhCxyZmghb2y8BEvwrRP4bZQ01y6I6luZIxEM175lHCT7mDhqVxHQCkm/NbO0ckV1RSjCGNaIbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=gcc.gnu.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 AM6PR08CA0036.eurprd08.prod.outlook.com (2603:10a6:20b:c0::24) by PAXPR08MB6655.eurprd08.prod.outlook.com (2603:10a6:102:15d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13; Thu, 9 Dec 2021 17:36:11 +0000 Received: from VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:c0:cafe::8c) by AM6PR08CA0036.outlook.office365.com (2603:10a6:20b:c0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 17:36:11 +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; Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT043.mail.protection.outlook.com (10.152.19.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4755.13 via Frontend Transport; Thu, 9 Dec 2021 17:36:11 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) 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.2308.20; Thu, 9 Dec 2021 17:36:09 +0000 Received: from e124257 (10.34.101.64) by mail.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.2308.20 via Frontend Transport; Thu, 9 Dec 2021 17:36:09 +0000 To: Richard Earnshaw via Gcc-patches Subject: [Patch 6/8 V2] Arm: Add pointer authentication for stack-unwinding runtime. References: <85f6fc81-2e00-789d-174d-546a1e79dcba@foss.arm.com> Date: Thu, 9 Dec 2021 18:36:09 +0100 In-Reply-To: <85f6fc81-2e00-789d-174d-546a1e79dcba@foss.arm.com> (Richard Earnshaw via Gcc-patches's message of "Tue, 7 Dec 2021 14:36:48 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.90 (gnu/linux) MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 2a38242f-501a-469c-de31-08d9bb3a6b30 X-MS-TrafficTypeDiagnostic: PAXPR08MB6655:EE_|VE1EUR03FT027:EE_|VI1PR08MB3773:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: RrNIA0woLUgiJinhaJOsuywgJ2DTPaUBrISf3cMuYLIudbQcEg1ZReQoHdbLySXAtPl4/3jKJPuhTVRwt+KzS/B9NdqsxsmFvvVRB5kFuSX2lnmMqISgahv9DCNe3yvKOKU17t7pd6CdXUUppDjZ2Z74cvLeQrKzLUjcoXWl/JzJjof5NEJ9pMK/mH3gY8Mp1U8VwAgKJZCzk7uMZkDs1roVFb5G1Sh/rZbDnrcGngX92oiJTGQrxnaRVQ5VVrIWo4C8k+WRCcnGuRKGtE+SqP7xOKX+kf+sFTWIg6tGcqZgmjcGxdKC01h7Is13TXvsXv8KzPQ8edw/2ltETKv7jL46v/QtTaN2PFOsMdjVm9/bIC/Vb/MrHqNexx8kazYshFgsDEc1d8WCGC7srfAI4Oznrvzxso6bjs9wY2qNzqM2AtVYLWfC5KDk17DgFJu1mQfeRXhjLbJCcjH0um50EkPri8RA6ad7Bv/o5YwETfA9OLwuln0z1MBQwzO2jxH1Xbb4oV8FNjkWsIAtT7xGntAS6M+gK4h82KgYJp+OhCxEIc8gHkU6F8zMxJt7TdDbZu/Hc67fKwJQwbCNHTON2l36lEpwE4420s8FAWKhVcWnK7fMvWVs/wqyxzxbHV/qn13vMXnp7TeNka4/9wKK00wLjhzj8rKLf5Qs1RbVbUvfz63HU2+Pdh5tnaelWCOQ901BNhwrP0O/Q+TE2OeSAYHld5BdTHnM1g4pRmT7I7WFvJXVo3TMC494Lq7DtVwg/7/s3wKeXgU58I0R23Ices7dFO9AqI6XKa+0jxDaRE0= 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:(4636009)(36840700001)(46966006)(40470700001)(81166007)(40460700001)(33964004)(53546011)(356005)(6916009)(47076005)(70206006)(82310400004)(2906002)(186003)(508600001)(86362001)(36860700001)(316002)(336012)(2616005)(54906003)(26005)(4001150100001)(4326008)(44832011)(426003)(36756003)(5660300002)(83380400001)(70586007)(235185007)(8676002)(8936002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6655 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 5480ba51-0768-4b7e-ebb4-08d9bb3a6425 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zPpc9Wk7O/Ch0jhcjYtJLGf7AiPhg9XqPzjnY7pcIBV/UFC0jYBM8h0J7IC71bn1izNOMuaJBE4KOx0JAx6X+RYRhjpaloySDaISF5uFYTe5PgCHvhpl6+hJfQBCswMYKTF0nor698zPtM4e3Jsceei5qeipypoAQ7IP00m1rkJrdVHkFZ4wTu5oc3MEoQzMEoUWz+P9WbiqPskKc2VAxoBIbO5Cs7WOcgewuYvdy0c5OVhemR7vS7tWmlWMLBpB/iwmZySJXDpzVb8huHD2iKW99jfD5rp4WxkkC0CiJ5L+0e+EeV13dm4ir6MA0z+OcpncfCXP0DIM+a7GrV8asLMQQR0jfarEPkcgs1AR5EHSLdp2Awd/vpvAjTvgo/EwHLPiNUYAmGPyvQOSrAcPny5zNRGOyj7Jbl0/Cn+WwyYSXE1TIw/PdnOWNYT3ya3OkxbBcADAz/UsqndpCBP8sUuBHsexWpSOHjgMBfTRavIJqyIfL+bPYs6uTdTBSmep4t0Upl3IuNz0iyd7wqBjJ+C9OxeZyXly5//r+0SSuxkrxXq6D2B6Jd/gpGscWGheN+z4X/4d88mSktBk3kqXTwr+A8YR/BAa9z3q4UxSQRMnDfpg+wRRRYnAufJLHFlwLohqZAIdtQmp0LuT45aoc2qX0+v+aRnjgnclG1ZZANFlSWcEu2Kdbl+mEVPwrEJORIcuEcnlwXoMLLXTqKd8uj4uTSGhozlgJ5FLgG1cLful3t5YMyYm159TNH6X6iL6rUanGlVtydgJFjqKMN8Dmw== 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:(4636009)(36840700001)(46966006)(40470700001)(33964004)(70586007)(70206006)(53546011)(316002)(5660300002)(2906002)(8676002)(36860700001)(4326008)(83380400001)(44832011)(86362001)(47076005)(235185007)(2616005)(63350400001)(26005)(508600001)(6916009)(186003)(426003)(63370400001)(336012)(54906003)(36756003)(40460700001)(8936002)(4001150100001)(82310400004)(81166007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 17:36:22.9091 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a38242f-501a-469c-de31-08d9bb3a6b30 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: VE1EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3773 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrea Corallo via Gcc-patches From: Andrea Corallo Reply-To: Andrea Corallo Cc: Tejas Belagod , Richard Earnshaw , Richard Earnshaw Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Richard Earnshaw via Gcc-patches writes: > On 28/10/2021 12:43, Tejas Belagod via Gcc-patches wrote: >> >>> -----Original Message----- >>> From: Gcc-patches >> bounces+belagod=gcc.gnu.org@gcc.gnu.org> On Behalf Of Tejas Belagod via >>> Gcc-patches >>> Sent: Friday, October 8, 2021 1:18 PM >>> To: gcc-patches@gcc.gnu.org >>> Subject: [Patch 5/7, Arm. GCC] Add pointer authentication for stack- >>> unwinding runtime. >>> >>> Hi, >>> >>> This patch adds authentication for when the stack is unwound when an >>> exception is taken. All the changes here are done to the runtime code in >>> libgcc's unwinder code for Arm target. All the changes are guarded under >>> defined (__ARM_FEATURE_PAC_DEFAULT) and activates only if the +pacbti >>> feature is switched on for the architecture. This means that switching on the >>> target feature via -march or -mcpu is sufficient and -mbranch-protection >>> need not be enabled. This ensures that the unwinder is authenticated only if >>> the PACBTI instructions are available in the non-NOP space as it uses AUTG. >>> Just generating PAC/AUT instructions using -mbranch-protection will not >>> enable authentication on the unwinder. >>> >>> Tested on arm-none-eabi. OK for trunk? >>> >>> 2021-10-04 Tejas Belagod >>> >>> gcc/ChangeLog: >>> >>> * ginclude/unwind-arm-common.h (_Unwind_VRS_RegClass): >>> Introduce >>> new pseudo register class _UVRSC_PAC. >>> * libgcc/config/arm/pr-support.c (__gnu_unwind_execute): Decode >>> exception opcode (0xb4) for saving RA_AUTH_CODE and >>> authenticate >>> with AUTG if found. >>> * libgcc/config/arm/unwind-arm.c (struct pseudo_regs): New. >>> (phase1_vrs): Introduce new field to store pseudo-reg state. >>> (phase2_vrs): Likewise. >>> (_Unwind_VRS_Get): Load pseudo register state from virtual reg set. >>> (_Unwind_VRS_Set): Store pseudo register state to virtual reg set. >>> (_Unwind_VRS_Pop): Load pseudo register value from stack into >>> VRS. >> Rebased and respin based on reviews for previous patches. >> This patch adds authentication for when the stack is unwound when >> an exception is taken. All the changes here are done to the runtime >> code in libgcc's unwinder code for Arm target. All the changes are >> guarded under defined (__ARM_FEATURE_PAUTH) and activates only >> if the +pacbti feature is switched on for the architecture. This means >> that switching on the target feature via -march or -mcpu is sufficient >> and -mbranch-protection need not be enabled. This ensures that the >> unwinder is authenticated only if the PACBTI instructions are available >> in the non-NOP space as it uses AUTG. Just generating PAC/AUT instructions >> using -mbranch-protection will not enable authentication on the unwinder. >> 2021-10-25 Tejas Belagod >> gcc/ChangeLog: >> * ginclude/unwind-arm-common.h (_Unwind_VRS_RegClass): >> Introduce >> new pseudo register class _UVRSC_PAC. >> * libgcc/config/arm/pr-support.c (__gnu_unwind_execute): Decode >> exception opcode (0xb4) for saving RA_AUTH_CODE and authenticate >> with AUTG if found. >> * libgcc/config/arm/unwind-arm.c (struct pseudo_regs): New. >> (phase1_vrs): Introduce new field to store pseudo-reg state. >> (phase2_vrs): Likewise. >> (_Unwind_VRS_Get): Load pseudo register state from virtual reg set. >> (_Unwind_VRS_Set): Store pseudo register state to virtual reg set. >> (_Unwind_VRS_Pop): Load pseudo register value from stack into VRS. >> Tested the following configurations, OK for trunk? >> -mthumb/-march=armv8.1-m.main+pacbti/-mfloat-abi=soft >> -marm/-march=armv7-a/-mfpu=vfpv3-d16/-mfloat-abi=softfp >> mcmodel=small and tiny >> aarch64-none-linux-gnu native test and bootstrap >> Thanks, >> Tejas. >> > I'd like to try to get rid of most of the ifdefs from this patch; at > least, it shouldn't be using the ACLE PAUTH feature. The unwinder > should be able to cope with any unwind sequence thrown at it. > > Things are a little more complicated for pointer authentication, > though, because some operations in the main code constructing the > frame may be using architectural NOP instructions, while the unwinder > cannot do the validation using only the architectural NOPs. > > So we need a fall-back: if the unwinder is built without the PAUTH > feature it needs to unwind the pauth frames without the additional > validation (but it still needs to be able to handle them). > > So the only remaining question is whether the additional support > should only be enabled for M-profile targets, or whether we should > just put this code into all builds of the unwinder. I'm not sure I > have a complete answer to that. My inclination is to put it in > unconditionally - we haven't had conditionals for any other optional > architecture feature before. If something similar is added for > A/R-profiles, then either we will share the code exactly, or we'll end > up with a different unwind code to use as a suitable discriminator. > > R. Hi Richard, thanks for reviewing. The attached patch implements what I think we want. That unwinders is always able to unwind the stack but will perform authentication only if built with PACBTI support. WDYT? Thanks Andrea From 2ddc381d96038e82cd52fe3bf914275c1869abb4 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 6 Dec 2021 11:42:11 +0100 Subject: [PATCH] Add pointer authentication for stack-unwinding runtime. gcc/ChangeLog: * ginclude/unwind-arm-common.h (_Unwind_VRS_RegClass): Introduce new pseudo register class _UVRSC_PAC. * libgcc/config/arm/pr-support.c (__gnu_unwind_execute): Decode exception opcode (0xb4) for saving RA_AUTH_CODE and authenticate with AUTG if found. * libgcc/config/arm/unwind-arm.c (struct pseudo_regs): New. (phase1_vrs): Introduce new field to store pseudo-reg state. (phase2_vrs): Likewise. (_Unwind_VRS_Get): Load pseudo register state from virtual reg set. (_Unwind_VRS_Set): Store pseudo register state to virtual reg set. (_Unwind_VRS_Pop): Load pseudo register value from stack into VRS. Co-Authored-By: Tejas Belagod --- gcc/ginclude/unwind-arm-common.h | 3 ++- libgcc/config/arm/pr-support.c | 27 +++++++++++++++++++++++++++ libgcc/config/arm/unwind-arm.c | 26 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/gcc/ginclude/unwind-arm-common.h b/gcc/ginclude/unwind-arm-common.h index 79f107d8abb..8410f82461c 100644 --- a/gcc/ginclude/unwind-arm-common.h +++ b/gcc/ginclude/unwind-arm-common.h @@ -127,7 +127,8 @@ extern "C" { _UVRSC_VFP = 1, /* vfp */ _UVRSC_FPA = 2, /* fpa */ _UVRSC_WMMXD = 3, /* Intel WMMX data register */ - _UVRSC_WMMXC = 4 /* Intel WMMX control register */ + _UVRSC_WMMXC = 4, /* Intel WMMX control register */ + _UVRSC_PAC = 5 /* Armv8.1-M Mainline PAC/AUTH pseudo-register */ } _Unwind_VRS_RegClass; diff --git a/libgcc/config/arm/pr-support.c b/libgcc/config/arm/pr-support.c index 7525e35b491..5fb1b014bd5 100644 --- a/libgcc/config/arm/pr-support.c +++ b/libgcc/config/arm/pr-support.c @@ -106,6 +106,7 @@ __gnu_unwind_execute (_Unwind_Context * context, __gnu_unwind_state * uws) { _uw op; int set_pc; + int set_pac = 0; _uw reg; set_pc = 0; @@ -114,6 +115,22 @@ __gnu_unwind_execute (_Unwind_Context * context, __gnu_unwind_state * uws) op = next_unwind_byte (uws); if (op == CODE_FINISH) { + /* When we reach end, we have to authenticate R12 we just popped earlier. */ + if (set_pac) + { +#if defined(TARGET_HAVE_PACBTI) + _uw sp; + _uw lr; + _uw pac; + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &sp); + _Unwind_VRS_Get (context, _UVRSC_CORE, R_LR, _UVRSD_UINT32, &lr); + _Unwind_VRS_Get (context, _UVRSC_PAC, R_IP, + _UVRSD_UINT32, &pac); + __asm__ __volatile__ + ("autg %0, %1, %2" : : "r"(pac), "r"(lr), "r"(sp) :); +#endif + } + /* If we haven't already set pc then copy it from lr. */ if (!set_pc) { @@ -227,6 +244,16 @@ __gnu_unwind_execute (_Unwind_Context * context, __gnu_unwind_state * uws) return _URC_FAILURE; continue; } + /* Pop PAC off the stack into VRS pseudo.pac. */ + if (op == 0xb4) + { + if (_Unwind_VRS_Pop (context, _UVRSC_PAC, 0, _UVRSD_UINT32) + != _UVRSR_OK) + return _URC_FAILURE; + set_pac = 1; + continue; + } + if ((op & 0xfc) == 0xb4) /* Obsolete FPA. */ return _URC_FAILURE; diff --git a/libgcc/config/arm/unwind-arm.c b/libgcc/config/arm/unwind-arm.c index d0394019c36..a620d46f53a 100644 --- a/libgcc/config/arm/unwind-arm.c +++ b/libgcc/config/arm/unwind-arm.c @@ -64,6 +64,12 @@ struct wmmxc_regs _uw wc[4]; }; +/* Holds value of pseudo registers eg. PAC. */ +struct pseudo_regs +{ + _uw pac; +}; + /* The ABI specifies that the unwind routines may only use core registers, except when actually manipulating coprocessor state. This allows us to write one implementation that works on all platforms by @@ -78,6 +84,9 @@ typedef struct /* The first fields must be the same as a phase2_vrs. */ _uw demand_save_flags; struct core_regs core; + /* Armv8.1-M Mainline PAC/AUTH values. This field should be in the same field + order as phase2_vrs. */ + struct pseudo_regs pseudo; _uw prev_sp; /* Only valid during forced unwinding. */ struct vfp_regs vfp; struct vfpv3_regs vfp_regs_16_to_31; @@ -99,6 +108,7 @@ typedef struct { _uw demand_save_flags; struct core_regs core; + struct pseudo_regs pac; } phase2_vrs; /* Coprocessor register state manipulation functions. */ @@ -175,6 +185,10 @@ _Unwind_VRS_Result _Unwind_VRS_Get (_Unwind_Context *context, case _UVRSC_WMMXC: return _UVRSR_NOT_IMPLEMENTED; + case _UVRSC_PAC: + *(_uw *) valuep = vrs->pseudo.pac; + return _UVRSR_OK; + default: return _UVRSR_FAILED; } @@ -206,6 +220,10 @@ _Unwind_VRS_Result _Unwind_VRS_Set (_Unwind_Context *context, case _UVRSC_WMMXC: return _UVRSR_NOT_IMPLEMENTED; + case _UVRSC_PAC: + vrs->pseudo.pac = *(_uw *) valuep; + return _UVRSR_OK; + default: return _UVRSR_FAILED; } @@ -246,6 +264,14 @@ _Unwind_VRS_Result _Unwind_VRS_Pop (_Unwind_Context *context, } return _UVRSR_OK; + case _UVRSC_PAC: + { + if (discriminator != 0) + return _UVRSR_FAILED; + vrs->pseudo.pac = *(_uw *) vrs->core.r[R_SP]; + return _UVRSR_OK; + } + case _UVRSC_VFP: { _uw start = discriminator >> 16;