From patchwork Fri Nov 12 11:23:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejas Belagod X-Patchwork-Id: 47514 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 324BD3858420 for ; Fri, 12 Nov 2021 11:24:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 324BD3858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636716249; bh=/WczVDG+QwtoyzpnKima3Eos0eiAI73PUmPY1y1gy5o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=D0HftHA1WRumCkONcxt+kyqmk8D2AgYurI6uhYle56ylfjhdTzUVGfwIOdNeEzDe9 66fNuwQ1uWgbgVzFOvLnq1QNHU/2zIef0leKTmhSIiB3mzlYFPEoqXpTZH/+oeG4Hp lXQ7iKpRHQbaN7JWeUvHNlJwg6Qq1FAdfIPhyV2s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50067.outbound.protection.outlook.com [40.107.5.67]) by sourceware.org (Postfix) with ESMTPS id 09FD53858402 for ; Fri, 12 Nov 2021 11:23:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 09FD53858402 Received: from AS8P189CA0001.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:31f::10) by AM6PR08MB3544.eurprd08.prod.outlook.com (2603:10a6:20b:4e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.19; Fri, 12 Nov 2021 11:23:36 +0000 Received: from AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:31f:cafe::3) by AS8P189CA0001.outlook.office365.com (2603:10a6:20b:31f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Fri, 12 Nov 2021 11:23:35 +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 AM5EUR03FT027.mail.protection.outlook.com (10.152.16.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.20 via Frontend Transport; Fri, 12 Nov 2021 11:23:35 +0000 Received: ("Tessian outbound 798acf5fb8aa:v109"); Fri, 12 Nov 2021 11:23:35 +0000 X-CR-MTA-TID: 64aa7808 Received: from 8807347bba12.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 29F5A71F-73B0-4550-9EBE-1E3FA37521A8.1; Fri, 12 Nov 2021 11:23:29 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8807347bba12.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 12 Nov 2021 11:23:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZhII2vrHBKoRxIcD0oQ+Sfo3QCBRGzxxhoIjWGIi+tTwVMCqkGQn3F6m0iHHnj/bVFhhKLBoSc214dgUltYdhzm6dM6HBlKsOvrT6Z01BzIzJDT5egRwtrhvXSWKRpACWhcF9XTXs9EKH9H7KzuHu54kga4dVn8X8yohbD8+CgyNUk8t+FCQLnDfk4PBRbt6E2JfyjrTv5Expzkm/8lVXHLtl3HRHhdnoWIJYfSaR2y1GP4wajkTt5J0Xaqh5qzZWhYWPdQj7FMquE0ysLIN6f4Uv4oznv4/HXLWzxnIvc2/CO7ukillYhAs+xflUGeIlPHC/GVzHA1XJ9GR2WKvEw== 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=/WczVDG+QwtoyzpnKima3Eos0eiAI73PUmPY1y1gy5o=; b=A3/XKSK56ubPRiMnRiGek/w1qyEQolanJ/3zBXHir3lAhFjS/bJaDdlnhUeYsUlVCEvxzwsnlUv5/2ZvkLK5IZGJk8x/NDI62Vmjq/ySoox2e/3XvM8bmyGHkKvZbtTzSOWBVuUIP9H+A9p6T3wsWx+hOp9KvZc/1e6iKHpTqx/YnPXm4Wd4i2qx6kr1iI7lponGfctZCL2y2aFaC5Fi5QcyE8u67Rqy+4esXmo4vGQnxE4Z8V/eRXq+fz5DqX87sWIZjJ+Xx/z+qmZXxs06BU5OP5rjrHYn+LNkcO7vvmO2cJ/Msn7TrwWaq4WwWgX0tVIqPuHNSDBjEj2jhi/HzA== 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 AS8PR08MB7079.eurprd08.prod.outlook.com (2603:10a6:20b:400::12) by AS8PR08MB7251.eurprd08.prod.outlook.com (2603:10a6:20b:342::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.19; Fri, 12 Nov 2021 11:23:28 +0000 Received: from AS8PR08MB7079.eurprd08.prod.outlook.com ([fe80::97a:a0e4:84c3:144c]) by AS8PR08MB7079.eurprd08.prod.outlook.com ([fe80::97a:a0e4:84c3:144c%5]) with mapi id 15.20.4690.026; Fri, 12 Nov 2021 11:23:28 +0000 To: "gcc-patches@gcc.gnu.org" Subject: [Patch 9/9, GCC, Arm] Implement arm Function target attribute 'branch-protection'. Thread-Topic: [Patch 9/9, GCC, Arm] Implement arm Function target attribute 'branch-protection'. Thread-Index: AdfXtkyZ7oBCcElgRlC0E1bdz+dtmw== Date: Fri, 12 Nov 2021 11:23:27 +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: 6F57A89D574F3442BB9D583050604BEB.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: 564fa42f-c09e-45d1-359a-08d9a5cede26 x-ms-traffictypediagnostic: AS8PR08MB7251:|AM6PR08MB3544: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:8882;OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: mrSOuQE67PXDxuKEPqz6eArd7VQDh5OL6sYqsYRnQRygmE5m+7GgWpzzqmtswtiQ2Te6QD7Hrp5r1QZnec0xlufZziA51CLOJam4VwDeH0wQGjv6CjbNFE/wJL5B0rzn1rT8ucybvf/r4ByJ7QQRmUZzfwYliEfBjdwpDGRWJNbUoq+GEwTODVh6pqKdhLWWChWEXxG9ddcOIVmZnO2eynNamVEs6wWZ/zgiZU3iYQnAP1RE18jv+s7FrHosk5QD7KUmkQS2Oh+OgbfVfX7NYj6iHhwE8qd3XUsQD1sSqHnaLHjAUZZ67wr6+0lLuPWkGKcVibEDRq/KK1ThVORq3S9e7Jxh9robG/v1AnYTwEGO0D+bRoJh9Hrvkev3GO7T4Y8nXIeeUTkBH6ybw3+Rk24zo0aE1bXbEm409P0wpmtzm5GcGTbFvhwGBnD7F8HiFFkQlGjt8Ign+TwnGU6Cz9lFPzy3YLf2TLbs8EgLSaTHaqKcpZhyseyF4qBgvO/WEMAMzWm+Ms4xYUE0D0VmZZ7iSQytWotZIDnUyL46YqFw/PHY+iMGTnJ3gYLLX0KNk+mFGdfwbgNxPVnqCQz5WQoigcem2jZi/MpJYTJSYzHCUTdp6+mWqL99V4JiJReERgXAruQ8rvwBgf+upY5XUSp57h2CycbtMXgYBRdcsaCoY9M3Z74LcZBNEP7aVHO/tPEkPB8rCvkZLqdfB0xl5I9CG0p+NyAPbQTCK/eZy/C2jP5kC/6mtFV5ORrT/UT9bxAsgA2GhAMnW81fhlmUMzbIjbJ5ZyJCOCovTwr0I3kXXC5/aRGxxVICQO74ZYdyFAt6gwt9ImQEPnRDleMLOQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7079.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(66946007)(316002)(4326008)(4001150100001)(76116006)(6506007)(55016002)(5660300002)(99936003)(6916009)(66476007)(71200400001)(66556008)(26005)(52536014)(66446008)(9686003)(7696005)(122000001)(8676002)(8936002)(64756008)(186003)(86362001)(33656002)(38070700005)(4744005)(508600001)(2906002)(38100700002)(966005); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7251 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: AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 384368b4-e4f3-4b35-f812-08d9a5ced986 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pnN3s3T+sKREADcIci82geqTrdor4yGVW2nF8GFGsM35SIgVIzaUCJRbx8sDRdwDuSTKIfpG/ZMeDvN0dHFlb6GXv2srbCnbpDWoiwdisu3QgWitDsHapoGcqnTIkZJmCCQdGICmaVnrUHssZRTkkFbNwGCb0oMvb6r7ak/y7/I9OcpZSfm8RzmL2jLsGYILeqLfPaeyp83pRWADtEcIYRhmgbC3vS4SLgfCeubp2P/yHXyTpalgPZacrqNnzu/05/Ar8QduHr41M/a3+kzRSOGQ618b1RUX+3VgTBuk+b0m4bv1VGOv5iGrjdZusn04wZswjQzRiJ1zjTO26qS/2njiEqNz4Q+HfFRR4r8ANxIUzbD71WvvyL+qFux4k/ziNiaw28WypzrhFBp7VjoPcCCbT3/5s+lFyjiDunnaGjAw2bq3gEJ/tGrSxjK64BtlQQ4TxLVL6d1F8rTcI2ektzofYFcZ58Qur64/o7yb4oVxfGbm8BJ/5eQWzyX0/TW+pQVgigB2DC0CV2/mxI09haFFYYDOMyWb5Sx2ni2tBE6RTazyVPvFD3bIhYMUymxg69GLrDGCCvzRi+Xip2j9F8v3Y3tJ4DD3I+yIbzzZxW2VOOsy8MTSFmvlv2RKaBwd4f0FQ/AK491iQeFqGcYX5as46GBRRkrHEeRpXRBttarYectR+CTsiNybhnFKFyj28i4/BMscZ2nYLDcfdMSziKXJOdW/GKsefILd6VUj3NGrLinB1JhW+jQ6uGUE+O8MH8puYZfcHxbqNrCwsJHTFyh0caNOFjUurk0sZNY8qY9+vu5E+DA10NUAn0Cb1kMqRm6CLEzOXXQ6ajDmeDFZpA== 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)(46966006)(36840700001)(356005)(26005)(966005)(55016002)(7696005)(186003)(8936002)(6506007)(86362001)(2906002)(508600001)(4001150100001)(316002)(70206006)(70586007)(9686003)(21480400003)(5660300002)(81166007)(6916009)(4326008)(33656002)(99936003)(8676002)(52536014)(36860700001)(47076005)(82310400003)(235185007)(336012); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 11:23:35.7988 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 564fa42f-c09e-45d1-359a-08d9a5cede26 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: AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3544 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, 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 Cc: Richard Earnshaw Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch is part of the series of PACBTI-M patches posted earlier https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582773.html This change adds the target function attribute 'branch-protection'. The options that it can take are the same the command-line option 'mbranch-protection'. The function attribute options override the command- line options for the function scope. Regression tested for arm-none-eabi. OK for trunk? 2021-11-11 Tejas Belagod gcc/ChangeLog: * config/arm/arm.c (arm_valid_target_attribute_rec): Add ARM function attribute 'branch-protection' and parse its options. * doc/extend.texi: Document ARM Function attribute 'branch-protection'. gcc/testsuite/ * gcc.target/arm/acle/pacbti-m-predef-7.c: New test. Thanks, Tejas. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index a87bcb298f9e6d7b2f3fd61b4586e291f46b0f81..64253f3814786b302f8fea573fdfc4213da439ce 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -33147,6 +33147,22 @@ arm_valid_target_attribute_rec (tree args, struct gcc_options *opts) opts->x_arm_arch_string = xstrndup (arch, strlen (arch)); } + else if (startswith (q, "branch-protection=")) + { + char *bp_str = q + strlen ("branch-protection="); + + opts->x_arm_branch_protection_string + = xstrndup (bp_str, strlen (bp_str)); + + /* Capture values from target attribute. */ + aarch_validate_mbranch_protection + (opts->x_arm_branch_protection_string); + + /* Init function target attr values. */ + opts->x_aarch_ra_sign_scope = aarch_ra_sign_scope; + opts->x_aarch_enable_bti = aarch_enable_bti; + + } else if (q[0] == '+') { opts->x_arm_arch_string diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index eee4c6737bbfa9529fd613a0197d513121d058ec..c605adf665754804735e244006fb39f02705c74e 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -4767,6 +4767,12 @@ In this example @code{target("+crc+nocrypto")} enables the @code{crc} extension and disables the @code{crypto} extension for the function @code{foo} without modifying an existing @option{-march=} or @option{-mcpu} option. +@item branch-protection= +@cindex @code{branch-protection=} function attribute, arm +Select the function scope on which branch protection will be applied. The +behavior and permissible arguments are the same as for the command-line option +@option{-mbranch-protection=}. The default value is @code{none}. + @end table @end table diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c new file mode 100644 index 0000000000000000000000000000000000000000..ccf3e1cb9ae6cbed77844142e94641548b75c918 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c @@ -0,0 +1,30 @@ +/* { dg-do run } */ +/* { dg-require-effective-target arm_pacbti_hw } */ +/* { dg-additional-options " -mbranch-protection=pac-ret+leaf --save-temps" } */ + +/* { dg-final { scan-assembler "\.eabi_attribute 50, 2" } } */ +/* { dg-final { scan-assembler "\.eabi_attribute 52, 2" } } */ +/* { dg-final { scan-assembler "\.eabi_attribute 74, 0" } } */ +/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */ + +#if defined (__ARM_FEATURE_BTI_DEFAULT) +#error "Feature test macro __ARM_FEATURE_BTI_DEFAULT should be undefined." +#endif + +#if !defined (__ARM_FEATURE_PAC_DEFAULT) +#error "Feature test macro __ARM_FEATURE_PAC_DEFAULT should be defined." +#endif + +__attribute__((target("branch-protection=pac-ret+bti"), noinline)) +void foo () +{ + if (__ARM_FEATURE_PAC_DEFAULT != 5) + __builtin_abort (); +} + +int +main() +{ + foo (); + return 0; +}