From patchwork Thu Jan 16 11:15:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1224158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-517506-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=Ad/bomkB; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=s6I/dVn3; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=s6I/dVn3; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47z1pL3Xk9z9sP3 for ; Thu, 16 Jan 2020 22:15:53 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=XbhVVbGvlTE06BIT5HPPjO6cj85EkDVXnc1qzyfAu8T9XLrSCE SkrhJvaN5pY3yUdxilbaEf7/970I3Jn1UV0zjV+ApQDo7MmYNEc/r0HrG3Pv5flZ iDDptfSlS8BHNyR6WykgDtKYSZxPKm/0v7hESd4LcwekRM5HvzLo/mrA8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=kuoy9rv6aUlfD68uvzKg8SAc+1E=; b=Ad/bomkBOp2x8Kb9PWa/ a+2fDRWsx0HDjJpGYAgQBWfptIx+pFQacBp0s9hQKU/fWvITjKMmxlZm7G3hoSRQ iTCOR1NEjbNURP+n96DH8fWVgiiSL6Xgcfyph8dRjUgz8oNDf/7c7q9Bi5tiEFXZ QlKGvT0UR3RdlquwMPQ7Mn0= Received: (qmail 10108 invoked by alias); 16 Jan 2020 11:15:43 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9877 invoked by uid 89); 16 Jan 2020 11:15:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.6 required=5.0 tests=AWL, BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=3, 1 X-HELO: EUR04-VI1-obe.outbound.protection.outlook.com Received: from mail-eopbgr80041.outbound.protection.outlook.com (HELO EUR04-VI1-obe.outbound.protection.outlook.com) (40.107.8.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Jan 2020 11:15:23 +0000 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=t10O/SSNUWsPMhaGmUGUozP3/jgReNyNTFzQ5aU5blE=; b=s6I/dVn34rqGLGE1KOpf7hilYdaq5tEFff9MT/0jecMcuNhbkwFRTl0xgaAXyNB+WIUdr7ZvvcWPsenIao0X6i5cdli5q0xUuyUUykvQRAtu98BAQtBgKFW47bL07f1aA9feAvsOF3ErBH4fYyzb2gHg3mQNsP+qgsKBPcnQlfI= Received: from VI1PR08CA0262.eurprd08.prod.outlook.com (2603:10a6:803:dc::35) by HE1PR0801MB1674.eurprd08.prod.outlook.com (2603:10a6:3:88::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20; Thu, 16 Jan 2020 11:15:09 +0000 Received: from VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::202) by VI1PR08CA0262.outlook.office365.com (2603:10a6:803:dc::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Thu, 16 Jan 2020 11:15:09 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; gcc.gnu.org; dmarc=bestguesspass 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 VE1EUR03FT013.mail.protection.outlook.com (10.152.19.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11 via Frontend Transport; Thu, 16 Jan 2020 11:15:09 +0000 Received: ("Tessian outbound 1da651c29646:v40"); Thu, 16 Jan 2020 11:15:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 70d14e07ff3ae843 X-CR-MTA-TID: 64aa7808 Received: from 3f0e49b83494.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D785F7F0-9C05-408F-972E-B28263830E23.1; Thu, 16 Jan 2020 11:15:03 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3f0e49b83494.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 16 Jan 2020 11:15:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NIoK7ssEblcc6GquB3CBPw3NgJIxv8osj+3DT3B8W+NK7ptJUa5l93u+QRLWiKj6Jle/C0lSAjmDEAl0k9pwd5x6NSwnRDtST95bJiOdxBIjW2pg+2V0smefJtBuUb1YPAtjg/uXgjuSELqy69rFprUhE/jI6+3eDsgHzB1ea5DLTyDQK7z1TJ9okcLuI3JydnBguSHFd2EunGfYt9o78H0ysZjzjpo1laUmFJxXvpmjA6yNMzYNw3IIYe8PR+rQKnBgeKttPboJOVdVeHomcBvHJPHhLY0Lv8/hZnDe3UlYGMXM5xISvytuGWr0KXpkPYCXH3OHBjUAugYp90382A== 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-SenderADCheck; bh=t10O/SSNUWsPMhaGmUGUozP3/jgReNyNTFzQ5aU5blE=; b=FfPa7akaVKGrQOF4TTwqXSD7+p+eLD7qMgSTc2Au94eF86Ia8LZq6SmICy5MoUzz83NkzkZgWScuU71eQSptcQGbYzZTJkbyKJOa/1vuaOBTxRo3L4jzN41dq5l3FPKvolBe9JdI59v25e1T8ikXYI4kzlX7DcUyRsr/fWoF9Dx5JsCQMDMBvN3gbuEovUjquhWLzvBmjNzibiwtKJoPbEHFLUBgtT4TVT4KLSxAoTYPXsAYy4U0WSm3pONx2Fxo/3vipsK3cXx/wVbHv1sT8hKg8fla30lNXgKN2Y0R28aGjhpvbeLfbRm9v+ecNPcl5d+yUd0h3QIXRWYosrhJ/A== 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 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=t10O/SSNUWsPMhaGmUGUozP3/jgReNyNTFzQ5aU5blE=; b=s6I/dVn34rqGLGE1KOpf7hilYdaq5tEFff9MT/0jecMcuNhbkwFRTl0xgaAXyNB+WIUdr7ZvvcWPsenIao0X6i5cdli5q0xUuyUUykvQRAtu98BAQtBgKFW47bL07f1aA9feAvsOF3ErBH4fYyzb2gHg3mQNsP+qgsKBPcnQlfI= Received: from DB7PR08MB3292.eurprd08.prod.outlook.com (52.134.111.30) by DB7PR08MB3036.eurprd08.prod.outlook.com (52.134.107.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20; Thu, 16 Jan 2020 11:15:01 +0000 Received: from DB7PR08MB3292.eurprd08.prod.outlook.com ([fe80::5d10:e4ac:4968:cab7]) by DB7PR08MB3292.eurprd08.prod.outlook.com ([fe80::5d10:e4ac:4968:cab7%4]) with mapi id 15.20.2623.018; Thu, 16 Jan 2020 11:15:01 +0000 Received: from [10.2.80.79] (217.140.106.55) by SN1PR12CA0053.namprd12.prod.outlook.com (2603:10b6:802:20::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.18 via Frontend Transport; Thu, 16 Jan 2020 11:14:59 +0000 From: Szabolcs Nagy To: GCC Patches CC: nd , Sudakshina Das , Richard Earnshaw , Richard Sandiford , Kyrylo Tkachov , Torsten Duwe , =?utf-8?b?RsSBbmctcnXDrCBTw7JuZw==?= Subject: [PATCH][AArch64] PR92424: Fix -fpatchable-function-entry=N, M with BTI Date: Thu, 16 Jan 2020 11:15:01 +0000 Message-ID: <00194eb0-f727-4d59-9bcd-60b05248d031@arm.com> user-agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; x-ms-exchange-transport-forked: True x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:2449;OLM:2449; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(346002)(136003)(376002)(39860400002)(396003)(366004)(199004)(189003)(316002)(31696002)(4744005)(31686004)(66476007)(66446008)(6666004)(54906003)(2906002)(16526019)(44832011)(64756008)(186003)(16576012)(5660300002)(66616009)(2616005)(66946007)(66556008)(956004)(52116002)(26005)(36756003)(8936002)(8676002)(81166006)(6486002)(478600001)(86362001)(71200400001)(4326008)(81156014)(6916009)(142933001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR08MB3036; H:DB7PR08MB3292.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 4+htnzLc8FDRhQsst92/+uc0Cz6Pmy51BzEjTTRj6Ce4/biiIuM/ugzFn+kLND5t7txPobC2O1EgTlIaG3CAA/0B21Q6AOrLFewdXqIj1w7DG26/Xlb7VRyMFuVO/BUIKu5COUHL4ATB9pUGLck7ZLbgVO7xI7J73+fpJJI1qF+Rs9RXeMXzU5yluSHtLCcXpj1R21duMBCwzuL532rpfc1UAQAsR88oaXjwdDQgqlv/VQz9EfwbAqe+Efe++UxWeJIg/69qldrHjmOmNEUwRpRreYniwhxObi/klgo/hvtlXt4XlpXA8y89r5JhOEnmEyRfaaFU8zcZgV7/HReea9/l9zRhiqlh/wwcscINWqbwz+Eg+R2nCP2HnBreW67vhl2IghB9+h4r/3KDuCbjkknAto1azyDWcChtzrbGu6gpt1RE5tz51sBVtujtBRvpxI4Ok6xHaHVzfKNAlx930tLItvFdelT5jYK3djJHz2/miXHRhG85dTMyHwFbJbJn MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 8c2a628d-aa07-4ff6-2f73-08d79a755452 X-IsSubscribed: yes this affects the linux kernel and technically a wrong code bug so this fix tries to be backportable (fixing all issues with -fpatchable-function-entry=N,M will likely require new option). gcc/ChangeLog: 2020-01-16 Szabolcs Nagy PR target/92424 * config/aarch64/aarch64.c (aarch64_declare_function_name): Emit BTI c if the function label is followed by a patch area. From ac2a46bab60ecc80a453328b4749a951908c02c5 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Wed, 15 Jan 2020 12:23:40 +0000 Subject: [PATCH] [AArch64] PR92424: Fix -fpatchable-function-entry=N,M with BTI This is a minimal workaround that emits another BTI after the function label if that is followed by a patch area. So before this commit -fpatchable-function-entry=3,1 with bti generates .section __patchable_function_entries .8byte .LPFE .text .LPFE: nop foo: nop nop bti c // or paciasp ... and after this commit .section __patchable_function_entries .8byte .LPFE .text .LPFE: nop foo: bti c nop nop bti c // or paciasp ... There is a new bti insn in the middle of the patchable area unless M=0 (patch area is after the new bti) or M=N (patch area is before the label, no new bti). Note that .cfi_startproc and the asynchronous unwind table entry label comes after the patch area, but whatever effect that has on the newly inserted bti c, it already affected the insns in the patch area. Tested on aarch64-none-linux-gnu. gcc/ChangeLog: PR target/92424 * config/aarch64/aarch64.c (aarch64_declare_function_name): Emit BTI c if the function label is followed by a patch area. --- gcc/config/aarch64/aarch64.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 66e20becaf2..0394c274330 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -18079,6 +18079,39 @@ aarch64_declare_function_name (FILE *stream, const char* name, /* Don't forget the type directive for ELF. */ ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); ASM_OUTPUT_LABEL (stream, name); + + if (!aarch64_bti_enabled () + || cgraph_node::get (fndecl)->only_called_directly_p ()) + return; + + /* Copy logic from varasm.c assemble_start_function + to handle -fpatchable-function-entry=N,M with BTI. */ + unsigned HOST_WIDE_INT patch_area_size = function_entry_patch_area_size; + unsigned HOST_WIDE_INT patch_area_entry = function_entry_patch_area_start; + + tree patchable_function_entry_attr + = lookup_attribute ("patchable_function_entry", DECL_ATTRIBUTES (fndecl)); + if (patchable_function_entry_attr) + { + tree pp_val = TREE_VALUE (patchable_function_entry_attr); + tree patchable_function_entry_value1 = TREE_VALUE (pp_val); + + patch_area_size = tree_to_uhwi (patchable_function_entry_value1); + patch_area_entry = 0; + if (TREE_CHAIN (pp_val) != NULL_TREE) + { + tree patchable_function_entry_value2 + = TREE_VALUE (TREE_CHAIN (pp_val)); + patch_area_entry = tree_to_uhwi (patchable_function_entry_value2); + } + } + + if (patch_area_entry > patch_area_size) + patch_area_entry = 0; + + /* Emit a BTI c if a patch area comes after the function label. */ + if (patch_area_size > patch_area_entry) + asm_fprintf (stream, "\thint\t34 // bti c\n"); } /* Implement ASM_OUTPUT_DEF_FROM_DECLS. Output .variant_pcs for aliases. */ -- 2.17.1