From patchwork Thu Apr 28 09:44:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Corallo X-Patchwork-Id: 53299 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 45C803857350 for ; Thu, 28 Apr 2022 09:44:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45C803857350 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651139090; bh=AIiZcAM8kx1tOW2z+W0mziUxDe2C/98PvhcV+q3fGeU=; 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=cUwt348a8HljsaRgfNSDC/bNw3wXTPHeXIvNz0Mzk8DMTNbLTX6DKAuHKWLiq5rwL dTyi4muf9wCk17hdXwSsKQ0fSSSShA6ekEMOn+tesbSo2JbQyPuKSEJOLYhp0WoX3T 3vmgfU+dDLeEScDl2/4QL5160e2A0VZ/1/qPm5OU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30086.outbound.protection.outlook.com [40.107.3.86]) by sourceware.org (Postfix) with ESMTPS id EB8F63858C2C for ; Thu, 28 Apr 2022 09:44:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB8F63858C2C ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=I2FjOG5RmHVouwQhUBipmfnbFy5TdqjCXmreZzapVTFwFplYCoxWVa7sdWLf8CTGxokwsA4o7hHGys3Mjcgw7V5rWtdwoggIszhavJiao+5oS7fHW78wy3qo2lIEGTHvazPtDrhY4oSmNt8htqi9Cv5GdCbElTvdQVZkQ7uz+H3i9lm3SqYET/bKbNNxbqZFSIf8OL9fL0YL9jGuAnHfDslHWnB6IJAvYZj0n75rahE1zQPqtC8GMHu7MwaqQT1WIu0Z++swyUsPGfnUsZpu7YgrE2PVN35P5Rl0ePGktCF33z8+IrWgHR43LEui9axoOF2TflwS1v2/fqAHG26Gew== 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=AIiZcAM8kx1tOW2z+W0mziUxDe2C/98PvhcV+q3fGeU=; b=ax57FgHaDOxcxdavz2SA+1Tfz2boMe8fT2X1uNvi3aVs3EDDm1+D65hEpzLWyjWhwEEDm9u9qs9QfLQjkCOZMNG3P0uOFqz+1SEHVYOAI74xUJtyeVBGVtuPKQ/StshkowVhzs0jMOf9Ffm0qXuBNjtdsQ7+/bTH3nZdp2Na2Vk/WwF20ufPS19viM3oc8ZnIBmbKF3faLbBMpRV7qyOkQ6gWaSBuuwOtVn7PqI+6jV+lGLaWk11XCPAmNo3YeIkjfs1bEuA7IdedKEMiq/vhl0eIJoqCy6fxP0vy3n/S21VP/LF4le1/POjeUBeDRD3sr5o6AYRZ3YqAO3Wt+20ug== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.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]) Received: from AS8P251CA0009.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:2f2::34) by VI1PR08MB4143.eurprd08.prod.outlook.com (2603:10a6:803:e9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 09:44:16 +0000 Received: from AM5EUR03FT028.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2f2:cafe::e3) by AS8P251CA0009.outlook.office365.com (2603:10a6:20b:2f2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 28 Apr 2022 09:44:16 +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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT028.mail.protection.outlook.com (10.152.16.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12 via Frontend Transport; Thu, 28 Apr 2022 09:44:16 +0000 Received: ("Tessian outbound 9613c00560a5:v118"); Thu, 28 Apr 2022 09:44:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b54dcc030e492759 X-CR-MTA-TID: 64aa7808 Received: from 02d2210a5c7e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 34AC16FC-55FC-43B1-847A-2254F078D482.1; Thu, 28 Apr 2022 09:44:08 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 02d2210a5c7e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 28 Apr 2022 09:44:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fPLKnepKtAVAVJNDUHcvCMZAH81+EDms7p6XWlMiLn+iDBKY0/zdHsFFyV2wfQsL9i+FgZfRLlLzmHxDfXN60TcG6mSEWWMrODWDTU7Awx2e8m1ENrTA0kNBg5J58693HShe4IHBja/8j2tL6Q62uDEhC0hVLExREXu+eAyCkEsMhMsiRzDPzo2tJdTw2r5F85Zwn3wtA2iizjcEzUbHCLgcDar2hD9o5obZDAV/XgZ/ELMdHUO+tBZpGjO94fmcEUmVnyyStuQ7u6P5oar2vVJMCT+CEowlMP7a7tld+zTJh5P3R0kyPLmzSyBJmvdxOHPOa5zsi32mMy0cqzYQ9Q== 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=AIiZcAM8kx1tOW2z+W0mziUxDe2C/98PvhcV+q3fGeU=; b=SVuJrEVaolIsuTL1t8+yqppdRFmxOIbEsGtCdRIjPqdX0Gwa2iE4gvmMXwdhEkAM7Hqf0+vNKVci1l/LhxlpvSov0fAEeRWSTGnHUXGE4ep+hhFyXjOGLkKg2wjJkknP8smOVEAxXF1zhj+EVy/YvkIIhQS7wttxVb8+qbxjVp0MT9sedE78NzbLVdKbpaaotKKe8YxX8r+f6WP/jGbY7UqCukIPhAaElxD9tJCVRthpzshq4N3c6AhykXeQteLqm1FAZNww1esHM+bvaDjKmShO74VvCW+10xVds1/q58pp+E+0bA5b20td0ODkkzI579ZzskBbR9awQ9MPqIMj8g== 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 DB8P191CA0012.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:130::22) by VI1PR08MB5341.eurprd08.prod.outlook.com (2603:10a6:803:135::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 09:44:06 +0000 Received: from DB5EUR03FT022.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:130:cafe::47) by DB8P191CA0012.outlook.office365.com (2603:10a6:10:130::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Thu, 28 Apr 2022 09:44:06 +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 DB5EUR03FT022.mail.protection.outlook.com (10.152.20.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5206.12 via Frontend Transport; Thu, 28 Apr 2022 09:44:06 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.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.27; Thu, 28 Apr 2022 09:44:08 +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.27 via Frontend Transport; Thu, 28 Apr 2022 09:44:07 +0000 To: Andrea Corallo via Gcc-patches Subject: [PATCH 6/12] arm: Add pointer authentication for stack-unwinding runtime References: Date: Thu, 28 Apr 2022 11:44:05 +0200 In-Reply-To: (Andrea Corallo via Gcc-patches's message of "Thu, 28 Apr 2022 10:39:31 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 1fc9ca1f-6780-44fb-aa7c-08da28fba8e4 X-MS-TrafficTypeDiagnostic: VI1PR08MB5341:EE_|AM5EUR03FT028:EE_|VI1PR08MB4143:EE_ X-Microsoft-Antispam-PRVS: 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: YTRUu+NLxaE7ukfVNNVLoeTTOJPGal/kXc+K7vY3nFQGXVj5oghjX4ek+pIeMgC8Wd9h+pBPptXsy4c7mEvSRt8h8z4BsZWAMC632T/tZiRK/XUoUls4rcQrIyaDoKwKgb4Yd5j+DBci0QfnEYh3++4Pu/vdpnEUuFCybBFQJsSwRWAM4m5rnp/f2Ct1INNOX6YwqNxXnCMs9Mfo2jpc98hg62Skio9tGCtdfgWYQCeu7OvsFisziL9gQDnlWPkPcxZCwOadwc0J6WgTja46PMtjI4rpnuzFtmQujSevm+PyzmRdc3tcN9J5uwseGSaR6AegoGPmKnGKZiCoS4m6oyDtVSi8aHmpfg5vfQs4CC/do+wu0QZZh6jFktTSp8xpCPN68kdGboYbWrpTBpdUUJCzmEsUFT3Yn6i73w3YevLCbCNGRfYQKfOZYdJWUN9MvQVj8EYdNJ3V/KIk8Ej+cz/xbVOQNo0N3uB2gBXdKrMGt3xZDjIevXHCsEo97CTpNd0LSQ5E691hX5Eailow2Kv0xnbKjVu9FGNMHs1O3B4eYoMf+cBEEUGEbwD2efqWPULYuIKOrqu0xgnCxIqrwkrGck8BVbVm3foPUPJDep000OWD80mAm2JHfBvQTslz8K4jOqkHJZhS3HH4+6v8HuSWkzuZmQNhu5kJaSKQBOVG/Cc92x6zOgC4QRg2ajs6l9dmp+LfvWQ2OA/z+DldCiocddVAzF9W/wJ5tEMqh3uolKjNHzK8/DlEQA44FfRQOhctmD+olWZP6RGKvIbtWobS3Gfw8y3tZCC6FAWwZTw= 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(4326008)(8676002)(70586007)(70206006)(2906002)(33964004)(36860700001)(356005)(40460700003)(235185007)(86362001)(5660300002)(44832011)(8936002)(508600001)(2616005)(83380400001)(26005)(47076005)(6916009)(54906003)(316002)(36756003)(336012)(426003)(186003)(81166007)(82310400005)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5341 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 08e1b633-cbdc-48d5-73fc-08da28fba2f8 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ngsq9Ccgqv+6PnpHquJ2xZKcRViXwTeB3pzKevOamYw6uuJN9Cyekusyp8mFBpShnrSH4NhAr6/Sdq9b9ZWBmIEpnJHgFhXb5Adlz45Gaer64OMBflFlVTqdfDDHSvU7jLwsFDwFnkVX1SVAQFlM7uZ/VZhK/Pq79MbPrvLNSDgrDl/uBK2UPHXtjfh0AeB5bmbMerVvDPflamvafZ7/USq6K1cYgQ1O4INU6HzkHoG2zSmaSxqXiYKgXwJr2sfZggI3Z0DK5kA6ljdVTmjwxTPmguDL6D/lFvpCK5+qtcTDE+hGNYUyTzHsuHrCQvAxbTHKVlDmqtoHJC4LbNIm88/OALfUYZYElBumuxmeQDOLLeddLMhp5dNPjUOtjrW/ccYbaWh3yU1N6l+Bc82mKigYz4EggGb6nRuQq96ohqWJF3V+F0HYAtoZ35uDxsExC6VD3ajCFBR8xU4r0CWyK45tjB4PCjIsWCBiH65wnw3OQVHOCooBvDvQSlnloNSqzimVP/LP/AcK9wmoEcm8ailmfQWx9V7oCpgNpYoJvKcguzEojgL1DHF5nuCTtKTN+fQprhP6+q71ipO7NaDzll/FI36mEs7iNM0WC043D39VStYunTWRMZY+LVcgNmYY0P606Gwy9xeKWGkkcbBxyTkH+1CBHj8fWTCvYzXIrlZsf4Ja4CIj3BBQ4Ok/8NXoGuATwsqw9dH5K5HB7I12CNFbMPgA5AD+8WlLHq6hk92yr6mrhKs1YfmZ9vyc+X19MkSrm7sPzMYTIrXaqbuQaA== 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:(13230001)(4636009)(40470700004)(46966006)(36840700001)(44832011)(33964004)(316002)(54906003)(4326008)(40460700003)(8936002)(70586007)(70206006)(508600001)(5660300002)(86362001)(81166007)(2906002)(235185007)(36860700001)(82310400005)(6916009)(26005)(336012)(426003)(186003)(47076005)(36756003)(83380400001)(2616005)(8676002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2022 09:44:16.1182 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1fc9ca1f-6780-44fb-aa7c-08da28fba8e4 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: AM5EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4143 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, 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: Richard Earnshaw , nd Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-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_PAC_DEFAULT) and activated 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. Pre-approved with the requested changes here . 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 diff --git a/gcc/ginclude/unwind-arm-common.h b/gcc/ginclude/unwind-arm-common.h index d3831f6c60a..f26702e8c6c 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 2de96c2a447..e48854587c6 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,27 @@ __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. + + Note: while the check provides additional security against a + corrupted unwind chain, it isn't essential for correct unwinding + of an uncorrupted chain. */ +#if defined(TARGET_HAVE_PACBTI) + if (set_pac) + { + _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 +249,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 386406564af..89f945d047e 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;