From patchwork Mon Jan 13 11:22:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Longo X-Patchwork-Id: 104682 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 04C6B3858432 for ; Mon, 13 Jan 2025 11:23:52 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on20627.outbound.protection.outlook.com [IPv6:2a01:111:f403:260e::627]) by sourceware.org (Postfix) with ESMTPS id 52A763858C98 for ; Mon, 13 Jan 2025 11:22:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52A763858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52A763858C98 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:260e::627 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1736767355; cv=pass; b=D2koTrtAw7x896ogJbkRcLZGjwLwigeRrDBwC45gkJSoHu3b3mKBckWJGrPRzyD6T6l+V5Fe29YHsZIwRCM3q0xuMCYgc86zpao2rafPwJ+E/fb5qX20LGGnupqUpn3NddsAdGwemdq2nhMJvn4ziYBcNR1b+My3bNEieJg+LjM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1736767355; c=relaxed/simple; bh=Df0mRcnTik7Xzc3ulRS2cXv0/Eq6XhLFkFfLfbAvous=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hXk+lK9bLti4InKWSdmH4vrvCVI6BBMDs2dTyShwr5BKyUbgtfdJWvLbkJxWYCLWvQFbS0dxGuXX5V5QkXiJzMmMoNgeVFlY8YBL5Y/lhnV3CPYzHil/yLfQsybqcqbO1rEd1s5z4q720xhoJQt/SKxzoqXFCbogOFXIzX0/h60= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52A763858C98 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=acCNT/VM ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kqj6v4lKT+366KgmJ4oHW08YvidMSuu9r5EpQzw/h2Ac1V+MvRLjBv2yrVxX0BbHbhGkWkptuAJlCIqOtQX5LtgCvG6PRaJlumk3+qzuNVu/iapCL1bJxYmMvlCYDi3BJY/yjnihDS+tuwg+r3k9/abDbyEYXuaDUYKNbdtTiKQMW86/bl9F5AFIfoKGAlrUs9tmz6j+LkqMf562Xp7nIh7+5vPdDMCnJGLMKpi6wp5juW6K5bdM8MLkAgtgOTEacAE6KyYaD/HG/u4UuWrogR0SIxY6QqYvFBE12LAGIQHSJcOY7Dpe0K7Bz/0ErQ24F1AU31xSu9P5wXFdq7dpqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=a2ubUibZDWLFf3893VsDg739a3Nv63cHjBwYxz/AXW8=; b=SfpJk5QXL4gMnBR3yeFeM7lyqStPiMYxKWkIBSS0WFeYjzYZu+CLqStepWmd+6IYknaEfy2+ViMvbko3wHe7d2Gog/htqhJHvIj84rM7QWta+dG5uhZ75m079KJ82VJzTFjlw8Jo9Mep/6549rFq0MHj3Z11X6kX3h3wmCgZuM5Ycv8H1Ycwq0DC7Fq8LF0v8rzPYiL2uzbNiSRxOdSLw85yFPz6HflzkAF12PRd1puz10UrrccIBkDHAn+kGsXF4Qr2jWgtVnSuG3NfB8cwu26rRm2zrrTWMOHBCgRzHyVDYMHQz7zerVmTkXqOdaAL7WxqXjZqvw9UGGTX82lZRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 172.205.89.229) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a2ubUibZDWLFf3893VsDg739a3Nv63cHjBwYxz/AXW8=; b=acCNT/VMiK3YjRpbWAnWpBUtpY59n4O582pnuavH7QkwtsELBPEzwUYOdWY4WAjlv4ZiV0onc3encYkDs8Hi0+Huysa4mLmWaH8Mab3lc/Oo0LFtbi1B422GWvmPbiG4Tn7wSrO/7cILzJwYUyufs3Pyq2e5SI6WsmPcRfIyDNg= Received: from AS4P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:5d9::19) by AM8PR08MB6626.eurprd08.prod.outlook.com (2603:10a6:20b:367::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.18; Mon, 13 Jan 2025 11:22:31 +0000 Received: from AM4PEPF00027A69.eurprd04.prod.outlook.com (2603:10a6:20b:5d9:cafe::49) by AS4P191CA0023.outlook.office365.com (2603:10a6:20b:5d9::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.18 via Frontend Transport; Mon, 13 Jan 2025 11:22:30 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 172.205.89.229) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=arm.com; Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 172.205.89.229 as permitted sender) receiver=protection.outlook.com; client-ip=172.205.89.229; helo=nebula.arm.com; Received: from nebula.arm.com (172.205.89.229) by AM4PEPF00027A69.mail.protection.outlook.com (10.167.16.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Mon, 13 Jan 2025 11:22:30 +0000 Received: from AZ-NEU-EXJ01.Arm.com (10.240.25.132) by AZ-NEU-EX06.Arm.com (10.240.25.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 13 Jan 2025 11:22:30 +0000 Received: from AZ-NEU-EX05.Arm.com (10.240.25.133) by AZ-NEU-EXJ01.Arm.com (10.240.25.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 13 Jan 2025 11:22:29 +0000 Received: from PW070M4K.arm.com (10.1.32.155) by mail.arm.com (10.240.25.133) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Mon, 13 Jan 2025 11:22:29 +0000 From: Matthieu Longo To: , Indu Bhagat CC: Richard Earnshaw , Nick Clifton , Jan Beulich , Matthieu Longo Subject: [PATCH v3 1/4] aarch64: make explicit that CFI gnu_window_save is for Sparc, not AArch64 Date: Mon, 13 Jan 2025 11:22:03 +0000 Message-ID: <20250113112206.1071596-2-matthieu.longo@arm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113112206.1071596-1-matthieu.longo@arm.com> References: <20250113112206.1071596-1-matthieu.longo@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM4PEPF00027A69:EE_|AM8PR08MB6626:EE_ X-MS-Office365-Filtering-Correlation-Id: 0dd2938b-c5a2-48c9-7ae2-08dd33c491ca X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: U4dILK8SJY0puRBVsh2GWsD24tI6wabhI2Kbf3rHDpUHkrjhuiJHm9qOsS2wPwpW5dNqPxciZ7aAneST5iYjBDbOHN7DB1Hp7xgcsM9hy3gcQ3i48Bd8c8UtBNZljNbWqePuPSBPacgN2czAncxv2k4kGppJmpSQKG6yfKnRvGv7iK+oMN2eokiOqzwiIdjqSMfpbH9fA/vZoqSIXxnW3DrxuQoCcvK7Ik1wd6dlIE9iIYIAsL0IlHmG+mmZS8oZRjesG1UZvnFERX3sfNJeBNWJvhcqpJz1dC8GGO68LIUTCJqQGk9Ka4IGeHWv01oQnRfR8c1Ie1yV6UnS71+S40GOyouOD5v1E1DQ8hhWWEi2NwFCfq5Kmfink5s+e8Gld5q4SdCXh7Z4swgtWP+y8BqhcA0X81JLx5HOD9Q8pW76u8qjqVAsahXkjAjc/96c/03C9orBPOOpGn5Ao9Jc101dF65bTk965cROsN00rT7A4ZQAAVc16ReULJXIsffrX4GAsQLTcRFIsuKkLIDJcXo/F0LZ2GlKxuz5APqovOQuSdInlJA/ueq5TkEa7JxPu1eyAf2y/7lHVTKyHP74raxIB5/kgQbcAY1abv7zwZOiN7bO0JPS0HaqebWWNkEeO+iX9QuC3T9DgyLmWmvX7ATo531xv6wvTMRz/PsNkk9ZWb3U4K6BSkQDB4m5+4q4meh4U4qoEMicgm4q8wGs1oyXtSy7PWWn5pEKepBJ/eIy7ZUcC9qC1jKFBnzgOtjC77Iz7YjTfDGa4k+6XsG5AJRmJPrwRcNYEKVUMErt1l7y9JU7GM/GosBOTaRG//I0NnDm4tDs6/38AKb4OOxmsib22SN8EwMgG2ZaEnC/qXejwNDVm49ZYFl8eU0CuyOmu+W5fL5JeAoru9ZalQVNyDGqyg79kH7bncSbLf5MXfRd82ac9vRtFVIB1fOoJTZkO+p+YXXpa/eIxCakd8ryjWjiwsstamY9ADgzXQpf3419QHYamJqQ7ypD2yRgd/BrPcdfoMLbEErSUs3wHdBHpHlhxUhRsbAd+e7OYMWuBFQ/JbMswhYl2ZPeGdioFKMJBE2oEEixCysJccK0adl6psnI/2yhSCl9f1ntAy74fIwCzHzL6Z+lv9aTHB+TwEP01GmrEjPXco21J6c/6UoMZDGuFo1Syt37iyq9NWEdvTl/d5hPHHsCoMc2NVvG6nhMzUHxrt3Z5hjitYPCqaMysWASrZiCJTv+4CvfQeHDSL2wfLLy9DslV7K4pC2zgZu7PVrOh+Jt5KnSRRW4ua+55JsQqijxFPPzKCI2maRdy+NIU7VoOXuGHgg0KZjvANoKcgnd2vfv3tfUXtDppQGe2zTSxfGJntqTjFu6s5ItIE6PxlK41HUgCJSuUhQGN+WihGf3m6NGOlM27H5XRKRbTSv/E+4TxzbH7FmCdn7N5W0SQSzwOKumOsfZyD/VWGxIycJD0UouiYpP0gWL/Da/QvQCOKmePse1IbJo3gxwKIE= X-Forefront-Antispam-Report: CIP:172.205.89.229; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2025 11:22:30.8738 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0dd2938b-c5a2-48c9-7ae2-08dd33c491ca X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[172.205.89.229]; Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-AuthSource: AM4PEPF00027A69.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6626 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_NUMSUBJECT, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org - add a detailed comment when parsing DW_CFA_GNU_window_save in SFrame to explain why we are checking whether the targeted architecture is AArch64, whereas this CFI is a Sparc extension. - replace .cfi_gnu_window_save by .cfi_negate_ra_state in existing AArch64 DWARF tests as this is the preferred directive since GCC 15. - add a new AARch64 test to check backward compatibility with old GCC versions that emits .cfi_gnu_window_save. --- gas/gen-sframe.c | 8 +++- gas/testsuite/gas/aarch64/pac_ab_key.s | 4 +- .../gas/aarch64/pac_compat_cfi_window_save.d | 44 +++++++++++++++++++ .../gas/aarch64/pac_compat_cfi_window_save.s | 20 +++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d create mode 100644 gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.s diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c index 71296f2f4fb..a3c40bdd735 100644 --- a/gas/gen-sframe.c +++ b/gas/gen-sframe.c @@ -1273,7 +1273,13 @@ sframe_xlate_do_aarch64_negate_ra_state (struct sframe_xlate_ctx *xlate_ctx, } /* Translate DW_CFA_GNU_window_save into SFrame context. - DW_CFA_AARCH64_negate_ra_state is multiplexed with DW_CFA_GNU_window_save. + DW_CFA_GNU_window_save is a DWARF Sparc extension, but is multiplexed with a + directive of DWARF AArch64 extension: DW_CFA_AARCH64_negate_ra_state. + The AArch64 backend of GCC 14 and older versions was emitting mistakenly the + Sparc CFI directive (.cfi_window_save). From GCC 15, the AArch64 backend + only emits .cfi_negate_ra_state. For backward compatibility, the handler for + .cfi_window_save needs to check whether the directive was used in a AArch ABI + context or not. Return SFRAME_XLATE_OK if success. */ static int diff --git a/gas/testsuite/gas/aarch64/pac_ab_key.s b/gas/testsuite/gas/aarch64/pac_ab_key.s index 4b328e72ae4..3b81919409d 100644 --- a/gas/testsuite/gas/aarch64/pac_ab_key.s +++ b/gas/testsuite/gas/aarch64/pac_ab_key.s @@ -7,7 +7,7 @@ _Z5foo_av: .LFB0: .cfi_startproc hint 25 // paciasp - .cfi_window_save + .cfi_negate_ra_state stp x29, x30, [sp, -16]! .cfi_def_cfa_offset 16 .cfi_offset 29, -16 @@ -23,7 +23,7 @@ _Z5foo_bv: .cfi_startproc .cfi_b_key_frame hint 27 // pacibsp - .cfi_window_save + .cfi_negate_ra_state stp x29, x30, [sp, -16]! .cfi_def_cfa_offset 16 .cfi_offset 29, -16 diff --git a/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d b/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d new file mode 100644 index 00000000000..8e59086c1b4 --- /dev/null +++ b/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d @@ -0,0 +1,44 @@ +#objdump: --dwarf=frames +# This test is only valid on ELF based ports. +#notarget: *-*-*coff *-*-pe *-*-wince *-*-*aout* *-*-netbsd + +## ARMv8.3 adds support for a new security feature named Pointer Authentication. +## The main idea behind this is to use the unused bits in the pointer values. +## Each pointer is patched with a PAC before writing to memory, and is verified +## before using it. +## When the pointers are mangled, the stack trace generator needs to know so it +## can mask off the PAC from the pointer value to recover the return address, +## and conversely, skip doing so if the pointers are not mangled. +## +## .cfi_negate_ra_state CFI directive is usually used to convey this information. +## .cfi_negate_ra_state and .cfi_window_save are both in the processor-specific +## numbering space, but use the same code value in the dwarf tables. +## In GCC 14 and older, the Sparc DWARF extension .cfi_window_save is emitted +## instead of .cfi_negate_ra_state, but it mapped to the same value. GCC 15 fixed +## this naming issue and there is no change to the object file created when the +## source is assembled. Nevertheless the support for the SPARC directive is +## preserved in binutils for backward compatibility with existing GCC releases, +## hence this test. + +.+: file .+ + +Contents of the .eh_frame section: + +0+ 0+10 0+ CIE + Version: 1 + Augmentation: "zR" + Code alignment factor: 4 + Data alignment factor: -8 + Return address column: 30 + Augmentation data: 1b + DW_CFA_def_cfa: r31 \(sp\) ofs 0 + +0+14 0+18 0+18 FDE cie=0+ pc=0+\.\.0+8 + DW_CFA_advance_loc: 4 to 0+4 + DW_CFA_AARCH64_negate_ra_state + DW_CFA_advance_loc: 4 to 0+8 + DW_CFA_def_cfa_offset: 16 + DW_CFA_offset: r29 \(x29\) at cfa-16 + DW_CFA_offset: r30 \(x30\) at cfa-8 + DW_CFA_nop + DW_CFA_nop diff --git a/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.s b/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.s new file mode 100644 index 00000000000..92a54f3a344 --- /dev/null +++ b/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.s @@ -0,0 +1,20 @@ + .arch armv8-a + .text + .align 2 + .global _Z5foo_av + .type _Z5foo_av, %function +_Z5foo_av: +.LFB0: + .cfi_startproc + hint 25 // paciasp + .cfi_window_save // really .cfi_negate_ra_state + stp x29, x30, [sp, -16]! + .cfi_def_cfa_offset 16 + .cfi_offset 29, -16 + .cfi_offset 30, -8 + .cfi_endproc +.LFE0: + .size _Z5foo_av, .-_Z5foo_av + .align 2 + .global _Z5foo_bv + .type _Z5foo_bv, %function