From patchwork Thu Dec 1 16:55:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 61326 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 DAA103858C83 for ; Thu, 1 Dec 2022 16:56:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAA103858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669913774; bh=XP7gt3R3rm4erXBW75Cvyuyv/FTWhfWsPkhmd5NLkFo=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=YsGi1LtQIqhoyxVwy17cRP1kPp3q93iKHRw+y2w0eQHykj2QOQPC7J/KC3DrK3/Kq T89iv6OzXzgSOH9oxihomtPhJs7Yw8poULDdktOa+5C+uJMhrYobxr7fCqAgcWRJ9r GI7TjK1ISTXRlFmL8ozUrzQssvwIJUhcS79zWrcM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2051.outbound.protection.outlook.com [40.107.22.51]) by sourceware.org (Postfix) with ESMTPS id C3AED3858C52 for ; Thu, 1 Dec 2022 16:55:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3AED3858C52 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IMQqgxtT5KN1XKCVY5kWAYx++p5qRH8Cg1FJVKW9aMfMhIJ1/1lJwMx+Mqvb++YWb03ByuuiWUUYsx+WWQSExkmUgfZPp42ZxtjiDCiGIjm924Vc2mXMFuLy59C8+4z6FZoqLXX12W0wLtvqtmZWcj/Rz9Ax1IugMhcsy/PqzyTlC3umVbWd56NjiQPlmE6euYF5TeeM2/wKJEUy/DX5bBgbWnuFkFdLdCFQ9NK9LNEqBCkM0JPtL/0PW0UjwUdy89oL/lP98VY16eAjoAt4ltexwUbdsuq0ParI8S9nVoVMamU9SMEbOSU8nWTwSP6HW3/92U9Y/8hW69WpPwZCmQ== 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=XP7gt3R3rm4erXBW75Cvyuyv/FTWhfWsPkhmd5NLkFo=; b=ULZvKNaGu40KIM2wNMYa2u7wMkBxkc4HGdL8wcROv1slQSyeYXkCq+HOOYTfr8tbq8qQbpUm0HQbh3J93kxn9z19tP9VUa9QLRSgd282Gipk0a4jPUow3C1OAZbtdo0OFM2Q34EvVT2N0eTYxX2fwnLgeATRZsm+uu9FmIiUYFetIK//SZNbD0rDPgde6GUkc8Z2nYnNqIdCLv7ndWrr4svf9Dw4SdfHlLoZ4W8EoBy62Txr9iu2YrRTy/TTDWNoe6Z2i6nbgG3yDY3sMJzPIHGh8+nkWudn7Q64OGceuas3anPZ8blvCdtX+IJslNmK406Xzcr13wcpkRjS2PMlHw== 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 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by DB9PR08MB6698.eurprd08.prod.outlook.com (2603:10a6:10:2a2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Thu, 1 Dec 2022 16:55:16 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::66e4:4940:d096:4f7]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::66e4:4940:d096:4f7%8]) with mapi id 15.20.5880.008; Thu, 1 Dec 2022 16:55:16 +0000 To: GCC Patches CC: Richard Sandiford Subject: [PATCH] libgcc: Fix uninitialized RA signing on AArch64 [PR107678] Thread-Topic: [PATCH] libgcc: Fix uninitialized RA signing on AArch64 [PR107678] Thread-Index: AQHZBaV7QJXP5PsIOEaE2xn0UPfNoA== Date: Thu, 1 Dec 2022 16:55:16 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PAWPR08MB8982:EE_|DB9PR08MB6698:EE_ x-ms-office365-filtering-correlation-id: b9d98b36-aa12-41af-2f65-08dad3bcd26f nodisclaimer: true x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2hoGP9IyY2nqzScOQYSeLuTq7t31hHzaVSgmjkA3RNGYjsfVOzkzTgkkWm42DHOkuHKPXu4Xz09UalJVefmPJ3px/hMPDaKBfww2ssgqSkxae/U5AYGnai0NcHQqXGn4wOVHGJ5sOkk+V/bajZc/NZKxTCOvNAF4gHX/vlzUPXXmE1UJuebRO22dyovj142Fxj3nFXlSOCIbvS9qNc1BE9EoJBmzOCRe3k3jMOqffqkqYpPqi/EIlG3oVTW+RIjQ5Fob9t0KcS/dp94hfBCEURL//OUg7Hdr28i1dVXQyLYWAyRkwWgYrdTrZfaEjYu1ZnOFQRWoSb00Cs1NhVao1noHJEoraQua+MtPP4LrRHYHLm2VF86H4Rrtq1pEgUpI1bGcuuCSpRWspCFPt+G+zw2MtMY7jf0qnHx2JwgATWbPa57OWwGPuSIk/D2gsSqhFo1rlD2UMjgWuKuvr1cUSZmtox9HqtZkY44SllV//PN7k/HRhkIgZHL5yplpcHmuVwLuV43XKLjGjCV4Mb88z4I1i6aGT+Ffzr1XqH2J4O2r4EoMvJv5yWD1ow553dc/WYCgDClkz4WmmRZS14dnUgCuD3RP6/E7dWHEZmrdsskNKbqLOUOcQJVANx6gRuFmhH88NoP+gwBtljFUBri0uP3pVwLRrrhfcMNx9NxvltWYk6F/iMxQeHE1hDfPxRiOJn3nGxe5E+i/PIEB6+76mw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAWPR08MB8982.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(39850400004)(376002)(396003)(346002)(451199015)(2906002)(83380400001)(38100700002)(91956017)(66946007)(7696005)(9686003)(66556008)(66446008)(76116006)(8676002)(33656002)(26005)(66476007)(64756008)(71200400001)(478600001)(122000001)(6506007)(186003)(8936002)(5660300002)(41300700001)(316002)(4326008)(6916009)(55016003)(38070700005)(52536014)(86362001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?bvv3bqKOXa+eEdG37p5glvY?= =?iso-8859-1?q?KMetLF8P7tW7KVwg9hl7kZh1ijXb8A5s3zk58sQP/3tmQOzadUR0POowhi09?= =?iso-8859-1?q?ql5BSYdgyLL6sA/9uNSrnaJwnGeeqmwOcUxhu4k2OS+ZCrpy2Wvd/ePu19ZF?= =?iso-8859-1?q?LI27h9knoD5mWWiJrR6gh3dMJj5+R6EFbUblkVqX+2soljRcbpDd4QWWrgcz?= =?iso-8859-1?q?u2SsLw9P8ooMcRfD0LVq4UkjEcN4GnJj3PnZmw98PN/F9IMsCzpvb+q1CCuM?= =?iso-8859-1?q?YOX8z1RoTl141ajmyM1Y+xmPghQ97AWwacdcr2vA2Lpj3bO2FDVdrHXcknrp?= =?iso-8859-1?q?qwiYd9uZfflwvHlmf+REjOCvPVRqBG7V1FverMsLyvoKOwObheDZwllUq7rY?= =?iso-8859-1?q?wDN9yvC3wqlHdWlAU4HxmuOiBWbFiDe0afC6MFHHBEk2U8B1ySHCJ0soswBh?= =?iso-8859-1?q?vCczwt3ie0U9+Auvjixm2sGPKaCHlwBrLB4o8mf8zkV59M746s+s1HhhPpMo?= =?iso-8859-1?q?OaORNOrHVYs4m5fhBn5rNW9HXDIJh/StACzjmv8Ac9opgxkZ7bos1ONHer7X?= =?iso-8859-1?q?xQO8psGpFH3eYvX4ZKICqzmKkGNn/2goNCPg28PvNQiq0v0IZd4YYn8m1NR8?= =?iso-8859-1?q?AQVjq47pYPq3IamfI9GrxyxbG75uhWD+f5KHZrwS/t7aNI+Hg4QQ6/3guoqV?= =?iso-8859-1?q?qQqM0v4JvHWzb20FnTCf+x1O7lREztLaCNFypAG7g2biXTzTV6FKCeUQo+P1?= =?iso-8859-1?q?HqJ0qVfKHUOVHD6puLKCrqGMKFEeNdxTKgJ92vVkM+lpaY0OdsiDPuHMchUK?= =?iso-8859-1?q?cmTMg4DdiF813vaZUnKhCP1RebF3omIT4YX5vYTa/a3QuWIW79Udg0fs6L2X?= =?iso-8859-1?q?7zJ+CukrrDzYYuv9xtU/KgGDwneNOJyKQVr0gxeII9g7Zj1Vl9D3PrTeLiEt?= =?iso-8859-1?q?AUOiyszHqtOnE7iMZB4IF39MleO0XtaBC0HBiFsS0x73sdR/mEYWDKQU0CF3?= =?iso-8859-1?q?QbGYhx9XP50GJt8NAGL6Wo/F2xmwwoAUltj+CQuNqFjbsqRIs+RTweHCyCh6?= =?iso-8859-1?q?CLn0C36+0F/8St5faIBGdTyfHssV81FOA6MOwU8cUcQrE3SVXd44kXfFu/GE?= =?iso-8859-1?q?l+kRedO6gaKjGRW/nlenhDevXFaO3jHYHNuU/AAToAvkYFeGthhro7CkeHB8?= =?iso-8859-1?q?jCWU7Um5dh0Sdok+UWz2CtqZXXhiABSZxDTz+GLFq2tTya4jymQ0NloZ1NpJ?= =?iso-8859-1?q?iz39ePPWrNvQStcEmVr/x5f0EQJaODgs/0FuTLh3uXk0AdGdB4yZGMFkFMl8?= =?iso-8859-1?q?XvBOpofJpDEWZXTQf8TqIGdhAqqF8m/+kWvgNrSgtKEj3UoIkqM7iGs8kHOm?= =?iso-8859-1?q?yWQdneS87lmEan2Ok4/55yrBARAyuZSM+xdpBAhQcTdMk6QFZh/iHbGM35E/?= =?iso-8859-1?q?Od2/99vIr1K0ejVFIzPbX17wNvPBLO1As9QPHj7SvZbk8yWjHmsHQfo+XSna?= =?iso-8859-1?q?AjBFxv8fdbwJT7d34s8UIVVmXCn3YpGnd+KRuaWtNERqU7dWue3yCYBG+zMq?= =?iso-8859-1?q?3qJlQNZQKVD2DJneZpuNH9YMG3T1f0vgCRj4v2L4TIQwcmqXIfZXO0dLPIdM?= =?iso-8859-1?q?qSPYw4hgYQJ2Cx49G?= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PAWPR08MB8982.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9d98b36-aa12-41af-2f65-08dad3bcd26f X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2022 16:55:16.3535 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Pv1Ts2rhwBlrUjS/QE5rJNK7GeCE8oZmZ9p8fKgQUlOe9YFmCAus1UnUXN+W4SY9P3+6o85NDYwln2KU+oK/IQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6698 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP 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: 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: Wilco Dijkstra via Gcc-patches From: Wilco Dijkstra Reply-To: Wilco Dijkstra Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" A recent change only initializes the regs.how[] during Dwarf unwinding which resulted in an uninitialized offset used in return address signing and random failures during unwinding. The fix is to use REG_SAVED_OFFSET as the state where the return address signing bit is valid, and if the state is REG_UNSAVED, initialize it to 0. Passes bootstrap & regress, OK for commit? libgcc/ PR target/107678 * unwind-dw2.c (execute_cfa_program): Initialize offset of DWARF_REGNUM_AARCH64_RA_STATE if in REG_UNSAVED state. * config/aarch64/aarch64-unwind.h (aarch64_frob_update_contex): Check state is REG_SAVED_OFFSET before using offset for RA state. diff --git a/libgcc/config/aarch64/aarch64-unwind.h b/libgcc/config/aarch64/aarch64-unwind.h index 26db9cbd9e5c526e0c410a4fc6be2bedb7d261cf..597133b3d708a50a366c8bfeff57475f5522b3f6 100644 --- a/libgcc/config/aarch64/aarch64-unwind.h +++ b/libgcc/config/aarch64/aarch64-unwind.h @@ -71,21 +71,15 @@ aarch64_demangle_return_addr (struct _Unwind_Context *context, } /* Do AArch64 private initialization on CONTEXT based on frame info FS. Mark - CONTEXT as return address signed if bit 0 of DWARF_REGNUM_AARCH64_RA_STATE is - set. */ + CONTEXT as having a signed return address if DWARF_REGNUM_AARCH64_RA_STATE + is initialized (REG_SAVED_OFFSET state) and the offset has bit 0 set. */ static inline void aarch64_frob_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs) { - const int reg = DWARF_REGNUM_AARCH64_RA_STATE; - int ra_signed; - if (fs->regs.how[reg] == REG_UNSAVED) - ra_signed = fs->regs.reg[reg].loc.offset & 0x1; - else - ra_signed = _Unwind_GetGR (context, reg) & 0x1; - if (ra_signed) - /* The flag is used for re-authenticating EH handler's address. */ + if (fs->regs.how[DWARF_REGNUM_AARCH64_RA_STATE] == REG_SAVED_OFFSET + && (fs->regs.reg[DWARF_REGNUM_AARCH64_RA_STATE].loc.offset & 1) != 0) context->flags |= RA_SIGNED_BIT; else context->flags &= ~RA_SIGNED_BIT; diff --git a/libgcc/unwind-dw2.c b/libgcc/unwind-dw2.c index eaceace20298b9b13344aff9d1fe9ee5f9c7bd73..87f2ae065b67982ce48f74e45523d9c754a7661c 100644 --- a/libgcc/unwind-dw2.c +++ b/libgcc/unwind-dw2.c @@ -1203,11 +1203,16 @@ execute_cfa_program (const unsigned char *insn_ptr, case DW_CFA_GNU_window_save: #if defined (__aarch64__) && !defined (__ILP32__) - /* This CFA is multiplexed with Sparc. On AArch64 it's used to toggle - return address signing status. */ - reg = DWARF_REGNUM_AARCH64_RA_STATE; - gcc_assert (fs->regs.how[reg] == REG_UNSAVED); - fs->regs.reg[reg].loc.offset ^= 1; + /* This CFA is multiplexed with Sparc. On AArch64 it's used to toggle + the return address signing status. It is initialized at the first + use and the state is stored in bit 0 of the offset. */ + reg = DWARF_REGNUM_AARCH64_RA_STATE; + if (fs->regs.how[reg] == REG_UNSAVED) + { + fs->regs.how[reg] = REG_SAVED_OFFSET; + fs->regs.reg[reg].loc.offset = 0; + } + fs->regs.reg[reg].loc.offset ^= 1; #else /* ??? Hardcoded for SPARC register window configuration. */ if (__LIBGCC_DWARF_FRAME_REGISTERS__ >= 32)