From patchwork Fri Jan 27 14:43:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Corallo X-Patchwork-Id: 49451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp869751wrn; Fri, 27 Jan 2023 06:44:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXsgZ3pimO/2Wd9A0c/0yNTR7UusZC4TzWkuBVEljUz8EOFbUFPfpMJdU3yg7lIxZnFaw9gT X-Received: by 2002:a17:906:8d0f:b0:870:b950:18d4 with SMTP id rv15-20020a1709068d0f00b00870b95018d4mr45660014ejc.5.1674830686508; Fri, 27 Jan 2023 06:44:46 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ma25-20020a1709079f1900b008784df7d93bsi4482843ejc.925.2023.01.27.06.44.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 06:44:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Qt1unADw; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 257933858423 for ; Fri, 27 Jan 2023 14:44:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 257933858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674830685; bh=czV79puObhMWvLtD8lZNzNROi86qU63e7tAcqUxV/kU=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Qt1unADwLcaJkdfCF0axCH/feqtJ/pFFAP4sLMBX7bOHW/qn+5K9uTVMd/qe1R/Bm hU9MeH0iyZY04GAj5tJD03J8LfxHGT8gqBeaaSYm7Dg9+gIq+Eb/SM9nXPkJ3o15h4 WGNccggWQIKa0/J9OkzPhgWntRaZvSlHrOr4xVMI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2056.outbound.protection.outlook.com [40.107.247.56]) by sourceware.org (Postfix) with ESMTPS id C21E53857365 for ; Fri, 27 Jan 2023 14:43:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C21E53857365 Received: from DB3PR06CA0005.eurprd06.prod.outlook.com (2603:10a6:8:1::18) by PAVPR08MB9796.eurprd08.prod.outlook.com (2603:10a6:102:2f8::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23; Fri, 27 Jan 2023 14:43:56 +0000 Received: from DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:8:1:cafe::15) by DB3PR06CA0005.outlook.office365.com (2603:10a6:8:1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23 via Frontend Transport; Fri, 27 Jan 2023 14:43:56 +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 DBAEUR03FT032.mail.protection.outlook.com (100.127.142.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23 via Frontend Transport; Fri, 27 Jan 2023 14:43:56 +0000 Received: ("Tessian outbound b1d3ffe56e73:v132"); Fri, 27 Jan 2023 14:43:53 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 55ea8faa06bb3f9e X-CR-MTA-TID: 64aa7808 Received: from 21dfcb6080c9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 976754D2-6468-4179-9067-3C3C024F9A06.1; Fri, 27 Jan 2023 14:43:44 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 21dfcb6080c9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Jan 2023 14:43:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Om+i7d8FOdQTRQo1OBVArXFpX2ULGtofBjzupngcesJ2uvyTNzHLJHSS+mdxMoI9beYST1kJ43mIvYL7mC7snolksuk5ooRQ8/LhoW/p5WMRAo9VCCrC83QIfi8VjpxlKt71IGwSfjmmnumufVbND2M67HWqNMOFT1MdKp3BlwAFNj1nUGNMiNGW2fNJuDGlkKMr4ZT5ubN+JsvU2m/W6Qbf1vGsGEKBWuhTzzd9cSguDmpEPoojvRipspWTBaJey7P7ldDZoMMGeRvlIqwV7ca5AFUiB271ytqx7T9aF9x4v5Tzgx9PM5LoxcjRcp6f2i7E66x0lDNMqrT8m7QNZQ== 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=czV79puObhMWvLtD8lZNzNROi86qU63e7tAcqUxV/kU=; b=bPDzF9mY/rnOEL6KzRzxaHyClfMZmKuarmApjrrbRbLzDBdi+kDZvaXoh/c9Wkn4Bu4rDhAzLTZ9F2TvNrAChq9EXGdF4r4MOwFfShxsm6vqkaZiO/PBaC7+8w1D8bweC6wDilTqoOQTZzqO6302iqRFsca0+mWLEs9KD8XtgZ8dAaQ9C951aaEpu+fWPUC3Ef60JVqhS+fQ4W2HrHYiPT7zmivnMASuW2J+npybE9e68GIU+/hqFDse9u6wZviIoxi8FCw/oxQugiPc7Zwazq2bAUpUrp0P+BBMCnshdj9JFXR/ZCv9vCSKcIMN40QSQednDMQK31RZq5xJt6AS/A== 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 Received: from DB8PR06CA0041.eurprd06.prod.outlook.com (2603:10a6:10:120::15) by DB9PR08MB6459.eurprd08.prod.outlook.com (2603:10a6:10:256::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23; Fri, 27 Jan 2023 14:43:39 +0000 Received: from DBAEUR03FT004.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:120:cafe::90) by DB8PR06CA0041.outlook.office365.com (2603:10a6:10:120::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.22 via Frontend Transport; Fri, 27 Jan 2023 14:43:39 +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 DBAEUR03FT004.mail.protection.outlook.com (100.127.142.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.21 via Frontend Transport; Fri, 27 Jan 2023 14:43:39 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.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; Fri, 27 Jan 2023 14:43:38 +0000 Received: from e124257.nice.arm.com (10.34.105.24) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 27 Jan 2023 14:43:38 +0000 To: CC: , , Andrea Corallo , Tejas Belagod Subject: [PATCH] arm: Implement arm Function target attribute 'branch-protection' Date: Fri, 27 Jan 2023 15:43:11 +0100 Message-ID: <20230127144311.2188730-1-andrea.corallo@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT004:EE_|DB9PR08MB6459:EE_|DBAEUR03FT032:EE_|PAVPR08MB9796:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e1f6d29-f7b4-4cf2-4df7-08db0074eb33 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: OzvQCk2ihshqiRgYx4RaOLUi8mWrF11jQozNaQBneN6rrF/zlwEhSV3T4hGaPp+hK1WYcRM2f/RAWMik8+Anrs4zgBXou3dQkpa6+OpjNeQRU4bey9JGnxsAb0XDHg0KQFKAahAVpGhzHy0G6i4Uw4akP9LhBrLgeYbTw630K5AQjillKKMD+qJpDGZQTXB6bOF8Sqti89YGA7E6n4VVeQg5M5BaKFqxyZRveBKbOdBNpwZUU6WAbWTpq+kTEQi5k/JoWcib9IxA+WoZIBTz8InRewtfIXJos9ezglWNQdxREEhSNgMrZ/LEh+56mOlg15Q+psi327BPuSg1b6IXZQnyGDnxtZsIgma9jND1UXiML27+iMfEH+yWpeVzD9xQ75MltKh4PU0aGsCfNOqYJX2rekxf5B206fjKcgCAlEEPTPdjOdM9HYGn3V3QBNQN+uEFcnv6D1fofVaPS5PvgLhF6DFOKjlAkfRAn6oNNxQ0PuWOTvFT+N3Jet9ey9Ggnn3uco0JB8n4R60+hL2HlcLfIf1V741TPQTmc7M4nbeNXqxzVqZSKTi7EDua0P6Xhl598CJF/vW4cnd2kND8jlYWGlDiz1b01gTHQdU3W2SkhoIXQoBSRh4HpFiwnX0kz3zapdtAZGlIF7xYOeWnPzb1pVCE7dWeeTkrs1gm7kZpG2TNOBGEgT9QtgLMVNt//tW1bX7XloqT5225WOgeLz5yLPfdRB6QE8NcIoLIEj6gCyynHWmchjLghPHKaWsng6MBGX/Y9CHi8ygTqCzaJQ== 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:(13230025)(4636009)(346002)(376002)(39860400002)(396003)(136003)(451199018)(36840700001)(40470700004)(46966006)(2906002)(44832011)(84970400001)(8936002)(5660300002)(83380400001)(7696005)(86362001)(41300700001)(6666004)(1076003)(8676002)(6916009)(54906003)(70586007)(70206006)(40460700003)(26005)(186003)(478600001)(4326008)(426003)(47076005)(336012)(2616005)(82310400005)(316002)(81166007)(40480700001)(356005)(82740400003)(36756003)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6459 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c094387f-5cb6-4680-e576-08db0074e0d4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mfHSzIs7qljVt/JXG/0bpnOGxnFjmjci12FDeJkQFzntnLJTvLE4A8DGJru6RU6sMLkBuwHXViK7hW05QGOMMDcEqmkCW5sPpaXGgGFfaSsqDrFknVYKrHIK35XO8q/up+VW7NWgS34fKUGoN8BqGwquwjc/MRBvEXrlaDSz9rx88p107tBuNgaskH8oPcnokQ1qq3Q4MbfUZIfIlvMLLfQpW4L1eAO6L0OWN626IJdleS97hGpaUdPWxYx93y5bCoQA+9bdyzSHgZnGS3YX4ZJjNq+IYNlZQUEhma8WVfX+bAISNjsjfBhT9/bJwx+79sol/M7qGKIEsOkWwZHJPz9FFtfcpXTrX0CcrS0NobgmoT9IBD72fAopc0CgJKEbRGUWycti6TzfjlZRsYzEe2gReILJ+J8swPSekEaXRCk/WhiVlYOkIscCkaumNFJWSdcxRUSZ04ehbox3WDets8jK6emc1zhlPpSCFqFss+8yYQddOKv07FmxHi1gJfNBnp53+lap8Cc5Xp4kxFCkb78BP1I4dSRxkmVG+JhxFECR/0WPmIvUqLdj1ICNfJLQCeZQuaTMs3FXiBirk/JAkVAKYMdiHc+xqZyXbZ23OISKm9nCIf58DBdrDSNb3DEDcnR7+Jl9+E1eH5WgYAv2O6EiSAZ1djmP6VTv15yyY4Zf0529xsVQ3Xjz9W88VVY3qDF8uAVBTZ4Vb84sjfqsoKcOvkwz2Inke1XvWDEFchc= 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:(13230025)(4636009)(136003)(39860400002)(396003)(376002)(346002)(451199018)(36840700001)(40470700004)(46966006)(41300700001)(86362001)(478600001)(6666004)(83380400001)(40460700003)(82740400003)(40480700001)(7696005)(2616005)(426003)(47076005)(82310400005)(336012)(1076003)(186003)(4326008)(26005)(6916009)(8676002)(70586007)(54906003)(70206006)(36756003)(316002)(36860700001)(2906002)(44832011)(5660300002)(8936002)(81166007)(84970400001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2023 14:43:56.5115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e1f6d29-f7b4-4cf2-4df7-08db0074eb33 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: DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9796 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, 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 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: Andrea Corallo via Gcc-patches From: Andrea Corallo Reply-To: Andrea Corallo Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756187261639135520?= X-GMAIL-MSGID: =?utf-8?q?1756187261639135520?= gcc/ * config/arm/arm.cc (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-13.c: New test. Co-Authored-By: Tejas Belagod --- gcc/config/arm/arm.cc | 16 ++++++++ gcc/doc/extend.texi | 7 ++++ .../gcc.target/arm/acle/pacbti-m-predef-13.c | 41 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.c diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index efc48349dd3..add33090f18 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -33568,6 +33568,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 4a89a3eae7c..23ee43919dd 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -4492,6 +4492,13 @@ Enable or disable calls to out-of-line helpers to implement atomic operations. This corresponds to the behavior of the command line options @option{-moutline-atomics} and @option{-mno-outline-atomics}. +@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 The above target attributes can be specified as follows: diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.c new file mode 100644 index 00000000000..b6d2df53072 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.c @@ -0,0 +1,41 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target mbranch_protection_ok } */ +/* { dg-options "-march=armv8.1-m.main+fp -mbranch-protection=pac-ret+leaf -mfloat-abi=hard --save-temps" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#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 + +/* +**foo: +** bti +** ... +*/ +__attribute__((target("branch-protection=pac-ret+bti"), noinline)) +int foo () +{ + return 3; +} + +/* +**main: +** pac ip, lr, sp +** ... +** aut ip, lr, sp +** bx lr +*/ +int +main() +{ + return 1 + foo (); +} + +/* { dg-final { scan-assembler "\.eabi_attribute 50, 1" } } */ +/* { dg-final { scan-assembler "\.eabi_attribute 52, 1" } } */ +/* { dg-final { scan-assembler-not "\.eabi_attribute 74" } } */ +/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */