From patchwork Fri Apr 24 08:19:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1276244 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=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.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=WGVZ+qgo; 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=WGVZ+qgo; 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 497nCq1jLmz9sSX for ; Fri, 24 Apr 2020 18:20:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B5593893665; Fri, 24 Apr 2020 08:20:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00077.outbound.protection.outlook.com [40.107.0.77]) by sourceware.org (Postfix) with ESMTPS id DFD853893662 for ; Fri, 24 Apr 2020 08:19:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DFD853893662 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=Jk1FQOMVEP20qlraAY83tr1z6Xk5k3R6hjUgaXdpsbI=; b=WGVZ+qgo6PrjJ/ef3LAOv0m+OlgEGDTob23rlKJuvW0uEEURT6pfye0L+ubUE0rTnsQ6v6m1DyEfeiqsmsPJkZHMzBfbnEfwUyVKNZn9/3jyDD9ku/9bBmuWB2LJFcVkVDzb16Xw/7Aooge4S3mB3vj8vudFxwX1OAyiLlNfUw4= Received: from AM6PR01CA0064.eurprd01.prod.exchangelabs.com (2603:10a6:20b:e0::41) by HE1PR0802MB2348.eurprd08.prod.outlook.com (2603:10a6:3:c5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Fri, 24 Apr 2020 08:19:55 +0000 Received: from VE1EUR03FT026.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:e0:cafe::2) by AM6PR01CA0064.outlook.office365.com (2603:10a6:20b:e0::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Fri, 24 Apr 2020 08:19:55 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.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 VE1EUR03FT026.mail.protection.outlook.com (10.152.18.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.19 via Frontend Transport; Fri, 24 Apr 2020 08:19:54 +0000 Received: ("Tessian outbound cbb03e3a1db0:v53"); Fri, 24 Apr 2020 08:19:54 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c2cffc0ee9b8e8ee X-CR-MTA-TID: 64aa7808 Received: from e18c4ccb069a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 304ED5B7-9425-4027-BA69-EF805BE237DF.1; Fri, 24 Apr 2020 08:19:48 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e18c4ccb069a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 24 Apr 2020 08:19:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jMMGEZE7GiLFhC3W5415BZiRf+d+WG5wRrZm+JL+hBgTczIOoLzs2JwsMU1bRrHsfHJUTwOr6Lg+CMrX+1s8mS1TsX8VjNI/IGb+bXQoYH4f/p4WCh4CQq9LEVMeILuKPhUJlw787/6EoBI5gBPdXVRfUDPRNGfNHJrvgR1Ytv1XZPRy0mwWQM5U1Ia4+Xn/pl9l/uLFXrF/l0m/HHJfWCQqgZjmyP6kD8VZ3zw5/1274H77P1AyouGCM24e3MmrWgXdQGcM3ecUMpLLaTn8ZOmcbl0x8bCkf7Bgkkq42uc24jYhmyKRwnFnjaxHaV57IGa5VaH0Qt9wDb9mH7LTSA== 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=Jk1FQOMVEP20qlraAY83tr1z6Xk5k3R6hjUgaXdpsbI=; b=LrtTgFhS4EPuYk2hNBAC+OBgXcya//atiCf0cMeKmo8imp/vgUGiQrxT6q5/DX0N2ad+dEAbqAEWR6WbaLaSzjWiB7fel9XhL5+mLbh3+pWkuYMNcBJy7Scpg06Jj+CY66SYn2GVav3qOIl5nTQ6ZhrJo4mW/smyhj/VDr+AqciFqlYZ0MzO7xuJXIeSPmzy1wl5gqSaXhItyW6KwAMrce2RBrvXjqA+ysDKohRvjGD1GnsxBwQRAgsEgaCqY08QoW37i9yh9BJijaKq2neXqgla6X7pd1G3madj/gTtbxjH/INUm5UMdo5DolGcH9udl+VoEq1BJr8rhed4z2lKrQ== 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=Jk1FQOMVEP20qlraAY83tr1z6Xk5k3R6hjUgaXdpsbI=; b=WGVZ+qgo6PrjJ/ef3LAOv0m+OlgEGDTob23rlKJuvW0uEEURT6pfye0L+ubUE0rTnsQ6v6m1DyEfeiqsmsPJkZHMzBfbnEfwUyVKNZn9/3jyDD9ku/9bBmuWB2LJFcVkVDzb16Xw/7Aooge4S3mB3vj8vudFxwX1OAyiLlNfUw4= Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB4088.eurprd08.prod.outlook.com (2603:10a6:20b:a9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Fri, 24 Apr 2020 08:19:45 +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.2937.020; Fri, 24 Apr 2020 08:19:45 +0000 Date: Fri, 24 Apr 2020 09:19:36 +0100 From: Szabolcs Nagy To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] aarch64: Fix .cfi_window_save with pac-ret [PR94515] Message-ID: <20200424081936.GF29015@arm.com> Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-ClientProxiedBy: DM5PR07CA0099.namprd07.prod.outlook.com (2603:10b6:4:ae::28) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.55) by DM5PR07CA0099.namprd07.prod.outlook.com (2603:10b6:4:ae::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Fri, 24 Apr 2020 08:19:43 +0000 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e71193ed-19aa-43e8-4588-08d7e82844b3 X-MS-TrafficTypeDiagnostic: AM6PR08MB4088:|AM6PR08MB4088:|HE1PR0802MB2348: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-Forefront-PRVS: 03838E948C 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)(39860400002)(346002)(366004)(376002)(396003)(136003)(7696005)(52116002)(66946007)(26005)(4326008)(2906002)(8886007)(956004)(66556008)(6916009)(36756003)(2616005)(66476007)(8936002)(316002)(54906003)(81156014)(6666004)(8676002)(16526019)(1076003)(86362001)(186003)(5660300002)(478600001)(33656002)(55016002)(44832011)(142923001); DIR:OUT; SFP:1101; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: TKpbw/QH6Os6EdVqD0D49YVl20p8TewTWdQNtxOROd/yhfephLK44RHtA4S8m9IKhFdQ8hVCEry936GeZY4Blez7khimBDlXrBgiFbg0dNccISsDkd2R4lpLQVrpJzHoQXIy6ejDqHyExB0CbndiOuunwSzOT38B0jPvu8AGfnC/Ca7o11T/s4QUNd5Y37EMGByrR8WSE+Ca7UhQC8TMldPsBXsYs3Rhf/Zw8r3CB1EjWYeuc1q2TvP1CCG8neCcDEoDR2q9+S8r9LkvPFJ6pQA39NqgqqhPPk+J76odFOKY0M9XnuQKIXDRsrfpt0OyJCIJgSQTv0D/shHNeaLCVoyud/nANVwL2LB+cnNyHqIju1MyS4GnoX+qBjNuDpM4cmnihilUIKIE1hJP6AeYPbSShv5GxaC6pFUuCLSb7GcK3tWONHqSOHTv1Y12Krd4YYyaSCG3uaq1xW4WqciW4aFXodnWAv5+A2AdUtUC0WOVK6YTNpyby4ElZTHE3KY5 X-MS-Exchange-AntiSpam-MessageData: HVUaZIjaomB8JDQe6FY25FAi2rwUPgTcNjMI/is1a93TksW4s7y9+5M7ZnxviWSsbh7vqW4BpF+ciB7UJF8IshnG6c6pHHg4GbfQotucA25RkXR/rG4sWQHDt3Ye7R8Ueb9khvG2sivDydSkiN4ZWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4088 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT026.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)(39860400002)(346002)(136003)(376002)(396003)(46966005)(1076003)(4326008)(8886007)(7696005)(8936002)(81166007)(55016002)(6916009)(26005)(33656002)(6666004)(8676002)(81156014)(82310400002)(356005)(16526019)(36906005)(186003)(336012)(956004)(47076004)(2616005)(2906002)(44832011)(82740400003)(316002)(478600001)(86362001)(70586007)(5660300002)(54906003)(70206006)(36756003)(142923001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 3f092839-89c9-46d7-e1e3-08d7e8283f01 X-Forefront-PRVS: 03838E948C X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eLok255JutrehkjsUiBw3PlH/AUcFMmZ+Mlo2oVtLAIWupMlNlRA46JVFuiKA5bDZGVes3fJunpZOCWXh+heW+m9I4x5ScF9v90mW9XWZwARejiAj293hd/DWXw1lryAfVdNV87LSgdXx2KKuwZdknSq2EuXxMo2L4gzIjqAXxqaBOMsGqnkNspPfy20SnQxrmg8AIb92yBdAIkcxBUDBVmeOQ+MYSBXIjHse8Xml1QSEz71GoVczXieHoICfKSZX3rUWq0tvN0Wa1WC13c4VJl1WwT4gHV40N4cswx3axPTtv+JfTPfd/5FiCY7cDY7y5njrJnD6qnlGt7KViAfMFPU+jklBxbU0e/7HhZ+dQ0TAeka2RetBEXh25HDUm1ASyfduOmqLb8GJLNfM7j2VA6Od8SL9U7zElzLvRFxZ7uKQvfO4HGbwyc/nylAjbUxqK0ej1VBh+RkAcmDCswAyv2waktUVkWaOzRjFYrDpH87GdQUFeYrJGVdhylO4YEvseLlltgYCDyff45+jhG0xy/oJrYhi8ETdKPi+aalyEs= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2020 08:19:54.3910 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e71193ed-19aa-43e8-4588-08d7e82844b3 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: HE1PR0802MB2348 X-Spam-Status: No, score=-28.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, 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: 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: , Cc: Richard Earnshaw , Eric Botcazou Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" On aarch64 -mbranch-protection=pac-ret reuses the dwarf opcode for window_save to mean "toggle the return address mangle state", but in the dwarf2cfi internal logic the state was not updated when an opcode was emitted, the currently present update logic is only valid for the original sparc use of window_save so a separate bool is used on aarch64 to track the state. This bug can cause the unwinder not to authenticate return addresses that were signed (or vice versa) which means a runtime crash on a pauth enabled system. Currently only aarch64 pac-ret uses REG_CFA_TOGGLE_RA_MANGLE. This should be backported to gcc-9 and gcc-8 branches. gcc/ChangeLog: 2020-04-23 Szabolcs Nagy PR target/94515 * dwarf2cfi.c (struct GTY): Add ra_mangled. (cfi_row_equal_p): Check ra_mangled. (dwarf2out_frame_debug_cfa_window_save): Remove the argument, this only handles the sparc logic now. (dwarf2out_frame_debug_cfa_toggle_ra_mangle): New function for the aarch64 specific logic. (dwarf2out_frame_debug): Update to use the new subroutines. (change_cfi_row): Check ra_mangled. gcc/testsuite/ChangeLog: 2020-04-23 Szabolcs Nagy PR target/94515 * g++.target/aarch64/pr94515-1.C: New test. * g++.target/aarch64/pr94515-2.C: New test. --- gcc/dwarf2cfi.c | 40 ++++++++++++++---- gcc/testsuite/g++.target/aarch64/pr94515-1.C | 44 ++++++++++++++++++++ gcc/testsuite/g++.target/aarch64/pr94515-2.C | 41 ++++++++++++++++++ 3 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.target/aarch64/pr94515-1.C create mode 100644 gcc/testsuite/g++.target/aarch64/pr94515-2.C diff --git a/gcc/dwarf2cfi.c b/gcc/dwarf2cfi.c index 229fbfacc30..fa9e6089b2a 100644 --- a/gcc/dwarf2cfi.c +++ b/gcc/dwarf2cfi.c @@ -71,6 +71,9 @@ struct GTY(()) dw_cfi_row /* True if the register window is saved. */ bool window_save; + + /* True if the return address is in a mangled state. */ + bool ra_mangled; }; /* The caller's ORIG_REG is saved in SAVED_IN_REG. */ @@ -772,6 +775,9 @@ cfi_row_equal_p (dw_cfi_row *a, dw_cfi_row *b) if (a->window_save != b->window_save) return false; + if (a->ra_mangled != b->ra_mangled) + return false; + return true; } @@ -1370,20 +1376,33 @@ dwarf2out_frame_debug_cfa_restore (rtx reg) } /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE. - FAKE is true if this is not really a window save but something else. ??? Perhaps we should note in the CIE where windows are saved (instead of assuming 0(cfa)) and what registers are in the window. */ static void -dwarf2out_frame_debug_cfa_window_save (bool fake) +dwarf2out_frame_debug_cfa_window_save (void) +{ + dw_cfi_ref cfi = new_cfi (); + + cfi->dw_cfi_opc = DW_CFA_GNU_window_save; + add_cfi (cfi); + cur_row->window_save = true; +} + +/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_TOGGLE_RA_MANGLE. + Note: DW_CFA_GNU_window_save dwarf opcode is reused for toggling RA mangle + state, this is a target specific operation on AArch64 and can only be used + on other targets if they don't use the window save operation otherwise. */ + +static void +dwarf2out_frame_debug_cfa_toggle_ra_mangle (void) { dw_cfi_ref cfi = new_cfi (); cfi->dw_cfi_opc = DW_CFA_GNU_window_save; add_cfi (cfi); - if (!fake) - cur_row->window_save = true; + cur_row->ra_mangled = !cur_row->ra_mangled; } /* Record call frame debugging information for an expression EXPR, @@ -2143,13 +2162,12 @@ dwarf2out_frame_debug (rtx_insn *insn) break; case REG_CFA_TOGGLE_RA_MANGLE: - /* This uses the same DWARF opcode as the next operation. */ - dwarf2out_frame_debug_cfa_window_save (true); + dwarf2out_frame_debug_cfa_toggle_ra_mangle (); handled_one = true; break; case REG_CFA_WINDOW_SAVE: - dwarf2out_frame_debug_cfa_window_save (false); + dwarf2out_frame_debug_cfa_window_save (); handled_one = true; break; @@ -2221,6 +2239,14 @@ change_cfi_row (dw_cfi_row *old_row, dw_cfi_row *new_row) cfi->dw_cfi_opc = DW_CFA_GNU_window_save; add_cfi (cfi); } + + if (old_row->ra_mangled != new_row->ra_mangled) + { + dw_cfi_ref cfi = new_cfi (); + /* DW_CFA_GNU_window_save is reused for toggling RA mangle state. */ + cfi->dw_cfi_opc = DW_CFA_GNU_window_save; + add_cfi (cfi); + } } /* Examine CFI and return true if a cfi label and set_loc is needed diff --git a/gcc/testsuite/g++.target/aarch64/pr94515-1.C b/gcc/testsuite/g++.target/aarch64/pr94515-1.C new file mode 100644 index 00000000000..cd63f4fb259 --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/pr94515-1.C @@ -0,0 +1,44 @@ +/* PR target/94515. Check .cfi_window_save with multiple return paths. */ +/* { dg-do run } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-additional-options "-O2 -mbranch-protection=pac-ret --save-temps" } */ + +volatile int zero = 0; + +__attribute__((noinline, target("branch-protection=none"))) +void unwind (void) +{ + if (zero == 0) + throw 42; +} + +__attribute__((noinline, noipa, target("branch-protection=pac-ret"))) +int test (int z) +{ + if (z) { + asm volatile ("":::"x20","x21"); + unwind (); + return 1; + } else { + unwind (); + return 2; + } +} + +__attribute__((target("branch-protection=none"))) +int main () +{ + try { + test (zero); + __builtin_abort (); + } catch (...) { + return 0; + } + __builtin_abort (); +} + +/* This check only works if there are two return paths in test and + cfi_window_save is used for both instead of cfi_remember_state + plus cfi_restore_state. This is currently the case with -O2. */ + +/* { dg-final { scan-assembler-times {\t\.cfi_window_save\n} 4 } } */ diff --git a/gcc/testsuite/g++.target/aarch64/pr94515-2.C b/gcc/testsuite/g++.target/aarch64/pr94515-2.C new file mode 100644 index 00000000000..1f13e1200ad --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/pr94515-2.C @@ -0,0 +1,41 @@ +/* PR target/94515. Check .cfi_window_save with multiple return paths. */ +/* { dg-do run } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-additional-options "-O2 -mbranch-protection=pac-ret" } */ + +volatile int zero = 0; +int global = 0; + +__attribute__((noinline)) +int bar(void) +{ + if (zero == 0) return 3; + return 0; +} + +__attribute__((noinline, noreturn)) +void unwind (void) +{ + throw 42; +} + +__attribute__((noinline, noipa, target("branch-protection=pac-ret"))) +int test(int x) +{ + if (x==1) return 2; /* This return path may not use the stack. */ + int y = bar(); + if (y > global) global=y; + if (y==3) unwind(); /* This return path must have RA mangle state set. */ + return 0; +} + +int main () +{ + try { + test (zero); + __builtin_abort (); + } catch (...) { + return 0; + } + __builtin_abort (); +}