From patchwork Thu Oct 28 11:41:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejas Belagod X-Patchwork-Id: 46739 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 0A4783858012 for ; Thu, 28 Oct 2021 11:42:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A4783858012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635421329; bh=18p0O29owTiaf1zOYObuEmNE7P53xoUjh9P67Mf0NN0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VhLMkyf9d6vJh/zKB/0fA5FfaGnwMdNwL1DUvPQcA8z7tUTWY6esv2BqPFLPsXODh 5zusBkmcqmhAIleErChCuaxntr0YuAW1DjDGCv3E7WApigHDxUN4bvKObPpc1Phkrr 94FCXsgH042uNsf5fgxAI3PLx0+xIbHdKvxcdjTE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60088.outbound.protection.outlook.com [40.107.6.88]) by sourceware.org (Postfix) with ESMTPS id 697D33857C72 for ; Thu, 28 Oct 2021 11:41:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 697D33857C72 Received: from AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) by HE1PR0801MB2076.eurprd08.prod.outlook.com (2603:10a6:3:4c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Thu, 28 Oct 2021 11:41:29 +0000 Received: from VE1EUR03FT036.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:469:cafe::50) by AS9PR0301CA0039.outlook.office365.com (2603:10a6:20b:469::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Thu, 28 Oct 2021 11:41:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT036.mail.protection.outlook.com (10.152.19.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14 via Frontend Transport; Thu, 28 Oct 2021 11:41:29 +0000 Received: ("Tessian outbound d49ee2bec50d:v108"); Thu, 28 Oct 2021 11:41:28 +0000 X-CR-MTA-TID: 64aa7808 Received: from 022f8c404fb1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F1CD4B07-BEDB-4FA0-8791-F0538CB0D906.1; Thu, 28 Oct 2021 11:41:22 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 022f8c404fb1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 28 Oct 2021 11:41:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HdycCkkgKm8mLlFeDUqjlaE61wTgAGDHGJE4ppyOc8vpN3a+ZHYMQxVypg4zgtr0sYZLQd3Ku5VXk36lYc75SrGkig0Qo2b5XQwGvle9nNpoonqCQznxxpxZVE6EvBNUuflv2mwO0asF3ks8QLOC2Fldn/U/V3AQRVRPqD63TUKCNDEumIEmGdEBHXmosf0Lj7oXk7aFwuYw3h/ZXcWwzY430SWrNv6jUQH+6eXyqWq4rdesmAeszQ7pBRYQ84DRHkPbP24xU1KDm3ZutL49ZgvjcfDNu8fGiyDiHDm40iXF8GOuKa03mOXxGI9hRl44g/Cy1d1yhWXTnBaxl153mQ== 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=18p0O29owTiaf1zOYObuEmNE7P53xoUjh9P67Mf0NN0=; b=jX3jy3C3zUv5bU3/e3+2hMd73kUuSHSnyqJD7BfqS6uRpvY2msZNluBdICR8P8jdHKxC/8pVQRBlMBcW3mXLbozgr828eMPrs0zcf+8UBi/SvVczx3oNr7q+JCSUK9yn+j71+d7+v+qWk74eLeNN3ArV3vsYNqkX+AF8JAvZZXrfgjyMDb9+jmUBe1k1fzGX9OpUFiEKl+KIJ/lmg8WXVmsE+awZkfU4XL8Vi/0HexCyeWOcVozH0Jlt5Dw5pAZZt9zUgSxBvgqixCkRegZu7UBpC1VVyfId2pEUYL0fCVRJloEf5c14Bi9pZbcqQhl1UaGPCrGFR1z+xPEuH3QCbw== 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 PAXPR08MB7075.eurprd08.prod.outlook.com (2603:10a6:102:201::15) by PAXPR08MB7261.eurprd08.prod.outlook.com (2603:10a6:102:210::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Thu, 28 Oct 2021 11:41:21 +0000 Received: from PAXPR08MB7075.eurprd08.prod.outlook.com ([fe80::9c7f:ad76:ac66:26f2]) by PAXPR08MB7075.eurprd08.prod.outlook.com ([fe80::9c7f:ad76:ac66:26f2%9]) with mapi id 15.20.4628.020; Thu, 28 Oct 2021 11:41:21 +0000 To: Richard Earnshaw , "gcc-patches@gcc.gnu.org" Subject: [Patch 1/8, Arm, AArch64, GCC] Refactor mbranch-protection option parsing and make it common to AArch32 and AArch64 backends. [Was RE: [Patch 2/7, Arm, GCC] Add option -mbranch-protection.] Thread-Topic: [Patch 1/8, Arm, AArch64, GCC] Refactor mbranch-protection option parsing and make it common to AArch32 and AArch64 backends. [Was RE: [Patch 2/7, Arm, GCC] Add option -mbranch-protection.] Thread-Index: AdfL8JcvuDyOwd6+SjWpR5X5uwhAlQ== Date: Thu, 28 Oct 2021 11:41:21 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-ts-tracking-id: B21AA4EF4D9DD54B8CDB47CAC94CF512.0 x-checkrecipientchecked: true Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: d517c707-431e-4bcd-b355-08d99a07e1b4 x-ms-traffictypediagnostic: PAXPR08MB7261:|HE1PR0801MB2076: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:6430;OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: g/kfL8JQI/5pKF7HDc/Q5OwHH0sW6Wnu3KFlqng1cavYXjmxNK5QJDp93elftIyMb/Gb6nFfe4uknp5H5Hbav5uvafKdHIeXy3CEqUpdZcp5JpyM8PP4ZnwZkw3H2qcvvygYdVlkiR/87O7klCmRbV1ozr5eiKYAAau8+jeOC555MnC0VUTozGB7dGdfYR/mLtszSH8CDyyVgKuYoQlfSnTFZcO9nylSmJRDT8d9ERgL7pFSyiGPn3buNTxOGHdXgBUc+z0l2336sLOhyvILXh4bTnpRXS0mpMWJ5lG+l5jznRIidWhcs+frHzxhmCjGt5X7o8VtdCt33BOzfjcBlmNFwD5ABBEu3ICJgnquv4pVjhXda9v8IzlJhYBZxdiMUNrOu8ybDEWxUBc3Y23FV6VmPyGBu1VJvbVmeuCXNJA/79ZoPaq7zWSKJjK80+QtSHMiupQcF7fSQn6gcDepomu2agSFz9D4B9yDSnljtrdO3r82lAX+m/8oBc1xh/2OkErnaweBpFgd68pWC9fp7CEY+k6HngeExipjqUcsoQBq9TRo4SZ752ZnhWeHKoiwiWtgh6is3hP+rZHuQlXvWVDW+NVPlBwWxrxo57wyJmi4d1dGijXoH94yo2nbhbJBKORqzGHb1sV6orZQYiODfM9O91SWjli50oxXeqi9cv0VsvyroGQ1LV8UYM3kNwecv1So4FsRjvHq7I+ERjgcEw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB7075.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(316002)(8676002)(110136005)(55016002)(9686003)(64756008)(66446008)(86362001)(38070700005)(66476007)(83380400001)(66556008)(8936002)(71200400001)(76116006)(66946007)(4001150100001)(7696005)(26005)(33656002)(52536014)(5660300002)(122000001)(2906002)(38100700002)(6506007)(53546011)(186003)(508600001)(99936003); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7261 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT036.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 0eed663d-03c4-4a86-cc46-08d99a07dd2f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1cHX/dmK/ljKtjpRwsh7E7qrAfraX7xLumPEs4+lNTdi93Z/2XGofgrpjUXRVbHNeQkoxq30bgr/MT6aHZDk+q++e7CmvRhRN2QnJ0uz+ui3ih7mxkqzjCQOzX94KmmQu4uGMttA7NnzvTkHW00qnbC2cpHWX0qjK8IXr+yeaNx0usr9MlRQdGH+Z5P8icZXqcpmDhGmuP5ZOCRaAoMeH1bs7CV4rSh/PnEjvYjgfQOkXiSdfEQSIU8OhcC9V3+IXvIk1zWkU6CvdUxcGbgsf0fjOroUDPRZ2kFu9ZHaS70W+DmeYM0TukaEwSaM8UI98NHgAFbk0NVfoR/KPsL0VzXel8fs3VcN2dUgdZebS04PnHvtq8cmhNrM4DFuK6dXk98S8lqZ/FO2zz0XGL0WwVDhKeqKZSX3QtANLF1WGTvAmV+GkI/9wgWQ7ujbWWMzdFTAuClLG+097EFnIlTFrdYcE6co5VpDlgTIj9h94PSD0wOV9EYKwlNPpOXYb3AOoOLGgKkVAULCHwkAplURhzn57fsbFAebTpqmLQ97ZKtHQXbnndhPwsv/jUDwziVS7xxRXEsThSmYSKyKeBr/4cET0Hy2j+iohKd6eHZ33OVVdkNKWcwDRYXSaUOFobNSJwh3m4gJEubHMn7uu++keSVWqAXpIC2XQAtmWfnmqQH0VccY0S2qAT9NbXWudyFtQ/WwMX/0aL0Ar+MSKgwY8w== 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:(4636009)(36840700001)(46966006)(26005)(21480400003)(9686003)(81166007)(70586007)(52536014)(356005)(36860700001)(55016002)(6506007)(33656002)(82310400003)(4001150100001)(33964004)(8676002)(83380400001)(53546011)(86362001)(316002)(336012)(8936002)(99936003)(70206006)(5660300002)(110136005)(2906002)(47076005)(186003)(235185007)(7696005)(508600001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 11:41:29.0411 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d517c707-431e-4bcd-b355-08d99a07e1b4 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: VE1EUR03FT036.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB2076 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tejas Belagod via Gcc-patches From: Tejas Belagod Reply-To: Tejas Belagod Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" > -----Original Message----- > From: Richard Earnshaw > Sent: Monday, October 11, 2021 1:58 PM > To: Tejas Belagod ; gcc-patches@gcc.gnu.org > Subject: Re: [Patch 2/7, Arm, GCC] Add option -mbranch-protection. > > On 08/10/2021 13:17, Tejas Belagod via Gcc-patches wrote: > > Hi, > > > > Add -mbranch-protection option and its associated parsing routines. > > This option enables the code-generation of pointer signing and > > authentication instructions in function prologues and epilogues. > > > > Tested on arm-none-eabi. OK for trunk? > > > > 2021-10-04 Tejas Belagod > > > > gcc/ChangeLog: > > > > * common/config/arm/arm-common.c > > (arm_print_hit_for_pacbti_option): New. > > (arm_progress_next_token): New. > > (arm_parse_pac_ret_clause): New routine for parsing the > > pac-ret clause for -mbranch-protection. > > (arm_parse_pacbti_option): New routine to parse all the options > > to -mbranch-protection. > > * config/arm/arm-protos.h (arm_parse_pacbti_option): Export. > > * config/arm/arm.c (arm_configure)build_target): Handle option > > to -mbranch-protection. > > * config/arm/arm.opt (mbranch-protection). New. > > (arm_enable_pacbti): New. > > > > You're missing documentation for invoke.texi. > > Also, how does this differ from the exising option in aarch64? Can the code > from that be adapted to be made common to both targets rather than doing > a new implementation? > > Finally, there are far to many manifest constants in this patch, they need > replacing with enums or #defines as appropriate if we cannot share the > aarch64 code. > Thanks for the reviews. 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 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. 2021-10-25 Tejas Belagod gcc/ChangeLog: * common/config/aarch64/aarch64-common.c: Include aarch-common.h. (all_architectures): Fix comment. (aarch64_parse_extension): Rename return type, enum value names. * config/aarch64/aarch64-c.c (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.c: Move mbranch-protection parsing types and functions out into aarch-common.h and aarch-common.c. 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.c: Include newly factored out types. Move all mbranch-protection code and data structures from aarch64.c. * 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. Tested the following configurations. OK for trunk? -mthumb/-march=armv8.1-m.main+pacbti/-mfloat-abi=soft -marm/-march=armv7-a/-mfpu=vfpv3-d16/-mfloat-abi=softfp mcmodel=small and tiny aarch64-none-linux-gnu native test and bootstrap Thanks, Tejas. > R. diff --git a/gcc/common/config/aarch64/aarch64-common.c b/gcc/common/config/aarch64/aarch64-common.c index 6d200a186604be2028b19ee9691e7bbf4a7be9c2..92c8f14a17466b9d6c44bdf4ede673a65f1b426f 100644 --- a/gcc/common/config/aarch64/aarch64-common.c +++ b/gcc/common/config/aarch64/aarch64-common.c @@ -30,6 +30,7 @@ #include "opts.h" #include "flags.h" #include "diagnostic.h" +#include "config/arm/aarch-common.h" #ifdef TARGET_BIG_ENDIAN_DEFAULT #undef TARGET_DEFAULT_TARGET_FLAGS @@ -192,11 +193,11 @@ static const struct 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, uint64_t *isa_flags, std::string *invalid_extension) { @@ -229,7 +230,7 @@ aarch64_parse_extension (const char *str, uint64_t *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. */ @@ -251,13 +252,13 @@ aarch64_parse_extension (const char *str, uint64_t *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.c b/gcc/config/aarch64/aarch64-c.c index f9ddffa007818a42710cfc0d60af580dd6c76f95..3518e9ab6cac6915e1b88eab450bb31879fbbabd 100644 --- a/gcc/config/aarch64/aarch64-c.c +++ b/gcc/config/aarch64/aarch64-c.c @@ -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 af3b7364a748f7b95cdbb5c1508a1e9566244175..d47e1e74f6c2f448ed364bf8787f11484e2f3595 100644 --- a/gcc/config/aarch64/aarch64-opts.h +++ b/gcc/config/aarch64/aarch64-opts.h @@ -71,16 +71,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 768e8fae136daa866fe589d72f30514e1229180f..b1dc87bcbdc888967a32a966ad0fd8a896e454be 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 @@ -637,18 +638,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 @@ -659,13 +648,7 @@ enum simd_immediate_check { AARCH64_CHECK_MOV = AARCH64_CHECK_ORR | AARCH64_CHECK_BIC }; -/* The key type that -msign-return-address should use. */ -enum aarch64_key_type { - AARCH64_KEY_A, - AARCH64_KEY_B -}; - -extern enum aarch64_key_type aarch64_ra_sign_key; +extern enum aarch_key_type aarch_ra_sign_key; extern struct tune_params aarch64_tune_params; @@ -1013,9 +996,9 @@ extern bool aarch64_classify_address (struct aarch64_address_info *, rtx, 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 *, - uint64_t *, - std::string *); +enum aarch_parse_opt_result aarch64_parse_extension (const char *, + uint64_t *, + std::string *); void aarch64_get_all_extension_candidates (auto_vec *candidates); std::string aarch64_get_extension_string_for_isa_flags (uint64_t, uint64_t); diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 699c105a42a613c06c462e2de686795279d85bc9..d2e1324520f8260a6abce6c162e2eb133e44e7c1 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -79,6 +79,8 @@ #include "tree-ssa-loop-niter.h" #include "fractional-cost.h" #include "rtlanal.h" +#include "config/arm/aarch-common.h" +#include "config/arm/aarch-common-protos.h" /* This file should be included last. */ #include "target-def.h" @@ -319,12 +321,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 @@ -2087,7 +2085,7 @@ static const struct processor *selected_arch; static const struct processor *selected_cpu; static const struct processor *selected_tune; -enum aarch64_key_type aarch64_ra_sign_key = AARCH64_KEY_A; +enum aarch_key_type aarch_ra_sign_key = AARCH_KEY_A; /* The current tuning set. */ struct tune_params aarch64_tune_params = generic_tunings; @@ -2156,100 +2154,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[] = @@ -7792,10 +7696,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))); } @@ -7803,7 +7707,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 @@ -8795,12 +8699,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: @@ -9084,12 +8988,12 @@ aarch64_expand_epilogue (bool for_sibcall) if (aarch64_return_address_signing_enabled () && (for_sibcall || !TARGET_ARMV8_3 || crtl->calls_eh_return)) { - 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: @@ -15994,12 +15898,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, uint64_t *isa_flags, std::string *invalid_extension) { @@ -16015,7 +15919,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. */ @@ -16029,32 +15933,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, uint64_t *isa_flags, std::string *invalid_extension) { @@ -16070,7 +15974,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. */ @@ -16084,29 +15988,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; @@ -16117,12 +16021,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 @@ -16696,22 +16600,22 @@ aarch64_validate_mcpu (const char *str, const struct processor **res, uint64_t *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); @@ -16796,110 +16700,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 @@ -16910,22 +16710,22 @@ aarch64_validate_march (const char *str, const struct processor **res, uint64_t *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); 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); @@ -16945,18 +16745,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; @@ -17044,7 +16844,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 @@ -17122,12 +16922,12 @@ aarch64_override_options (void) if (!selected_tune) selected_tune = selected_cpu; - 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 } @@ -17137,9 +16937,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 } @@ -17153,7 +16953,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%>"); /* Make sure we properly set up the explicit options. */ @@ -17280,7 +17080,7 @@ aarch64_option_restore (struct gcc_options *opts, = ptr->x_aarch64_branch_protection_string; if (opts->x_aarch64_branch_protection_string) { - aarch64_parse_branch_protection (opts->x_aarch64_branch_protection_string, + aarch_parse_branch_protection (opts->x_aarch64_branch_protection_string, NULL); } @@ -17404,10 +17204,10 @@ aarch64_handle_attr_arch (const char *str) { const struct processor *tmp_arch = NULL; std::string invalid_extension; - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_arch (str, &tmp_arch, &aarch64_isa_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) { gcc_assert (tmp_arch); selected_arch = tmp_arch; @@ -17417,14 +17217,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 (\"%s\") 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 (\"%s\") in " "% pragma or attribute", invalid_extension.c_str (), str); aarch64_print_hint_for_extensions (invalid_extension); @@ -17443,10 +17243,10 @@ aarch64_handle_attr_cpu (const char *str) { const struct processor *tmp_cpu = NULL; std::string invalid_extension; - enum aarch64_parse_opt_result parse_res + enum aarch_parse_opt_result parse_res = aarch64_parse_cpu (str, &tmp_cpu, &aarch64_isa_flags, &invalid_extension); - if (parse_res == AARCH64_PARSE_OK) + if (parse_res == AARCH_PARSE_OK) { gcc_assert (tmp_cpu); selected_tune = tmp_cpu; @@ -17459,14 +17259,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 (\"%s\") 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 %s of value (\"%s\") in " "% pragma or attribute", invalid_extension.c_str (), str); aarch64_print_hint_for_extensions (invalid_extension); @@ -17484,23 +17284,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 (\"%s\") 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 (); @@ -17515,10 +17315,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; @@ -17528,7 +17328,7 @@ aarch64_handle_attr_tune (const char *str) switch (parse_res) { - case AARCH64_PARSE_INVALID_ARG: + case AARCH_PARSE_INVALID_ARG: error ("invalid name (\"%s\") in % pragma or attribute", str); aarch64_print_hint_for_core (str); break; @@ -17547,7 +17347,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; uint64_t isa_flags = aarch64_isa_flags; /* We allow "+nothing" in the beginning to clear out all architectural @@ -17561,7 +17361,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_isa_flags = isa_flags; return true; @@ -17569,11 +17369,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 %s of value (\"%s\") in " "% pragma or attribute", invalid_extension.c_str (), str); break; @@ -21473,7 +21273,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"); } @@ -25574,7 +25374,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 1a39470a1feeb8d23a3d0d4f8a9b54535f769fd9..de6052b588ac6e8537ec0c8c40cc1476d3dfa8f5 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -882,7 +882,7 @@ && (TARGET_PAUTH) && !crtl->calls_eh_return) { - 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 32191cf1acf43302c4a544b85db60b7b6e14da48..0739a4fe0064c0359107cde3c1c34dae43075fa6 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 explicit_tune_core = aarch64_none @@ -34,7 +37,7 @@ TargetVariable uint64_t aarch64_isa_flags = 0 TargetVariable -unsigned aarch64_enable_bti = 2 +unsigned aarch_enable_bti = 2 ; The TLS dialect names to use with -mtls-dialect. @@ -161,21 +164,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 6be5fb1e083d7ff130386dfa181b9a0c8fd5437c..bea0f306ecf641429d03df3f6b1440e5dd80f907 100644 --- a/gcc/config/arm/aarch-common-protos.h +++ b/gcc/config/arm/aarch-common-protos.h @@ -150,4 +150,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.h b/gcc/config/arm/aarch-common.h new file mode 100644 index 0000000000000000000000000000000000000000..486726a61fdaaa54457ad06f663446487a20e701 --- /dev/null +++ b/gcc/config/arm/aarch-common.h @@ -0,0 +1,73 @@ +/* Types shared between arm and aarch64. + + Copyright (C) 1991-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/aarch-common.c b/gcc/config/arm/aarch-common.c index 67343fe40250221c8b791f7776c39a2d2287cc35..26631572a39c543d615f5f7c76eba0387990300f 100644 --- a/gcc/config/arm/aarch-common.c +++ b/gcc/config/arm/aarch-common.c @@ -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; } + +#include "aarch-common.h" + +#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/arm-protos.h b/gcc/config/arm/arm-protos.h index 9b1f61394ad7d778a6c0b84bc6c805f14709f598..463ecdc4f363604a7349aad557cd207fe291458e 100644 --- a/gcc/config/arm/arm-protos.h +++ b/gcc/config/arm/arm-protos.h @@ -577,6 +577,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.c b/gcc/config/arm/arm.c index c4ff06b087ebecc91c419cb4ecf009c3535955df..a952655db80663f28f5a5d12005f2adb4702894f 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -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" @@ -2390,6 +2392,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 a7677eeb45c805d6a314f4d1d2d6063d8c0b687c..5c5b4f3ae0699a3a9d78df40a5ab65324dcba7b9 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 = 2 + Enum Name(tls_type) Type(enum arm_tls_type) TLS dialect to use: