From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2056.outbound.protection.outlook.com [40.107.105.56]) by sourceware.org (Postfix) with ESMTPS id C4B0D385782B for ; Fri, 3 Nov 2023 15:36:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4B0D385782B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4B0D385782B Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.105.56 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1699025822; cv=pass; b=Ye6lFoPTZC0rMBSeQMQgPQw6kY7FHoJcKPl4pxEl89I7KVypDmW4iy9oW5A0Wk/ygMHdD9HsaZjSzIuQ1ZxxoFp+bWc6An27AIITtoMBvr+xaGV/7kEy5BMQT6HQ8e+EbKzGQZQ6YeQAgnwK6W7YkCtWdeYl8m2LbRmjb8NUH+o= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1699025822; c=relaxed/simple; bh=5PgI3H4QW0RibeMgDjtKrTxngfhu5Y2oZEmRNWop8ts=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=gSEPajaWSlf3bC99n7YSsLOkTpn5LIAS0Nfh0HZpE7wCiRDL8ddQz2B3KqqRFJLAbFsgvCa3wJZ51TAJ+n5twJgHqS1Zmg+edyDNPZedPuKdIEpKj89wiy9hywtsLjgBMoTCHah+s5kBi8D6OhlTGkIv/onCVMG814oamihP34g= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Q5BoUh+vU5hctZto3FznJ8tX5y1qh8qGOX4NjBePyr4J4eiqSiR2o32IFRNdK0uRlPh6wyhVkX3GT6ir8WUwjGzMbaLo+kI/x+Hm0Xg90X6NXTvPGO9+0lodqTns1SrYKt8vgTTIreGOWFP75cWLQZjmiBvjbBokDXwOzx6EsskTmeWAsurjqid1lkz+1+smr/Lt/Xujbdvh5uNFXwBw8LuVpR8yebuX984pRqSbtuPdM3aG9C0Oyyd+8Dos8LBWUtv4ewIa1mouAhdoX2Wy/UOizFbJnM5szXB2cA1TqcneHJ8RRRn2V7IQEDOUK+PHDm2HLUYYtMyzxK+xgHrskw== ARC-Message-Signature: i=2; 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=DaC2dKVG1B1Uu3gP8j0Hg/TbL/0dwxW1hKXjK3eJCAw=; b=BTQEw06a6Nv56ZHcnkPGoNuafKMWf/kr43eTWM2OjYJuQDuceno17fb7n4g+1KIFGVJuRQmYuE6wwGYvSW3+6tZCwCrsdOs8PXKI/BR7ovz9qfctHrV83fQNxL8VG2zmHyG2lY1iCsv5x0AY6Pq7JqMe6b6l4ZGS96Npn+bFXienlyuID3OaE1Rqxbx77CooXU407UdNvj8Lgx6V+wK6iI4Z8x/Tj2pQw+l65pobIV2MmAzqJwCLhug0n3iiZeNYeARUQqfsgA0Leffg+oXZozp7eB2o91o+xs/fdvdm/Pjbu4ojDjXkyw9d04MEPrNe38F3WicLpEuI2EY5jV3oHg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=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=DaC2dKVG1B1Uu3gP8j0Hg/TbL/0dwxW1hKXjK3eJCAw=; b=B6JdcBSEdntq+9Dh7Y/Va1hV87avOUNswVAsvw+hok5vO9F+vjZI8cKEJ4+UH39qKBa4TTPHo05sZ6BsOwbg9KxkLB+Trlow5CxDgIVH1KStGdP3U9zczIEhQSXQ4rZ0ITJA25UEzDVw9vvR9DSDIhbKSpeuxn7h/7X31u3viFU= Received: from DB8PR06CA0039.eurprd06.prod.outlook.com (2603:10a6:10:120::13) by AS8PR08MB9362.eurprd08.prod.outlook.com (2603:10a6:20b:5a9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.21; Fri, 3 Nov 2023 15:36:49 +0000 Received: from DU6PEPF0000B622.eurprd02.prod.outlook.com (2603:10a6:10:120:cafe::7) by DB8PR06CA0039.outlook.office365.com (2603:10a6:10:120::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.29 via Frontend Transport; Fri, 3 Nov 2023 15:36:49 +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 DU6PEPF0000B622.mail.protection.outlook.com (10.167.8.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Fri, 3 Nov 2023 15:36:49 +0000 Received: ("Tessian outbound 7c4ecdadb9e7:v228"); Fri, 03 Nov 2023 15:36:48 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 312157a517788791 X-CR-MTA-TID: 64aa7808 Received: from c302e2a62c7c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3C3389C7-32BE-443C-B47A-FB59C0F03BD8.1; Fri, 03 Nov 2023 15:36:42 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c302e2a62c7c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 03 Nov 2023 15:36:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=foKzqFwCG/TAABqOE8J25C2iMJg0HRRPFixhcrgMRfMmQaxXnxjSt+BsZoiB96Y541EMQo/vlD6epx+p8g94zmEQmlBR5Xomjyut3lrGNvLnqMaR8FbznjgPDRVBB/uv0XgsFUSWvS0yErtPccITV4+PnWuGYdB+8Ftw3uftUz9T38m4PKbV1MBby2/OHp129rpU3KR04KtJYMR/HZMbBarhD4rb78uvijEsfPUFMb33TI8kqGFJfTYaGrxvd1x73a1w/zHK6uDO5DInVfJbTJxTSc0aM8aIxCgLTXag5XSkF1++sf+zC3CsKjPhOpjb/wTsIuMoUphbcj7dcFaTSw== 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=DaC2dKVG1B1Uu3gP8j0Hg/TbL/0dwxW1hKXjK3eJCAw=; b=efRfonIEfqMzyXCQBHowEC+YSxB9gbXGAAmEraJJ8+hJ12Okz6fMAFUquk4Xgy8aC8zgMUS5VRspK3Xm99CigsxraXb36L9Pzj5ei6q3A5gbf7lU6Mi4cdOty1ustTKfXDVUqtDzCYi+8jXtBlbpJw+WEdxGsUDzt2toRy5Wdro7YdjksQIJFPdDlOyxIgvM5DMV7F2v7tn6QxXwDEHmP9BeEFyygmkpYlIWL9n1v/C5uq0gLfciVNy4nJPQT9TiXewH5MqrK0afACRGw+nh1W2yeDBBQGDt3dT+c4btp+GE1W3qxzfhwnfMaenr3XCmH6HGgAK2ioLBQ/qApWYrsA== 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 (0) 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=DaC2dKVG1B1Uu3gP8j0Hg/TbL/0dwxW1hKXjK3eJCAw=; b=B6JdcBSEdntq+9Dh7Y/Va1hV87avOUNswVAsvw+hok5vO9F+vjZI8cKEJ4+UH39qKBa4TTPHo05sZ6BsOwbg9KxkLB+Trlow5CxDgIVH1KStGdP3U9zczIEhQSXQ4rZ0ITJA25UEzDVw9vvR9DSDIhbKSpeuxn7h/7X31u3viFU= Received: from AM6P194CA0011.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::24) by DB9PR08MB9849.eurprd08.prod.outlook.com (2603:10a6:10:462::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.21; Fri, 3 Nov 2023 15:36:39 +0000 Received: from AMS0EPF000001B1.eurprd05.prod.outlook.com (2603:10a6:209:90:cafe::98) by AM6P194CA0011.outlook.office365.com (2603:10a6:209:90::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.22 via Frontend Transport; Fri, 3 Nov 2023 15:36: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 AMS0EPF000001B1.mail.protection.outlook.com (10.167.16.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6954.19 via Frontend Transport; Fri, 3 Nov 2023 15:36:39 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) 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.32; Fri, 3 Nov 2023 15:36:38 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.32 via Frontend Transport; Fri, 3 Nov 2023 15:36:38 +0000 From: Szabolcs Nagy To: Subject: [PATCH v2 6/7] aarch64,arm: Fix branch-protection= parsing Date: Fri, 3 Nov 2023 15:36:38 +0000 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AMS0EPF000001B1:EE_|DB9PR08MB9849:EE_|DU6PEPF0000B622:EE_|AS8PR08MB9362:EE_ X-MS-Office365-Filtering-Correlation-Id: 0313f8db-d678-4fe6-4cff-08dbdc82b1cf 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: Dyqz8PKrFfoa/KlxBDXefofZ4+jU73Q+A/uApu3AkUhVxUuYTFKHXxahSC4YhZnj6vUk//ZXAm72lcetMuybl/LqZxaVQ53ag495nuJVqRKbWA9VUQlN5/uGQku8crqfYhv+yVJm9f//4SncZ+uzCmFkxPg3EqnWRGqCsNJpwfjc2PGB4ESgVbS6zSB7RXa5Uw4F8s/P5BdfTpzVCYfUTntpXjbPp92FcIg9+F0KMfGiXeMJixHVW5TkUFxv3MzXooDWz0J2NhahHuzrr24s9GRv8uZ7lseb/0YnI2Q8FJMelkBR5MRkuQy0OtYCJd2CBZtUUsFskrVXIhZsWv0qbpX15uRCwGpcXAXHRYRUU8cCbpSjdYoHsegvW+IdZMR45ffrOO6BxPe+LMi9z2QlzBGHxxp8vmXMZC6E//9DOfBhe9LiiNNQ1e8/azdDasWLrq5buutgamVHOYKSdoImZUTugLcMErwQPPYuAOIV0NMx74fbYdXW1MICqaWeOn3m68J3ntwqitBFByL6BVc7QxZWlhJrPtS3lhFEfEiwA1mdzj8RXhX8EWvgYpiGF42zHd6kHtwMhEPwe31FinqAj9QiwE7z4Mw4pfGtqUg4Tb4sk4YVSgQ4EfvN4tKkrO5TJoUbndF0O26KIWBxNn7nzAR4otQu9g3sexv22VRLiBH4Y0eaz2a1Yd5c8e5ILa64a2J9Z5zeTKffyHFCVFLF6dY1zocgH10F6+7/d9l95nz/aD5Hmf506LAU13PrZIGfjxbKRj4xhMce+oLTU2+TZe19gWKncpjtoFj2r6cjeNo= 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:(13230031)(4636009)(39860400002)(136003)(346002)(376002)(396003)(230922051799003)(451199024)(64100799003)(1800799009)(82310400011)(186009)(36840700001)(40470700004)(46966006)(40480700001)(40460700003)(26005)(2616005)(7696005)(47076005)(36860700001)(83380400001)(2906002)(336012)(426003)(478600001)(8676002)(30864003)(41300700001)(70586007)(44832011)(5660300002)(966005)(70206006)(316002)(6916009)(8936002)(36756003)(81166007)(356005)(82740400003)(86362001)(84970400001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB9849 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU6PEPF0000B622.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 41a01b01-d031-4a3a-47b1-08dbdc82ac2a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 49HNORHSzX6NS3shbk8z/O3vqVfr4OGGsucLyHaBYxIFN0yDj5nHfiJL25DOsSux1tgOGrNmGIORfFnM6a0SJPTHpowXUGonmU65LL5K5rI6JKZbx27ONh1mU6E2533hyej0Kry852yLivnw8OE+jmP4HWKM47b2KioB4qd+9L1v3CPfi62GfGJrlJizSUe4IDOHQA/SIiHq5J8HmfDq9PuxhWfYhgDyUlxhPJ6bzp7WWkKSEePspnVUc1ld27LTXzwrM/u5beoFHlZEuy68gJMV4GLlltrE0orS5cs/PneyvM0SSLySvKiTwPWN+9nt0f3kd+H3saNQjwAAtmAh4FTIRrgpJjXHJOCacdA7B0FxQjBlyZdXCwgEyFXw7BUVz2RFZVJV4g82NEjtzj4546cw7fGa1NIfsEZkmyKEI9f4LcxK296eLCnOklmvg70ZE8hHvZgISgkiuY98a178VtYlKkn4AFDvDeBA6yL2jOhGfyP67UjNT/aHNaR4ZTt9T2j/4MIIG3jXqzUPCbI7jY01mWieA6ZwEZ++kEkxpoN0MWQHF+CKQ3yn/c5O9AzGl+K316XeWAf/imdbpTmOBYeVsI2bZhIFaZzH6ovXxJjgkJOzymp88xGcbPtDshKorO6AubLBL7FDNmNeBEbVZglSUsj4bfD3Vt4jeZHVw7Yva51lM+cfsZIbX8nph0bvHWxuXEN0bNLMrUZjZuuQel6nRR9aDz9USsw8mHWsIfrWV5xhVnAgQhMuc44acZsgwYTkuaEFRzS1RUGcvL603g== 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:(13230031)(4636009)(136003)(396003)(376002)(346002)(39860400002)(230922051799003)(64100799003)(451199024)(82310400011)(186009)(1800799009)(40470700004)(36840700001)(46966006)(8676002)(966005)(40460700003)(2906002)(478600001)(2616005)(26005)(426003)(336012)(82740400003)(86362001)(81166007)(83380400001)(47076005)(36756003)(36860700001)(40480700001)(7696005)(5660300002)(6916009)(316002)(70206006)(41300700001)(84970400001)(70586007)(44832011)(30864003)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2023 15:36:49.0069 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0313f8db-d678-4fe6-4cff-08dbdc82b1cf 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: DU6PEPF0000B622.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9362 X-Spam-Status: No, score=-11.5 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,T_SCC_BODY_TEXT_LINE,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: Refactor the parsing to have a single API and fix a few parsing issues: - Different handling of "bti+none" and "none+bti": these should be rejected because "none" can only appear alone. - Accepted empty strings such as "bti++pac-ret" or "bti+", this bug was caused by using strtok_r. - Memory got leaked (str_root was never freed). And two buffers got allocated when one is enough. The callbacks now have no failure mode, only parsing can fail and all failures are handled locally. The "-mbranch-protection=" vs "target("branch-protection=")" difference in the error message is handled by a separate argument to aarch_validate_mbranch_protection. gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_override_options): Update. (aarch64_handle_attr_branch_protection): Update. * config/arm/aarch-common-protos.h (aarch_parse_branch_protection): Remove. (aarch_validate_mbranch_protection): Add new argument. * config/arm/aarch-common.cc (aarch_handle_no_branch_protection): Update. (aarch_handle_standard_branch_protection): Update. (aarch_handle_pac_ret_protection): Update. (aarch_handle_pac_ret_leaf): Update. (aarch_handle_pac_ret_b_key): Update. (aarch_handle_bti_protection): Update. (aarch_parse_branch_protection): Remove. (next_tok): New. (aarch_validate_mbranch_protection): Rewrite. * config/arm/aarch-common.h (struct aarch_branch_protect_type): Add field "alone". * config/arm/arm.cc (arm_configure_build_target): Update. gcc/testsuite/ChangeLog: * gcc.target/aarch64/branch-protection-attr.c: Update. * gcc.target/aarch64/branch-protection-option.c: Update. --- v2: merge tests updates into the patch error message is not changed, see previous discussion: https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633945.html --- gcc/config/aarch64/aarch64.cc | 37 +-- gcc/config/arm/aarch-common-protos.h | 5 +- gcc/config/arm/aarch-common.cc | 214 ++++++++---------- gcc/config/arm/aarch-common.h | 14 +- gcc/config/arm/arm.cc | 3 +- .../aarch64/branch-protection-attr.c | 6 +- .../aarch64/branch-protection-option.c | 2 +- 7 files changed, 113 insertions(+), 168 deletions(-) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index f8e8fefc8d8..4f7f707b675 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -18642,7 +18642,8 @@ aarch64_override_options (void) aarch64_validate_sls_mitigation (aarch64_harden_sls_string); if (aarch64_branch_protection_string) - aarch_validate_mbranch_protection (aarch64_branch_protection_string); + aarch_validate_mbranch_protection (aarch64_branch_protection_string, + "-mbranch-protection="); /* -mcpu=CPU is shorthand for -march=ARCH_FOR_CPU, -mtune=CPU. If either of -march or -mtune is given, they override their @@ -19016,34 +19017,12 @@ aarch64_handle_attr_cpu (const char *str) /* Handle the argument STR to the branch-protection= attribute. */ - static bool - aarch64_handle_attr_branch_protection (const char* str) - { - char *err_str = (char *) xmalloc (strlen (str) + 1); - enum aarch_parse_opt_result res = aarch_parse_branch_protection (str, - &err_str); - bool success = false; - switch (res) - { - case AARCH_PARSE_MISSING_ARG: - error ("missing argument to % pragma or" - " attribute"); - break; - case AARCH_PARSE_INVALID_ARG: - error ("invalid protection type %qs in % pragma or attribute", err_str); - break; - case AARCH_PARSE_OK: - success = true; - /* Fall through. */ - case AARCH_PARSE_INVALID_FEATURE: - break; - default: - gcc_unreachable (); - } - free (err_str); - return success; - } +static bool +aarch64_handle_attr_branch_protection (const char* str) +{ + return aarch_validate_mbranch_protection (str, + "target(\"branch-protection=\")"); +} /* Handle the argument STR to the tune= target attribute. */ diff --git a/gcc/config/arm/aarch-common-protos.h b/gcc/config/arm/aarch-common-protos.h index f8cb6562096..75ffdfbb050 100644 --- a/gcc/config/arm/aarch-common-protos.h +++ b/gcc/config/arm/aarch-common-protos.h @@ -159,10 +159,7 @@ 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 *); +bool aarch_validate_mbranch_protection (const char *, 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 cbc7f68a8bf..159c61b786c 100644 --- a/gcc/config/arm/aarch-common.cc +++ b/gcc/config/arm/aarch-common.cc @@ -659,169 +659,143 @@ arm_md_asm_adjust (vec &outputs, vec & /*inputs*/, return saw_asm_flag ? seq : NULL; } -static enum aarch_parse_opt_result -aarch_handle_no_branch_protection (char* str, char* rest) +static void +aarch_handle_no_branch_protection (void) { 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) +static void +aarch_handle_standard_branch_protection (void) { 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) +static void +aarch_handle_pac_ret_protection (void) { 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) +static void +aarch_handle_pac_ret_leaf (void) { 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) +static void +aarch_handle_pac_ret_b_key (void) { 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) +static void +aarch_handle_bti_protection (void) { 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 } + { "leaf", false, aarch_handle_pac_ret_leaf, NULL, 0 }, + { "b-key", false, aarch_handle_pac_ret_b_key, NULL, 0 }, + { NULL, false, 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, + { "none", true, aarch_handle_no_branch_protection, NULL, 0 }, + { "standard", true, aarch_handle_standard_branch_protection, NULL, 0 }, + { "pac-ret", false, 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 } + { "bti", false, aarch_handle_bti_protection, NULL, 0 }, + { NULL, false, 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. */ +/* In-place split *str at delim, return *str and set *str to the tail + of the string or NULL if the end is reached. */ -enum aarch_parse_opt_result -aarch_parse_branch_protection (const char *const_str, char** last_str) +static char * +next_tok (char **str, int delim) { - 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 *tok = *str; + for (char *p = tok; p && *p != '\0'; p++) { - 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) + if (*p == delim) { - 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; + *p = '\0'; + *str = p + 1; + return tok; } } - /* 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; - } - return res; + *str = NULL; + return tok; } +/* Parses CONST_STR for branch protection features specified in + aarch64_branch_protect_types, and set any global variables required. + Returns true on success. */ + bool -aarch_validate_mbranch_protection (const char *const_str) +aarch_validate_mbranch_protection (const char *const_str, const char *opt) { - 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; + char *str_root = xstrdup (const_str); + char *next_str = str_root; + char *str = next_tok (&next_str, '+'); + char *alone_str = NULL; + bool reject_alone = false; + bool res = true; + + /* First entry is "none" and it is used to reset the state. */ + aarch_branch_protect_types[0].handler (); + + while (str) + { + const aarch_branch_protect_type *type = aarch_branch_protect_types; + for (; type->name; type++) + if (strcmp (str, type->name) == 0) + break; + if (type->name == NULL) + { + res = false; + error ("invalid argument %<%s%> for %<%s%>", str, opt); + break; + } + + if (type->alone && alone_str == NULL) + alone_str = str; + else + reject_alone = true; + if (reject_alone && alone_str != NULL) + { + res = false; + error ("argument %<%s%> can only appear alone in %<%s%>", + alone_str, opt); + break; + } + + type->handler (); + str = next_tok (&next_str, '+'); + if (type->subtypes == NULL) + continue; + + /* Loop through tokens until we find one that isn't a subtype. */ + while (str) + { + const aarch_branch_protect_type *subtype = type->subtypes; + for (; subtype->name; subtype++) + if (strcmp (str, subtype->name) == 0) + break; + if (subtype->name == NULL) + break; + + subtype->handler (); + str = next_tok (&next_str, '+'); + } + } + + free (str_root); + return res; } diff --git a/gcc/config/arm/aarch-common.h b/gcc/config/arm/aarch-common.h index c6a67f0d05c..f72e21127fc 100644 --- a/gcc/config/arm/aarch-common.h +++ b/gcc/config/arm/aarch-common.h @@ -55,16 +55,10 @@ 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*); + /* The type can only appear alone, other types should be rejected. */ + int alone; + /* Function to handle the protection type and set global variables. */ + void (*handler)(void); /* A list of types that can follow this type in the option string. */ const struct aarch_branch_protect_type* subtypes; unsigned int num_subtypes; diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index f49312cace0..5681073a948 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -3297,7 +3297,8 @@ arm_configure_build_target (struct arm_build_target *target, if (opts->x_arm_branch_protection_string) { - aarch_validate_mbranch_protection (opts->x_arm_branch_protection_string); + aarch_validate_mbranch_protection (opts->x_arm_branch_protection_string, + "-mbranch-protection="); if (aarch_ra_sign_key != AARCH_KEY_A) { diff --git a/gcc/testsuite/gcc.target/aarch64/branch-protection-attr.c b/gcc/testsuite/gcc.target/aarch64/branch-protection-attr.c index 272000c2747..dae2a758a56 100644 --- a/gcc/testsuite/gcc.target/aarch64/branch-protection-attr.c +++ b/gcc/testsuite/gcc.target/aarch64/branch-protection-attr.c @@ -4,19 +4,19 @@ void __attribute__ ((target("branch-protection=leaf"))) foo1 () { } -/* { dg-error {invalid protection type 'leaf' in 'target\("branch-protection="\)' pragma or attribute} "" { target *-*-* } 5 } */ +/* { dg-error {invalid argument 'leaf' for 'target\("branch-protection="\)'} "" { target *-*-* } 5 } */ /* { dg-error {pragma or attribute 'target\("branch-protection=leaf"\)' is not valid} "" { target *-*-* } 5 } */ void __attribute__ ((target("branch-protection=none+pac-ret"))) foo2 () { } -/* { dg-error "unexpected 'pac-ret' after 'none'" "" { target *-*-* } 12 } */ +/* { dg-error {argument 'none' can only appear alone in 'target\("branch-protection="\)'} "" { target *-*-* } 12 } */ /* { dg-error {pragma or attribute 'target\("branch-protection=none\+pac-ret"\)' is not valid} "" { target *-*-* } 12 } */ void __attribute__ ((target("branch-protection="))) foo3 () { } -/* { dg-error {missing argument to 'target\("branch-protection="\)' pragma or attribute} "" { target *-*-* } 19 } */ +/* { dg-error {invalid argument '' for 'target\("branch-protection="\)'} "" { target *-*-* } 19 } */ /* { dg-error {pragma or attribute 'target\("branch-protection="\)' is not valid} "" { target *-*-* } 19 } */ diff --git a/gcc/testsuite/gcc.target/aarch64/branch-protection-option.c b/gcc/testsuite/gcc.target/aarch64/branch-protection-option.c index 1b3bf4ee2b8..e2f847a31c4 100644 --- a/gcc/testsuite/gcc.target/aarch64/branch-protection-option.c +++ b/gcc/testsuite/gcc.target/aarch64/branch-protection-option.c @@ -1,4 +1,4 @@ /* { dg-do "compile" } */ /* { dg-options "-mbranch-protection=leaf -mbranch-protection=none+pac-ret" } */ -/* { dg-error "unexpected 'pac-ret' after 'none'" "" { target *-*-* } 0 } */ +/* { dg-error "argument 'none' can only appear alone in '-mbranch-protection='" "" { target *-*-* } 0 } */ -- 2.25.1