From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2052.outbound.protection.outlook.com [40.107.6.52]) by sourceware.org (Postfix) with ESMTPS id 02B8E3858D1E for ; Thu, 22 Dec 2022 17:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 02B8E3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=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=LLECrjMjWmcf7xaHALfas1AWtE8rmgc674G564W5aco=; b=ARxC+TNK4MF+84Mu9mTKrqmY48U3YVSCy0UTtJohUnF5iaNbLJCM9jL2qp4LD5/fcbXuFXo5YsbYNaxGdgopTTV+t4C60S4k2GRsBmRsOe09mbXmIuueAYzOSZky2bu/NPU1J1r0R0SKoaL0Hmdip2nDqDJ7/QNsV33uOfjwqq4= Received: from FR3P281CA0191.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a4::9) by DB9PR08MB8338.eurprd08.prod.outlook.com (2603:10a6:10:3dd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.6; Thu, 22 Dec 2022 17:04:30 +0000 Received: from VI1EUR03FT005.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:a4:cafe::5c) by FR3P281CA0191.outlook.office365.com (2603:10a6:d10:a4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.10 via Frontend Transport; Thu, 22 Dec 2022 17:04:30 +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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VI1EUR03FT005.mail.protection.outlook.com (100.127.144.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.10 via Frontend Transport; Thu, 22 Dec 2022 17:04:29 +0000 Received: ("Tessian outbound 0d7b2ab0f13d:v132"); Thu, 22 Dec 2022 17:04:29 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 36cc04d87969432b X-CR-MTA-TID: 64aa7808 Received: from 5e307bad4b12.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F9405079-5EB9-4DE4-BA52-1A1BC9DB4337.1; Thu, 22 Dec 2022 17:04:22 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5e307bad4b12.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 22 Dec 2022 17:04:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OrwTdXrWZ6ixso2YjqDcPkbMj6rz2IO14+ThM2GLKsh6RJ6D4Vk9CivD7f68a9AZK9f7l1XYdTMz2JYnDX+bptqZUvMvn5N+s1zEU6mxG5yRwYusmDhI454i4awxEy/YG1Ha1dch8l/pqsIcodtmok6u3ooCNzzh9eRWahAMqdQix6XU5CKnTdi+0OkAK6kpUN82WWbZ3zPW5hrMLCLRc9nvvrjwpYcjV0L8u3NsPWPmzmYJsRpTEKiJeVb0M5hwzIFbvpvArvUEfNrI2K6usXr/1xtwomPPKfV2nKVbUaIQnN2nin6b3LtFiur6UqPkNpOsIOt9kcF88/OFOd/9Gw== 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=LLECrjMjWmcf7xaHALfas1AWtE8rmgc674G564W5aco=; b=f47vhLgvSXfr2XSC6h321R258SV92TxdO3DFio5vTlHtnhxWDHJGi0NTVveovyXuPjiYbkwR107Kw65TZN5pzT/qZl4YzNICkmR1t/4qlSeBE2Ylmn+fNwoxjP+mQTfrsBxJ0KXE11PZhQ7VQvrS1IwCMnpSSet5+RCgjBAvr7SkxXu1xcTNhe1iiurH/mNWeWKD5WBOrpZf2WvPz0J+d7Z3nyxF29JcYuny6APjE6CUAUgH/2QOujG5yuqq6TxX3NTxdnCdAkbC+o6xUWg/50WxlYHkCChEe2v+qrueea+Wc5hqnBLnUplmcoxdF2GYj6WDjxdWd+QXIL4X0YtVVA== 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 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=LLECrjMjWmcf7xaHALfas1AWtE8rmgc674G564W5aco=; b=ARxC+TNK4MF+84Mu9mTKrqmY48U3YVSCy0UTtJohUnF5iaNbLJCM9jL2qp4LD5/fcbXuFXo5YsbYNaxGdgopTTV+t4C60S4k2GRsBmRsOe09mbXmIuueAYzOSZky2bu/NPU1J1r0R0SKoaL0Hmdip2nDqDJ7/QNsV33uOfjwqq4= Received: from AM6PR10CA0037.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::14) by DB9PR08MB9729.eurprd08.prod.outlook.com (2603:10a6:10:45c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.12; Thu, 22 Dec 2022 17:04:14 +0000 Received: from AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:80:cafe::1b) by AM6PR10CA0037.outlook.office365.com (2603:10a6:209:80::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.12 via Frontend Transport; Thu, 22 Dec 2022 17:04:14 +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; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT039.mail.protection.outlook.com (100.127.140.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5944.12 via Frontend Transport; Thu, 22 Dec 2022 17:04:14 +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.2507.16; Thu, 22 Dec 2022 17:04:13 +0000 Received: from e124257 (10.34.105.24) 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.2507.16 via Frontend Transport; Thu, 22 Dec 2022 17:04:13 +0000 From: Andrea Corallo To: Andrea Corallo via Gcc-patches CC: Richard Earnshaw , nd Subject: [PATCH 1/15 V2] arm: Make mbranch-protection opts parsing common to AArch32/64 References: Date: Thu, 22 Dec 2022 18:04:12 +0100 In-Reply-To: (Andrea Corallo via Gcc-patches's message of "Fri, 12 Aug 2022 17:14:27 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT039:EE_|DB9PR08MB9729:EE_|VI1EUR03FT005:EE_|DB9PR08MB8338:EE_ X-MS-Office365-Filtering-Correlation-Id: 83ffd3c2-2ea1-456a-d530-08dae43e9710 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: e9bwBa/iyF1j8HFUz4NTCdl2gKXqiakD3dVRpHw23kAZZrQQKpBu+jgUd+8ggQ7no8OjkO3x2TlrZMbmh1qNHT+j4amPZQN8J6WU2M1Kj9RczSyv5ZvIM1WKeLQm4P8loydbry2MLlzEVZu/jgdEJpYv89wOH/0vpoL93PEUZhtXAild10UsWLNaxnoW+HJ+1O+ijKNlpSfrgra4o+dzaB8ytB6t4bC6peaO6sipvRc/Lgb3mX36rEqcAAgYxjDDytp2jhBssYJQiptxVnqxBJVIpPzLztWwoDZJ4rWlqv3vPkUOrJLpUeATKefF0R7Qh3hfWudC8UMYZg/rtbO0Db/FrxSz2aD8Xjzy6+9aYUvnZgZQ6WBMfk2jlu0e0tMYVmJ90AFH6MQthSnIg01JeMptrESy8pZf6yapI9Ik1GZF+bJqzaRhfCV6gZQCvh5OiVLfG89pQTi4mB734XQnd+dvR40NUfqua3HaEBVoiTqHVh+IfoVy6bdq5wmdxhfqx4v7haJluGH8R/tfzYunSiuCZElYiXDGSAA6DIj+3SPKgls4TiUj5W8sKaYYT6mJJOPFEZZP0SfEp1S6UhjZrp2FjD9yX2x3/lvExv2ejbnHQx3WVBHEAlqO24aXIKv9RfSjmxZEOj2sjpRMF+7oruS3KeceOzfJwPqDZ7sUSVR1rh9JYKPsM+WwhHjUzrH53ZCf4jdbrDONQWS+XL5s5JDnAd6SqD6Ktp1gEsaJ8xm6NPm22QOptk1BJF2aMCaJ 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:(13230022)(4636009)(396003)(376002)(136003)(346002)(39860400002)(451199015)(40470700004)(46966006)(36840700001)(336012)(478600001)(40480700001)(82740400003)(70586007)(70206006)(8676002)(4326008)(33964004)(316002)(36860700001)(564344004)(36756003)(54906003)(40460700003)(6916009)(41300700001)(2616005)(235185007)(82310400005)(5660300002)(2906002)(44832011)(186003)(8936002)(26005)(81166007)(86362001)(47076005)(426003)(356005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB9729 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: f9a56117-80a3-4c1d-7293-08dae43e8dd2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GmlEJ+Uw2sxeKKq/1EGLfuvP3moYTW8bIPasHjtGvyo9yBMXsgLT7+VBumtNHrySWvigYg1dKLKSrVeuV1OTRS38e2VLK+HpgtF1JwzT3keTbPwZS/A7txe5xXTbR7cwGqOkodQ20iuea1Nu+BpU0rH1lq5hxX580qgtHv46yTHyLw67ej0gHlkWu6AXWfIbIAbnz4y3MFmEOUecrySckuhDyLqwi6SGa0RjwZKqhNUndfmZsjxawBBmc/i2XY9dUtI3y0taJWtalLQ7mn6M8dnuN5aSSONeOfhR0O8YeSYQ6U9l2sl2qfrPKnMN+iuS1EWM7YqAllmZXyw3J1SyQk40TQvDsZDMl3e1fI7AtTtj1xKvVU/t8O/Hjf3vC7C0XcLSJ/gzlyknhRSX8WF5dYMTRHOAN8i9FZwg/GNlGvMqOh4d4tCMlUqZBtqbhboMHYH60WsHzbrjpgebSZwwKSeX2ohVsPwdEdwwWuBgaF2DOb015w7lHyY2f7QHKrCqHkLKPZwkbmwbXyvCOpSGdUrzpgpHSNcIouham4sBlR9FV6vMBuADMZRMjTdv6KtgK2T3iD0MPDJqXML9QOOEa+jP4ndmIfZiQpJIqryLeT6gOQRgSS1nKM91VZzYFsnRSWzFg0QzYDa7+9OBs4JdF2BRtGi2qmHnGGy6epwMJHSIaUSdXokg1HQzI5fazS2wwrq+g3oQv4S5c4n4TD24oA== 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:(13230022)(4636009)(136003)(346002)(376002)(39860400002)(396003)(451199015)(36840700001)(40470700004)(46966006)(33964004)(26005)(186003)(478600001)(2906002)(316002)(426003)(47076005)(2616005)(36756003)(81166007)(86362001)(40460700003)(336012)(82740400003)(82310400005)(564344004)(44832011)(8936002)(36860700001)(5660300002)(6916009)(54906003)(40480700001)(70586007)(235185007)(70206006)(41300700001)(8676002)(4326008);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2022 17:04:29.8508 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83ffd3c2-2ea1-456a-d530-08dae43e9710 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: VI1EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8338 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,KAM_NUMSUBJECT,KAM_SHORT,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --=-=-= Content-Type: text/plain Hi all, respinning this as a rebase was necessary, also now is setting 'aarch_enable_bti' to zero as default for arm as suggested during the review of 12/15. Best Regards Andrea --=-=-= Content-Type: text/plain; charset="utf-8" Content-Disposition: attachment; filename="0001-PATCH-1-15-arm-Make-mbranch-protection-opts-parsing-.patch" >From 6c765818542cc7b40701e8adae2cbe077d5982cc Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 6 Dec 2021 11:34:35 +0100 Subject: [PATCH] [PATCH 1/15] arm: Make mbranch-protection opts parsing common to AArch32/64 Hi all, This change refactors all the mbranch-protection option parsing code and types to make it common to both AArch32 and AArch64 backends. This change also pulls in some supporting types from AArch64 to make it common (aarch_parse_opt_result). The significant changes in this patch are the movement of all branch protection parsing routines from aarch64.c to aarch-common.c and supporting data types and static data structures. This patch also pre-declares variables and types required in the aarch32 back-end for moved variables for function sign scope and key to prepare for the impending series of patches that support parsing the feature mbranch-protection in the aarch32 back-end. gcc/ChangeLog: * common/config/aarch64/aarch64-common.cc: Include aarch-common.h. (all_architectures): Fix comment. (aarch64_parse_extension): Rename return type, enum value names. * config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Rename factored out aarch_ra_sign_scope and aarch_ra_sign_key variables. Also rename corresponding enum values. * config/aarch64/aarch64-opts.h (aarch64_function_type): Factor out aarch64_function_type and move it to common code as aarch_function_type in aarch-common.h. * config/aarch64/aarch64-protos.h: Include common types header, move out types aarch64_parse_opt_result and aarch64_key_type to aarch-common.h * config/aarch64/aarch64.cc: Move mbranch-protection parsing types and functions out into aarch-common.h and aarch-common.cc. Fix up all the name changes resulting from the move. * config/aarch64/aarch64.md: Fix up aarch64_ra_sign_key type name change and enum value. * config/aarch64/aarch64.opt: Include aarch-common.h to import type move. Fix up name changes from factoring out common code and data. * config/arm/aarch-common-protos.h: Export factored out routines to both backends. * config/arm/aarch-common.cc: Include newly factored out types. Move all mbranch-protection code and data structures from aarch64.cc. * config/arm/aarch-common.h: New header that declares types shared between aarch32 and aarch64 backends. * config/arm/arm-protos.h: Declare types and variables that are made common to aarch64 and aarch32 backends - aarch_ra_sign_key, aarch_ra_sign_scope and aarch_enable_bti. Co-Authored-By: Tejas Belagod --- gcc/common/config/aarch64/aarch64-common.cc | 13 +- gcc/config/aarch64/aarch64-c.cc | 8 +- gcc/config/aarch64/aarch64-opts.h | 10 - gcc/config/aarch64/aarch64-protos.h | 21 +- gcc/config/aarch64/aarch64.cc | 360 +++++--------------- gcc/config/aarch64/aarch64.md | 2 +- gcc/config/aarch64/aarch64.opt | 15 +- gcc/config/arm/aarch-common-protos.h | 6 + gcc/config/arm/aarch-common.cc | 185 ++++++++++ gcc/config/arm/aarch-common.h | 73 ++++ gcc/config/arm/arm-protos.h | 2 + gcc/config/arm/arm.cc | 7 + gcc/config/arm/arm.opt | 9 + 13 files changed, 390 insertions(+), 321 deletions(-) create mode 100644 gcc/config/arm/aarch-common.h diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc index 61007839d35..18b0b72c012 100644 --- a/gcc/common/config/aarch64/aarch64-common.cc +++ b/gcc/common/config/aarch64/aarch64-common.cc @@ -31,6 +31,7 @@ #include "flags.h" #include "diagnostic.h" #include "config/aarch64/aarch64-feature-deps.h" +#include "config/arm/aarch-common.h" #ifdef TARGET_BIG_ENDIAN_DEFAULT #undef TARGET_DEFAULT_TARGET_FLAGS @@ -191,13 +192,13 @@ static constexpr arch_to_arch_name all_architectures[] = /* Parse the architecture extension string STR and update ISA_FLAGS with the architecture features turned on or off. Return a - aarch64_parse_opt_result describing the result. + aarch_parse_opt_result describing the result. When the STR string contains an invalid extension, a copy of the string is created and stored to INVALID_EXTENSION. */ -enum aarch64_parse_opt_result +enum aarch_parse_opt_result aarch64_parse_extension (const char *str, aarch64_feature_flags *isa_flags, - std::string *invalid_extension) + std::string *invalid_extension) { /* The extension string is parsed left to right. */ const struct aarch64_option_extension *opt = NULL; @@ -228,7 +229,7 @@ aarch64_parse_extension (const char *str, aarch64_feature_flags *isa_flags, adding_ext = 1; if (len == 0) - return AARCH64_PARSE_MISSING_ARG; + return AARCH_PARSE_MISSING_ARG; /* Scan over the extensions table trying to find an exact match. */ @@ -250,13 +251,13 @@ aarch64_parse_extension (const char *str, aarch64_feature_flags *isa_flags, /* Extension not found in list. */ if (invalid_extension) *invalid_extension = std::string (str, len); - return AARCH64_PARSE_INVALID_FEATURE; + return AARCH_PARSE_INVALID_FEATURE; } str = ext; }; - return AARCH64_PARSE_OK; + return AARCH_PARSE_OK; } /* Append all architecture extension candidates to the CANDIDATES vector. */ diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc index e296c73350f..c8e4431ac56 100644 --- a/gcc/config/aarch64/aarch64-c.cc +++ b/gcc/config/aarch64/aarch64-c.cc @@ -183,14 +183,14 @@ aarch64_update_cpp_builtins (cpp_reader *pfile) "__ARM_FEATURE_BTI_DEFAULT", pfile); cpp_undef (pfile, "__ARM_FEATURE_PAC_DEFAULT"); - if (aarch64_ra_sign_scope != AARCH64_FUNCTION_NONE) + if (aarch_ra_sign_scope != AARCH_FUNCTION_NONE) { int v = 0; - if (aarch64_ra_sign_key == AARCH64_KEY_A) + if (aarch_ra_sign_key == AARCH_KEY_A) v |= 1; - if (aarch64_ra_sign_key == AARCH64_KEY_B) + if (aarch_ra_sign_key == AARCH_KEY_B) v |= 2; - if (aarch64_ra_sign_scope == AARCH64_FUNCTION_ALL) + if (aarch_ra_sign_scope == AARCH_FUNCTION_ALL) v |= 4; builtin_define_with_int_value ("__ARM_FEATURE_PAC_DEFAULT", v); } diff --git a/gcc/config/aarch64/aarch64-opts.h b/gcc/config/aarch64/aarch64-opts.h index ba23c90c411..71f834635b3 100644 --- a/gcc/config/aarch64/aarch64-opts.h +++ b/gcc/config/aarch64/aarch64-opts.h @@ -75,16 +75,6 @@ enum aarch64_code_model { AARCH64_CMODEL_LARGE }; -/* Function types -msign-return-address should sign. */ -enum aarch64_function_type { - /* Don't sign any function. */ - AARCH64_FUNCTION_NONE, - /* Non-leaf functions. */ - AARCH64_FUNCTION_NON_LEAF, - /* All functions. */ - AARCH64_FUNCTION_ALL -}; - /* SVE vector register sizes. */ enum aarch64_sve_vector_bits_enum { SVE_SCALABLE, diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h index fcc3a66cdf2..f031bd7026c 100644 --- a/gcc/config/aarch64/aarch64-protos.h +++ b/gcc/config/aarch64/aarch64-protos.h @@ -23,6 +23,7 @@ #define GCC_AARCH64_PROTOS_H #include "input.h" +#include "config/arm/aarch-common.h" /* SYMBOL_SMALL_ABSOLUTE: Generate symbol accesses through high and lo relocs that calculate the base address using a PC @@ -651,18 +652,6 @@ enum aarch64_extra_tuning_flags AARCH64_EXTRA_TUNE_ALL = (1u << AARCH64_EXTRA_TUNE_index_END) - 1 }; -/* Enum describing the various ways that the - aarch64_parse_{arch,tune,cpu,extension} functions can fail. - This way their callers can choose what kind of error to give. */ - -enum aarch64_parse_opt_result -{ - AARCH64_PARSE_OK, /* Parsing was successful. */ - AARCH64_PARSE_MISSING_ARG, /* Missing argument. */ - AARCH64_PARSE_INVALID_FEATURE, /* Invalid feature modifier. */ - AARCH64_PARSE_INVALID_ARG /* Invalid arch, tune, cpu arg. */ -}; - /* Enum to distinguish which type of check is to be done in aarch64_simd_valid_immediate. This is used as a bitmask where AARCH64_CHECK_MOV has both bits set. Thus AARCH64_CHECK_MOV will @@ -673,6 +662,8 @@ enum simd_immediate_check { AARCH64_CHECK_MOV = AARCH64_CHECK_ORR | AARCH64_CHECK_BIC }; +extern enum aarch_key_type aarch_ra_sign_key; + extern struct tune_params aarch64_tune_params; /* The available SVE predicate patterns, known in the ACLE as "svpattern". */ @@ -1038,9 +1029,9 @@ void aarch64_set_asm_isa_flags (gcc_options *, aarch64_feature_flags); bool aarch64_handle_option (struct gcc_options *, struct gcc_options *, const struct cl_decoded_option *, location_t); const char *aarch64_rewrite_selected_cpu (const char *name); -enum aarch64_parse_opt_result aarch64_parse_extension (const char *, - aarch64_feature_flags *, - std::string *); +enum aarch_parse_opt_result aarch64_parse_extension (const char *, + aarch64_feature_flags *, + std::string *); void aarch64_get_all_extension_candidates (auto_vec *candidates); std::string aarch64_get_extension_string_for_isa_flags (aarch64_feature_flags, aarch64_feature_flags); diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 45d659a4a91..ffef5e6f32e 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -82,6 +82,8 @@ #include "tree-dfa.h" #include "asan.h" #include "aarch64-feature-deps.h" +#include "config/arm/aarch-common.h" +#include "config/arm/aarch-common-protos.h" /* This file should be included last. */ #include "target-def.h" @@ -318,12 +320,8 @@ bool aarch64_pcrelative_literal_loads; /* Global flag for whether frame pointer is enabled. */ bool aarch64_use_frame_pointer; -#define BRANCH_PROTECT_STR_MAX 255 char *accepted_branch_protection_string = NULL; -static enum aarch64_parse_opt_result -aarch64_parse_branch_protection (const char*, char**); - /* Support for command line parsing of boolean flags in the tuning structures. */ struct aarch64_flag_desc @@ -2761,6 +2759,8 @@ static const struct processor all_cores[] = {NULL, aarch64_none, aarch64_none, aarch64_no_arch, 0, NULL} }; +enum aarch_key_type aarch_ra_sign_key = AARCH_KEY_A; + /* The current tuning set. */ struct tune_params aarch64_tune_params = generic_tunings; @@ -2826,100 +2826,6 @@ aarch64_cc; #define AARCH64_INVERSE_CONDITION_CODE(X) ((aarch64_cc) (((int) X) ^ 1)) -struct aarch64_branch_protect_type -{ - /* The type's name that the user passes to the branch-protection option - string. */ - const char* name; - /* Function to handle the protection type and set global variables. - First argument is the string token corresponding with this type and the - second argument is the next token in the option string. - Return values: - * AARCH64_PARSE_OK: Handling was sucessful. - * AARCH64_INVALID_ARG: The type is invalid in this context and the caller - should print an error. - * AARCH64_INVALID_FEATURE: The type is invalid and the handler prints its - own error. */ - enum aarch64_parse_opt_result (*handler)(char*, char*); - /* A list of types that can follow this type in the option string. */ - const aarch64_branch_protect_type* subtypes; - unsigned int num_subtypes; -}; - -static enum aarch64_parse_opt_result -aarch64_handle_no_branch_protection (char* str, char* rest) -{ - aarch64_ra_sign_scope = AARCH64_FUNCTION_NONE; - aarch64_enable_bti = 0; - if (rest) - { - error ("unexpected %<%s%> after %<%s%>", rest, str); - return AARCH64_PARSE_INVALID_FEATURE; - } - return AARCH64_PARSE_OK; -} - -static enum aarch64_parse_opt_result -aarch64_handle_standard_branch_protection (char* str, char* rest) -{ - aarch64_ra_sign_scope = AARCH64_FUNCTION_NON_LEAF; - aarch64_ra_sign_key = AARCH64_KEY_A; - aarch64_enable_bti = 1; - if (rest) - { - error ("unexpected %<%s%> after %<%s%>", rest, str); - return AARCH64_PARSE_INVALID_FEATURE; - } - return AARCH64_PARSE_OK; -} - -static enum aarch64_parse_opt_result -aarch64_handle_pac_ret_protection (char* str ATTRIBUTE_UNUSED, - char* rest ATTRIBUTE_UNUSED) -{ - aarch64_ra_sign_scope = AARCH64_FUNCTION_NON_LEAF; - aarch64_ra_sign_key = AARCH64_KEY_A; - return AARCH64_PARSE_OK; -} - -static enum aarch64_parse_opt_result -aarch64_handle_pac_ret_leaf (char* str ATTRIBUTE_UNUSED, - char* rest ATTRIBUTE_UNUSED) -{ - aarch64_ra_sign_scope = AARCH64_FUNCTION_ALL; - return AARCH64_PARSE_OK; -} - -static enum aarch64_parse_opt_result -aarch64_handle_pac_ret_b_key (char* str ATTRIBUTE_UNUSED, - char* rest ATTRIBUTE_UNUSED) -{ - aarch64_ra_sign_key = AARCH64_KEY_B; - return AARCH64_PARSE_OK; -} - -static enum aarch64_parse_opt_result -aarch64_handle_bti_protection (char* str ATTRIBUTE_UNUSED, - char* rest ATTRIBUTE_UNUSED) -{ - aarch64_enable_bti = 1; - return AARCH64_PARSE_OK; -} - -static const struct aarch64_branch_protect_type aarch64_pac_ret_subtypes[] = { - { "leaf", aarch64_handle_pac_ret_leaf, NULL, 0 }, - { "b-key", aarch64_handle_pac_ret_b_key, NULL, 0 }, - { NULL, NULL, NULL, 0 } -}; - -static const struct aarch64_branch_protect_type aarch64_branch_protect_types[] = { - { "none", aarch64_handle_no_branch_protection, NULL, 0 }, - { "standard", aarch64_handle_standard_branch_protection, NULL, 0 }, - { "pac-ret", aarch64_handle_pac_ret_protection, aarch64_pac_ret_subtypes, - ARRAY_SIZE (aarch64_pac_ret_subtypes) }, - { "bti", aarch64_handle_bti_protection, NULL, 0 }, - { NULL, NULL, NULL, 0 } -}; /* The condition codes of the processor, and the inverse function. */ static const char * const aarch64_condition_codes[] = @@ -8893,10 +8799,10 @@ aarch64_return_address_signing_enabled (void) if (crtl->calls_eh_return) return false; - /* If signing scope is AARCH64_FUNCTION_NON_LEAF, we only sign a leaf function + /* If signing scope is AARCH_FUNCTION_NON_LEAF, we only sign a leaf function if its LR is pushed onto stack. */ - return (aarch64_ra_sign_scope == AARCH64_FUNCTION_ALL - || (aarch64_ra_sign_scope == AARCH64_FUNCTION_NON_LEAF + return (aarch_ra_sign_scope == AARCH_FUNCTION_ALL + || (aarch_ra_sign_scope == AARCH_FUNCTION_NON_LEAF && known_ge (cfun->machine->frame.reg_offset[LR_REGNUM], 0))); } @@ -8904,7 +8810,7 @@ aarch64_return_address_signing_enabled (void) bool aarch64_bti_enabled (void) { - return (aarch64_enable_bti == 1); + return (aarch_enable_bti == 1); } /* The caller is going to use ST1D or LD1D to save or restore an SVE @@ -9896,12 +9802,12 @@ aarch64_expand_prologue (void) /* Sign return address for functions. */ if (aarch64_return_address_signing_enabled ()) { - switch (aarch64_ra_sign_key) + switch (aarch_ra_sign_key) { - case AARCH64_KEY_A: + case AARCH_KEY_A: insn = emit_insn (gen_paciasp ()); break; - case AARCH64_KEY_B: + case AARCH_KEY_B: insn = emit_insn (gen_pacibsp ()); break; default: @@ -10202,12 +10108,12 @@ aarch64_expand_epilogue (bool for_sibcall) if (aarch64_return_address_signing_enabled () && (for_sibcall || !TARGET_ARMV8_3)) { - switch (aarch64_ra_sign_key) + switch (aarch_ra_sign_key) { - case AARCH64_KEY_A: + case AARCH_KEY_A: insn = emit_insn (gen_autiasp ()); break; - case AARCH64_KEY_B: + case AARCH_KEY_B: insn = emit_insn (gen_autibsp ()); break; default: @@ -17222,12 +17128,12 @@ static void initialize_aarch64_code_model (struct gcc_options *); /* Parse the TO_PARSE string and put the architecture struct that it selects into RES and the architectural features into ISA_FLAGS. - Return an aarch64_parse_opt_result describing the parse result. + Return an aarch_parse_opt_result describing the parse result. If there is an error parsing, RES and ISA_FLAGS are left unchanged. When the TO_PARSE string contains an invalid extension, a copy of the string is created and stored to INVALID_EXTENSION. */ -static enum aarch64_parse_opt_result +static enum aarch_parse_opt_result aarch64_parse_arch (const char *to_parse, const struct processor **res, aarch64_feature_flags *isa_flags, std::string *invalid_extension) @@ -17244,7 +17150,7 @@ aarch64_parse_arch (const char *to_parse, const struct processor **res, len = strlen (to_parse); if (len == 0) - return AARCH64_PARSE_MISSING_ARG; + return AARCH_PARSE_MISSING_ARG; /* Loop through the list of supported ARCHes to find a match. */ @@ -17258,32 +17164,32 @@ aarch64_parse_arch (const char *to_parse, const struct processor **res, if (ext != NULL) { /* TO_PARSE string contains at least one extension. */ - enum aarch64_parse_opt_result ext_res + enum aarch_parse_opt_result ext_res = aarch64_parse_extension (ext, &isa_temp, invalid_extension); - if (ext_res != AARCH64_PARSE_OK) + if (ext_res != AARCH_PARSE_OK) return ext_res; } /* Extension parsing was successful. Confirm the result arch and ISA flags. */ *res = arch; *isa_flags = isa_temp; - return AARCH64_PARSE_OK; + return AARCH_PARSE_OK; } } /* ARCH name not found in list. */ - return AARCH64_PARSE_INVALID_ARG; + return AARCH_PARSE_INVALID_ARG; } /* Parse the TO_PARSE string and put the result tuning in RES and the - architecture flags in ISA_FLAGS. Return an aarch64_parse_opt_result + architecture flags in ISA_FLAGS. Return an aarch_parse_opt_result describing the parse result. If there is an error parsing, RES and ISA_FLAGS are left unchanged. When the TO_PARSE string contains an invalid extension, a copy of the string is created and stored to INVALID_EXTENSION. */ -static enum aarch64_parse_opt_result +static enum aarch_parse_opt_result aarch64_parse_cpu (const char *to_parse, const struct processor **res, aarch64_feature_flags *isa_flags, std::string *invalid_extension) @@ -17300,7 +17206,7 @@ aarch64_parse_cpu (const char *to_parse, const struct processor **res, len = strlen (to_parse); if (len == 0) - return AARCH64_PARSE_MISSING_ARG; + return AARCH_PARSE_MISSING_ARG; /* Loop through the list of supported CPUs to find a match. */ @@ -17313,29 +17219,29 @@ aarch64_parse_cpu (const char *to_parse, const struct processor **res, if (ext != NULL) { /* TO_PARSE string contains at least one extension. */ - enum aarch64_parse_opt_result ext_res + enum aarch_parse_opt_result ext_res = aarch64_parse_extension (ext, &isa_temp, invalid_extension); - if (ext_res != AARCH64_PARSE_OK) + if (ext_res != AARCH_PARSE_OK) return ext_res; } /* Extension parsing was successfull. Confirm the result cpu and ISA flags. */ *res = cpu; *isa_flags = isa_temp; - return AARCH64_PARSE_OK; + return AARCH_PARSE_OK; } } /* CPU name not found in list. */ - return AARCH64_PARSE_INVALID_ARG; + return AARCH_PARSE_INVALID_ARG; } /* Parse the TO_PARSE string and put the cpu it selects into RES. - Return an aarch64_parse_opt_result describing the parse result. + Return an aarch_parse_opt_result describing the parse result. If the parsing fails the RES does not change. */ -static enum aarch64_parse_opt_result +static enum aarch_parse_opt_result aarch64_parse_tune (const char *to_parse, const struct processor **res) { const struct processor *cpu; @@ -17346,12 +17252,12 @@ aarch64_parse_tune (const char *to_parse, const struct processor **res) if (strcmp (cpu->name, to_parse) == 0) { *res = cpu; - return AARCH64_PARSE_OK; + return AARCH_PARSE_OK; } } /* CPU name not found in list. */ - return AARCH64_PARSE_INVALID_ARG; + return AARCH_PARSE_INVALID_ARG; } /* Parse TOKEN, which has length LENGTH to see if it is an option @@ -17942,22 +17848,22 @@ aarch64_validate_mcpu (const char *str, const struct processor **res, aarch64_feature_flags *isa_flags) { std::string invalid_extension; - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_cpu (str, res, isa_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) return true; switch (parse_res) { - case AARCH64_PARSE_MISSING_ARG: + case AARCH_PARSE_MISSING_ARG: error ("missing cpu name in %<-mcpu=%s%>", str); break; - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("unknown value %qs for %<-mcpu%>", str); aarch64_print_hint_for_core (str); break; - case AARCH64_PARSE_INVALID_FEATURE: + case AARCH_PARSE_INVALID_FEATURE: error ("invalid feature modifier %qs in %<-mcpu=%s%>", invalid_extension.c_str (), str); aarch64_print_hint_for_extensions (invalid_extension); @@ -18042,110 +17948,6 @@ aarch64_validate_sls_mitigation (const char *const_str) free (str_root); } -/* Parses CONST_STR for branch protection features specified in - aarch64_branch_protect_types, and set any global variables required. Returns - the parsing result and assigns LAST_STR to the last processed token from - CONST_STR so that it can be used for error reporting. */ - -static enum -aarch64_parse_opt_result aarch64_parse_branch_protection (const char *const_str, - char** last_str) -{ - char *str_root = xstrdup (const_str); - char* token_save = NULL; - char *str = strtok_r (str_root, "+", &token_save); - enum aarch64_parse_opt_result res = AARCH64_PARSE_OK; - if (!str) - res = AARCH64_PARSE_MISSING_ARG; - else - { - char *next_str = strtok_r (NULL, "+", &token_save); - /* Reset the branch protection features to their defaults. */ - aarch64_handle_no_branch_protection (NULL, NULL); - - while (str && res == AARCH64_PARSE_OK) - { - const aarch64_branch_protect_type* type = aarch64_branch_protect_types; - bool found = false; - /* Search for this type. */ - while (type && type->name && !found && res == AARCH64_PARSE_OK) - { - if (strcmp (str, type->name) == 0) - { - found = true; - res = type->handler (str, next_str); - str = next_str; - next_str = strtok_r (NULL, "+", &token_save); - } - else - type++; - } - if (found && res == AARCH64_PARSE_OK) - { - bool found_subtype = true; - /* Loop through each token until we find one that isn't a - subtype. */ - while (found_subtype) - { - found_subtype = false; - const aarch64_branch_protect_type *subtype = type->subtypes; - /* Search for the subtype. */ - while (str && subtype && subtype->name && !found_subtype - && res == AARCH64_PARSE_OK) - { - if (strcmp (str, subtype->name) == 0) - { - found_subtype = true; - res = subtype->handler (str, next_str); - str = next_str; - next_str = strtok_r (NULL, "+", &token_save); - } - else - subtype++; - } - } - } - else if (!found) - res = AARCH64_PARSE_INVALID_ARG; - } - } - /* Copy the last processed token into the argument to pass it back. - Used by option and attribute validation to print the offending token. */ - if (last_str) - { - if (str) strcpy (*last_str, str); - else *last_str = NULL; - } - if (res == AARCH64_PARSE_OK) - { - /* If needed, alloc the accepted string then copy in const_str. - Used by override_option_after_change_1. */ - if (!accepted_branch_protection_string) - accepted_branch_protection_string = (char *) xmalloc ( - BRANCH_PROTECT_STR_MAX - + 1); - strncpy (accepted_branch_protection_string, const_str, - BRANCH_PROTECT_STR_MAX + 1); - /* Forcibly null-terminate. */ - accepted_branch_protection_string[BRANCH_PROTECT_STR_MAX] = '\0'; - } - return res; -} - -static bool -aarch64_validate_mbranch_protection (const char *const_str) -{ - char *str = (char *) xmalloc (strlen (const_str)); - enum aarch64_parse_opt_result res = - aarch64_parse_branch_protection (const_str, &str); - if (res == AARCH64_PARSE_INVALID_ARG) - error ("invalid argument %<%s%> for %<-mbranch-protection=%>", str); - else if (res == AARCH64_PARSE_MISSING_ARG) - error ("missing argument for %<-mbranch-protection=%>"); - free (str); - return res == AARCH64_PARSE_OK; -} - /* Validate a command-line -march option. Parse the arch and extensions (if any) specified in STR and throw errors if appropriate. Put the results, if they are valid, in RES and ISA_FLAGS. Return whether the @@ -18156,27 +17958,27 @@ aarch64_validate_march (const char *str, const struct processor **res, aarch64_feature_flags *isa_flags) { std::string invalid_extension; - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_arch (str, res, isa_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) return true; switch (parse_res) { - case AARCH64_PARSE_MISSING_ARG: + case AARCH_PARSE_MISSING_ARG: error ("missing arch name in %<-march=%s%>", str); break; - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("unknown value %qs for %<-march%>", str); aarch64_print_hint_for_arch (str); /* A common user error is confusing -march and -mcpu. If the -march string matches a known CPU suggest -mcpu. */ parse_res = aarch64_parse_cpu (str, res, isa_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) inform (input_location, "did you mean %<-mcpu=%s%>?", str); break; - case AARCH64_PARSE_INVALID_FEATURE: + case AARCH_PARSE_INVALID_FEATURE: error ("invalid feature modifier %qs in %<-march=%s%>", invalid_extension.c_str (), str); aarch64_print_hint_for_extensions (invalid_extension); @@ -18196,18 +17998,18 @@ aarch64_validate_march (const char *str, const struct processor **res, static bool aarch64_validate_mtune (const char *str, const struct processor **res) { - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_tune (str, res); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) return true; switch (parse_res) { - case AARCH64_PARSE_MISSING_ARG: + case AARCH_PARSE_MISSING_ARG: error ("missing cpu name in %<-mtune=%s%>", str); break; - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("unknown value %qs for %<-mtune%>", str); aarch64_print_hint_for_core (str); break; @@ -18269,7 +18071,7 @@ aarch64_override_options (void) aarch64_validate_sls_mitigation (aarch64_harden_sls_string); if (aarch64_branch_protection_string) - aarch64_validate_mbranch_protection (aarch64_branch_protection_string); + aarch_validate_mbranch_protection (aarch64_branch_protection_string); /* -mcpu=CPU is shorthand for -march=ARCH_FOR_CPU, -mtune=CPU. If either of -march or -mtune is given, they override their @@ -18322,12 +18124,12 @@ aarch64_override_options (void) selected_tune = tune ? tune->ident : cpu->ident; - if (aarch64_enable_bti == 2) + if (aarch_enable_bti == 2) { #ifdef TARGET_ENABLE_BTI - aarch64_enable_bti = 1; + aarch_enable_bti = 1; #else - aarch64_enable_bti = 0; + aarch_enable_bti = 0; #endif } @@ -18337,9 +18139,9 @@ aarch64_override_options (void) if (!TARGET_ILP32 && accepted_branch_protection_string == NULL) { #ifdef TARGET_ENABLE_PAC_RET - aarch64_ra_sign_scope = AARCH64_FUNCTION_NON_LEAF; + aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF; #else - aarch64_ra_sign_scope = AARCH64_FUNCTION_NONE; + aarch_ra_sign_scope = AARCH_FUNCTION_NONE; #endif } @@ -18353,7 +18155,7 @@ aarch64_override_options (void) /* Convert -msve-vector-bits to a VG count. */ aarch64_sve_vg = aarch64_convert_sve_vector_bits (aarch64_sve_vector_bits); - if (aarch64_ra_sign_scope != AARCH64_FUNCTION_NONE && TARGET_ILP32) + if (aarch_ra_sign_scope != AARCH_FUNCTION_NONE && TARGET_ILP32) sorry ("return address signing is only supported for %<-mabi=lp64%>"); /* The pass to insert speculation tracking runs before @@ -18568,10 +18370,10 @@ aarch64_handle_attr_arch (const char *str) const struct processor *tmp_arch = NULL; std::string invalid_extension; aarch64_feature_flags tmp_flags; - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_arch (str, &tmp_arch, &tmp_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) { gcc_assert (tmp_arch); selected_arch = tmp_arch->arch; @@ -18581,14 +18383,14 @@ aarch64_handle_attr_arch (const char *str) switch (parse_res) { - case AARCH64_PARSE_MISSING_ARG: + case AARCH_PARSE_MISSING_ARG: error ("missing name in % pragma or attribute"); break; - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("invalid name %qs in % pragma or attribute", str); aarch64_print_hint_for_arch (str); break; - case AARCH64_PARSE_INVALID_FEATURE: + case AARCH_PARSE_INVALID_FEATURE: error ("invalid feature modifier %s of value %qs in " "% pragma or attribute", invalid_extension.c_str (), str); aarch64_print_hint_for_extensions (invalid_extension); @@ -18608,10 +18410,10 @@ aarch64_handle_attr_cpu (const char *str) const struct processor *tmp_cpu = NULL; std::string invalid_extension; aarch64_feature_flags tmp_flags; - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_cpu (str, &tmp_cpu, &tmp_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) { gcc_assert (tmp_cpu); selected_tune = tmp_cpu->ident; @@ -18622,14 +18424,14 @@ aarch64_handle_attr_cpu (const char *str) switch (parse_res) { - case AARCH64_PARSE_MISSING_ARG: + case AARCH_PARSE_MISSING_ARG: error ("missing name in % pragma or attribute"); break; - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("invalid name %qs in % pragma or attribute", str); aarch64_print_hint_for_core (str); break; - case AARCH64_PARSE_INVALID_FEATURE: + case AARCH_PARSE_INVALID_FEATURE: error ("invalid feature modifier %qs of value %qs in " "% pragma or attribute", invalid_extension.c_str (), str); aarch64_print_hint_for_extensions (invalid_extension); @@ -18647,23 +18449,23 @@ aarch64_handle_attr_cpu (const char *str) aarch64_handle_attr_branch_protection (const char* str) { char *err_str = (char *) xmalloc (strlen (str) + 1); - enum aarch64_parse_opt_result res = aarch64_parse_branch_protection (str, - &err_str); + enum aarch_parse_opt_result res = aarch_parse_branch_protection (str, + &err_str); bool success = false; switch (res) { - case AARCH64_PARSE_MISSING_ARG: + case AARCH_PARSE_MISSING_ARG: error ("missing argument to % pragma or" " attribute"); break; - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("invalid protection type %qs in % pragma or attribute", err_str); break; - case AARCH64_PARSE_OK: + case AARCH_PARSE_OK: success = true; /* Fall through. */ - case AARCH64_PARSE_INVALID_FEATURE: + case AARCH_PARSE_INVALID_FEATURE: break; default: gcc_unreachable (); @@ -18678,10 +18480,10 @@ static bool aarch64_handle_attr_tune (const char *str) { const struct processor *tmp_tune = NULL; - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_tune (str, &tmp_tune); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) { gcc_assert (tmp_tune); selected_tune = tmp_tune->ident; @@ -18690,7 +18492,7 @@ aarch64_handle_attr_tune (const char *str) switch (parse_res) { - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("invalid name %qs in % pragma or attribute", str); aarch64_print_hint_for_core (str); break; @@ -18709,7 +18511,7 @@ aarch64_handle_attr_tune (const char *str) static bool aarch64_handle_attr_isa_flags (char *str) { - enum aarch64_parse_opt_result parse_res; + enum aarch_parse_opt_result parse_res; auto isa_flags = aarch64_asm_isa_flags; /* We allow "+nothing" in the beginning to clear out all architectural @@ -18723,7 +18525,7 @@ aarch64_handle_attr_isa_flags (char *str) std::string invalid_extension; parse_res = aarch64_parse_extension (str, &isa_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) { aarch64_set_asm_isa_flags (isa_flags); return true; @@ -18731,11 +18533,11 @@ aarch64_handle_attr_isa_flags (char *str) switch (parse_res) { - case AARCH64_PARSE_MISSING_ARG: + case AARCH_PARSE_MISSING_ARG: error ("missing value in % pragma or attribute"); break; - case AARCH64_PARSE_INVALID_FEATURE: + case AARCH_PARSE_INVALID_FEATURE: error ("invalid feature modifier %qs of value %qs in " "% pragma or attribute", invalid_extension.c_str (), str); break; @@ -18984,10 +18786,10 @@ aarch64_process_target_attr (tree args) leading '+'. */ aarch64_feature_flags isa_temp = 0; auto with_plus = std::string ("+") + token; - enum aarch64_parse_opt_result ext_res + enum aarch_parse_opt_result ext_res = aarch64_parse_extension (with_plus.c_str (), &isa_temp, nullptr); - if (ext_res == AARCH64_PARSE_OK) + if (ext_res == AARCH_PARSE_OK) error ("arch extension %<%s%> should be prefixed by %<+%>", token); else @@ -22753,7 +22555,7 @@ void aarch64_post_cfi_startproc (FILE *f, tree ignored ATTRIBUTE_UNUSED) { if (cfun->machine->frame.laid_out && aarch64_return_address_signing_enabled () - && aarch64_ra_sign_key == AARCH64_KEY_B) + && aarch_ra_sign_key == AARCH_KEY_B) asm_fprintf (f, "\t.cfi_b_key_frame\n"); } @@ -27163,7 +26965,7 @@ aarch64_file_end_indicate_exec_stack () if (aarch64_bti_enabled ()) feature_1_and |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI; - if (aarch64_ra_sign_scope != AARCH64_FUNCTION_NONE) + if (aarch_ra_sign_scope != AARCH_FUNCTION_NONE) feature_1_and |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC; if (feature_1_and) diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 896b6a8ac79..9711a1ed419 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -891,7 +891,7 @@ (define_insn "*do_return" if (aarch64_return_address_signing_enabled () && (TARGET_PAUTH)) { - if (aarch64_ra_sign_key == AARCH64_KEY_B) + if (aarch_ra_sign_key == AARCH_KEY_B) ret = "retab"; else ret = "retaa"; diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt index b89b2045071..ded70bf7e39 100644 --- a/gcc/config/aarch64/aarch64.opt +++ b/gcc/config/aarch64/aarch64.opt @@ -21,6 +21,9 @@ HeaderInclude config/aarch64/aarch64-opts.h +HeaderInclude +config/arm/aarch-common.h + TargetVariable enum aarch64_processor selected_tune = aarch64_none @@ -34,7 +37,7 @@ TargetVariable aarch64_feature_flags aarch64_isa_flags = 0 TargetVariable -unsigned aarch64_enable_bti = 2 +unsigned aarch_enable_bti = 2 TargetVariable enum aarch64_key_type aarch64_ra_sign_key = AARCH64_KEY_A @@ -164,21 +167,21 @@ Target RejectNegative Joined Var(aarch64_branch_protection_string) Save Use branch-protection features. msign-return-address= -Target WarnRemoved RejectNegative Joined Enum(aarch64_ra_sign_scope_t) Var(aarch64_ra_sign_scope) Init(AARCH64_FUNCTION_NONE) Save +Target WarnRemoved RejectNegative Joined Enum(aarch_ra_sign_scope_t) Var(aarch_ra_sign_scope) Init(AARCH_FUNCTION_NONE) Save Select return address signing scope. Enum -Name(aarch64_ra_sign_scope_t) Type(enum aarch64_function_type) +Name(aarch_ra_sign_scope_t) Type(enum aarch_function_type) Supported AArch64 return address signing scope (for use with -msign-return-address= option): EnumValue -Enum(aarch64_ra_sign_scope_t) String(none) Value(AARCH64_FUNCTION_NONE) +Enum(aarch_ra_sign_scope_t) String(none) Value(AARCH_FUNCTION_NONE) EnumValue -Enum(aarch64_ra_sign_scope_t) String(non-leaf) Value(AARCH64_FUNCTION_NON_LEAF) +Enum(aarch_ra_sign_scope_t) String(non-leaf) Value(AARCH_FUNCTION_NON_LEAF) EnumValue -Enum(aarch64_ra_sign_scope_t) String(all) Value(AARCH64_FUNCTION_ALL) +Enum(aarch_ra_sign_scope_t) String(all) Value(AARCH_FUNCTION_ALL) mlow-precision-recip-sqrt Target Var(flag_mrecip_low_precision_sqrt) Optimization diff --git a/gcc/config/arm/aarch-common-protos.h b/gcc/config/arm/aarch-common-protos.h index ae0465159f7..17a369f7e99 100644 --- a/gcc/config/arm/aarch-common-protos.h +++ b/gcc/config/arm/aarch-common-protos.h @@ -153,4 +153,10 @@ rtx_insn *arm_md_asm_adjust (vec &outputs, vec & /*inputs*/, vec &clobbers, HARD_REG_SET &clobbered_regs, location_t loc); +/* Parsing routine for branch-protection common to AArch64 and Arm. */ +enum aarch_parse_opt_result aarch_parse_branch_protection (const char*, char**); + +/* Validation routine for branch-protection common to AArch64 and Arm. */ +bool aarch_validate_mbranch_protection (const char *); + #endif /* GCC_AARCH_COMMON_PROTOS_H */ diff --git a/gcc/config/arm/aarch-common.cc b/gcc/config/arm/aarch-common.cc index 04a53d75093..6d254101f6a 100644 --- a/gcc/config/arm/aarch-common.cc +++ b/gcc/config/arm/aarch-common.cc @@ -36,6 +36,7 @@ #include "expr.h" #include "function.h" #include "emit-rtl.h" +#include "aarch-common.h" /* Return TRUE if X is either an arithmetic shift left, or is a multiplication by a power of two. */ @@ -657,3 +658,187 @@ arm_md_asm_adjust (vec &outputs, vec & /*inputs*/, return saw_asm_flag ? seq : NULL; } + +#define BRANCH_PROTECT_STR_MAX 255 +extern char *accepted_branch_protection_string; +extern enum aarch_key_type aarch_ra_sign_key; + +static enum aarch_parse_opt_result +aarch_handle_no_branch_protection (char* str, char* rest) +{ + aarch_ra_sign_scope = AARCH_FUNCTION_NONE; + aarch_enable_bti = 0; + if (rest) + { + error ("unexpected %<%s%> after %<%s%>", rest, str); + return AARCH_PARSE_INVALID_FEATURE; + } + return AARCH_PARSE_OK; +} + +static enum aarch_parse_opt_result +aarch_handle_standard_branch_protection (char* str, char* rest) +{ + aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF; + aarch_ra_sign_key = AARCH_KEY_A; + aarch_enable_bti = 1; + if (rest) + { + error ("unexpected %<%s%> after %<%s%>", rest, str); + return AARCH_PARSE_INVALID_FEATURE; + } + return AARCH_PARSE_OK; +} + +static enum aarch_parse_opt_result +aarch_handle_pac_ret_protection (char* str ATTRIBUTE_UNUSED, + char* rest ATTRIBUTE_UNUSED) +{ + aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF; + aarch_ra_sign_key = AARCH_KEY_A; + return AARCH_PARSE_OK; +} + +static enum aarch_parse_opt_result +aarch_handle_pac_ret_leaf (char* str ATTRIBUTE_UNUSED, + char* rest ATTRIBUTE_UNUSED) +{ + aarch_ra_sign_scope = AARCH_FUNCTION_ALL; + return AARCH_PARSE_OK; +} + +static enum aarch_parse_opt_result +aarch_handle_pac_ret_b_key (char* str ATTRIBUTE_UNUSED, + char* rest ATTRIBUTE_UNUSED) +{ + aarch_ra_sign_key = AARCH_KEY_B; + return AARCH_PARSE_OK; +} + +static enum aarch_parse_opt_result +aarch_handle_bti_protection (char* str ATTRIBUTE_UNUSED, + char* rest ATTRIBUTE_UNUSED) +{ + aarch_enable_bti = 1; + return AARCH_PARSE_OK; +} + +static const struct aarch_branch_protect_type aarch_pac_ret_subtypes[] = { + { "leaf", aarch_handle_pac_ret_leaf, NULL, 0 }, + { "b-key", aarch_handle_pac_ret_b_key, NULL, 0 }, + { NULL, NULL, NULL, 0 } +}; + +static const struct aarch_branch_protect_type aarch_branch_protect_types[] = { + { "none", aarch_handle_no_branch_protection, NULL, 0 }, + { "standard", aarch_handle_standard_branch_protection, NULL, 0 }, + { "pac-ret", aarch_handle_pac_ret_protection, aarch_pac_ret_subtypes, + ARRAY_SIZE (aarch_pac_ret_subtypes) }, + { "bti", aarch_handle_bti_protection, NULL, 0 }, + { NULL, NULL, NULL, 0 } +}; + +/* Parses CONST_STR for branch protection features specified in + aarch64_branch_protect_types, and set any global variables required. Returns + the parsing result and assigns LAST_STR to the last processed token from + CONST_STR so that it can be used for error reporting. */ + +enum aarch_parse_opt_result +aarch_parse_branch_protection (const char *const_str, char** last_str) +{ + char *str_root = xstrdup (const_str); + char* token_save = NULL; + char *str = strtok_r (str_root, "+", &token_save); + enum aarch_parse_opt_result res = AARCH_PARSE_OK; + if (!str) + res = AARCH_PARSE_MISSING_ARG; + else + { + char *next_str = strtok_r (NULL, "+", &token_save); + /* Reset the branch protection features to their defaults. */ + aarch_handle_no_branch_protection (NULL, NULL); + + while (str && res == AARCH_PARSE_OK) + { + const aarch_branch_protect_type* type = aarch_branch_protect_types; + bool found = false; + /* Search for this type. */ + while (type && type->name && !found && res == AARCH_PARSE_OK) + { + if (strcmp (str, type->name) == 0) + { + found = true; + res = type->handler (str, next_str); + str = next_str; + next_str = strtok_r (NULL, "+", &token_save); + } + else + type++; + } + if (found && res == AARCH_PARSE_OK) + { + bool found_subtype = true; + /* Loop through each token until we find one that isn't a + subtype. */ + while (found_subtype) + { + found_subtype = false; + const aarch_branch_protect_type *subtype = type->subtypes; + /* Search for the subtype. */ + while (str && subtype && subtype->name && !found_subtype + && res == AARCH_PARSE_OK) + { + if (strcmp (str, subtype->name) == 0) + { + found_subtype = true; + res = subtype->handler (str, next_str); + str = next_str; + next_str = strtok_r (NULL, "+", &token_save); + } + else + subtype++; + } + } + } + else if (!found) + res = AARCH_PARSE_INVALID_ARG; + } + } + /* Copy the last processed token into the argument to pass it back. + Used by option and attribute validation to print the offending token. */ + if (last_str) + { + if (str) + strcpy (*last_str, str); + else + *last_str = NULL; + } + + if (res == AARCH_PARSE_OK) + { + /* If needed, alloc the accepted string then copy in const_str. + Used by override_option_after_change_1. */ + if (!accepted_branch_protection_string) + accepted_branch_protection_string + = (char *) xmalloc (BRANCH_PROTECT_STR_MAX + 1); + strncpy (accepted_branch_protection_string, const_str, + BRANCH_PROTECT_STR_MAX + 1); + /* Forcibly null-terminate. */ + accepted_branch_protection_string[BRANCH_PROTECT_STR_MAX] = '\0'; + } + return res; +} + +bool +aarch_validate_mbranch_protection (const char *const_str) +{ + char *str = (char *) xmalloc (strlen (const_str)); + enum aarch_parse_opt_result res = + aarch_parse_branch_protection (const_str, &str); + if (res == AARCH_PARSE_INVALID_ARG) + error ("invalid argument %<%s%> for %<-mbranch-protection=%>", str); + else if (res == AARCH_PARSE_MISSING_ARG) + error ("missing argument for %<-mbranch-protection=%>"); + free (str); + return res == AARCH_PARSE_OK; +} diff --git a/gcc/config/arm/aarch-common.h b/gcc/config/arm/aarch-common.h new file mode 100644 index 00000000000..c6a67f0d05c --- /dev/null +++ b/gcc/config/arm/aarch-common.h @@ -0,0 +1,73 @@ +/* Types shared between arm and aarch64. + + Copyright (C) 2009-2021 Free Software Foundation, Inc. + Contributed by Arm Ltd. + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ + +#ifndef GCC_AARCH_COMMON_H +#define GCC_AARCH_COMMON_H + +/* Enum describing the various ways that the + aarch*_parse_{arch,tune,cpu,extension} functions can fail. + This way their callers can choose what kind of error to give. */ + +enum aarch_parse_opt_result +{ + AARCH_PARSE_OK, /* Parsing was successful. */ + AARCH_PARSE_MISSING_ARG, /* Missing argument. */ + AARCH_PARSE_INVALID_FEATURE, /* Invalid feature modifier. */ + AARCH_PARSE_INVALID_ARG /* Invalid arch, tune, cpu arg. */ +}; + +/* Function types -msign-return-address should sign. */ +enum aarch_function_type { + /* Don't sign any function. */ + AARCH_FUNCTION_NONE, + /* Non-leaf functions. */ + AARCH_FUNCTION_NON_LEAF, + /* All functions. */ + AARCH_FUNCTION_ALL +}; + +/* The key type that -msign-return-address should use. */ +enum aarch_key_type { + AARCH_KEY_A, + AARCH_KEY_B +}; + +struct aarch_branch_protect_type +{ + /* The type's name that the user passes to the branch-protection option + string. */ + const char* name; + /* Function to handle the protection type and set global variables. + First argument is the string token corresponding with this type and the + second argument is the next token in the option string. + Return values: + * AARCH_PARSE_OK: Handling was sucessful. + * AARCH_INVALID_ARG: The type is invalid in this context and the caller + should print an error. + * AARCH_INVALID_FEATURE: The type is invalid and the handler prints its + own error. */ + enum aarch_parse_opt_result (*handler)(char*, char*); + /* A list of types that can follow this type in the option string. */ + const struct aarch_branch_protect_type* subtypes; + unsigned int num_subtypes; +}; + +#endif /* GCC_AARCH_COMMON_H */ diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h index 550272facd1..6e6bf147e9c 100644 --- a/gcc/config/arm/arm-protos.h +++ b/gcc/config/arm/arm-protos.h @@ -581,6 +581,8 @@ struct cpu_option extern const arch_option all_architectures[]; extern const cpu_option all_cores[]; +extern enum aarch_key_type aarch_ra_sign_key; + const cpu_option *arm_parse_cpu_option_name (const cpu_option *, const char *, const char *, bool = true); const arch_option *arm_parse_arch_option_name (const arch_option *, diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index b587561eebe..cfc8fdc4edd 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -72,6 +72,8 @@ #include "selftest.h" #include "tree-vectorizer.h" #include "opts.h" +#include "aarch-common.h" +#include "aarch-common-protos.h" /* This file should be included last. */ #include "target-def.h" @@ -2413,6 +2415,11 @@ const struct tune_params arm_fa726te_tune = tune_params::SCHED_AUTOPREF_OFF }; +/* Key type for Pointer Authentication extension. */ +enum aarch_key_type aarch_ra_sign_key = AARCH_KEY_A; + +char *accepted_branch_protection_string = NULL; + /* Auto-generated CPU, FPU and architecture tables. */ #include "arm-cpu-data.h" diff --git a/gcc/config/arm/arm.opt b/gcc/config/arm/arm.opt index 3209b6c623b..500ff06bed4 100644 --- a/gcc/config/arm/arm.opt +++ b/gcc/config/arm/arm.opt @@ -21,6 +21,15 @@ HeaderInclude config/arm/arm-opts.h +HeaderInclude +config/arm/aarch-common.h + +TargetVariable +enum aarch_function_type aarch_ra_sign_scope = AARCH_FUNCTION_NONE + +TargetVariable +unsigned aarch_enable_bti = 0 + Enum Name(tls_type) Type(enum arm_tls_type) TLS dialect to use: -- 2.25.1 --=-=-=--