Message ID | 20221205215000.2563281-1-gary@garyguo.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2493773wrr; Mon, 5 Dec 2022 14:02:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Awt/cuQi90YpjuW9IVo1xt8QlwtbWydLwrUBTba2NOQVQauP2UXyWXsywUNaGz5rFN5dl X-Received: by 2002:aa7:dd45:0:b0:45a:3c66:b0e4 with SMTP id o5-20020aa7dd45000000b0045a3c66b0e4mr76773790edw.33.1670277725990; Mon, 05 Dec 2022 14:02:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1670277725; cv=pass; d=google.com; s=arc-20160816; b=MLb4kfES3oCLi2b8X22FjV9YdREF7JrBPxhH/3gD9gzjmYuizRKk4GuNsS8/1a6GZm E4au2g3UAMWWMJQphz0zRJAhaLcQ0q4KAjOIXiRqFbQBCT9VhRc3C5u8Q9Msdn4wsVJn mUEuj0ORYtWaR1PTtnZ4R7QTdiZ1bBItHpfURkztkBfRj13ClR63BGcC1MCTVhJ0YnL5 f//nHx3H9+qCUqbZjPM11aMdJfGUU6G0G16kipMxEPbi02Bzwo/ZEwic9R3qHBFW54ID PxKC+DIe6SFYGQwzTnlBlHzxTHPUlic1ifJoSWFNWzueIYbu4w6XvrMKu2XRwvFor+dO sxhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=HutuBfseF8+fbw5cXCGK1xdciMWeZsnZ28w1ftJ43PA=; b=eeztHqSV46NS4Fne3mcww36w1kLwdmE7gBsuTOzaCIuXbjCxf9kf9LxHzJLxlRKdrd OnuI/em4QU86rhnToifwZNj8lptU5JqIb2WfThWzwjsSZEMlQLbXqiG0dWNtfWNNzWAG ncBoVQYjE+QZjowhKN05FJ05G+o90uQGOoGkVy22JOxfkap2chGRjJWILj8glNMPlwF5 46ZUgSW71MxnDg+WqUnLpH2MG7v0t+pZedTW453gEuxbLoUeSY6vdZjfrQs1ARRt+sUh XdFrxYLXKbil4rIPtb7YDsYwHbMHbUDe6hd+ElOc9CiaU4shCGNcADQbFiE19CeyCEir HJ5w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=ZIvfZcAj; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw19-20020a170907a0d300b007c0d7aca43asi4795738ejc.583.2022.12.05.14.01.40; Mon, 05 Dec 2022 14:02:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=ZIvfZcAj; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232678AbiLEVvs (ORCPT <rfc822;jaysivo@gmail.com> + 99 others); Mon, 5 Dec 2022 16:51:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231420AbiLEVvZ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 5 Dec 2022 16:51:25 -0500 Received: from GBR01-LO2-obe.outbound.protection.outlook.com (mail-lo2gbr01on0718.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe15::718]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6CDA766F; Mon, 5 Dec 2022 13:50:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CU+7+wCxiOyUu62972QvmHeJkJTmBqrxCKEgyGi6+CcwO/lUASZADqf+RoesJe0FIX3tp29ajj4/adRQhIGZem7Ie5OYgWUyfQNfORTHAV2GrPWUutWmRDxyB3Z5ei70r0Ns0HetPo7Lsr8QuUZ6dxvc2I+oMwqMK0+hxSJcuvbMd/4h9YFsGA7gEmNT/EwcllG/4s0rxgizdmj9w71jMeC8/TfRWBtiGT6Jc5YJOtmg1KSCnp0B3mIkLyjFy6X1CJkKOsMQ2SA9GF876Tf5j0CbSJGcsyi0k9PKhKwMLzjMaqgT9VxNILy+vuixafiGIdTJ3Z9Hl44S9XZL/VQo2g== 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=HutuBfseF8+fbw5cXCGK1xdciMWeZsnZ28w1ftJ43PA=; b=IWWLCMaUFyfirGg29oLrZEHKL+OVupdQcJUCvbyi38QtZCoaC72wWysWuH5rfwcfJJsETx62rRrxOu/QzVrO0p9MCQ0lMWl0Hmavou2q0eqae2e7EHz7vuIIdhcj7GteJ+Cgdwv7Bi9j3kw6We3wiidg42VOdQ+BakTFqO2gcHk6Ya5EkYToqpZLniVDLLzup0FtIbT4hBrr69rjUlbeHbbPiegSIJxhBQcVE3xvt8/Q8bFRItZHescSuM56wllwp6rnVw+M+OMqkvMwykuQ4qhMfFu3eKscfTB1yof+IqU06rTqLaCljtHhoVzunvu+x/pfbUFSafONT2rjRpe8XQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HutuBfseF8+fbw5cXCGK1xdciMWeZsnZ28w1ftJ43PA=; b=ZIvfZcAj3rIUr1DJSE0ci4aqqrrk2JbLUKrc4PLKB2bw/XYiLIsCn8uC5l7Ds6D90j1ii9ez2rLtdLIhPOQR0lWOpz4PcY8YPYlzlCqqdK36gfALuwqjvGptC2BocvpFVqQvAvy1mbWekYejFWRGRwqHZycaAfl14mnXfCJWbWA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by LO4P265MB6464.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2d4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Mon, 5 Dec 2022 21:50:15 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::6c07:e2da:3210:3fd7]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::6c07:e2da:3210:3fd7%6]) with mapi id 15.20.5880.014; Mon, 5 Dec 2022 21:50:15 +0000 From: Gary Guo <gary@garyguo.net> To: Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nick Desaulniers <ndesaulniers@google.com> Subject: [PATCH v4] rust: compiler_builtins: make stubs non-global Date: Mon, 5 Dec 2022 21:50:00 +0000 Message-Id: <20221205215000.2563281-1-gary@garyguo.net> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P265CA0146.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c4::18) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|LO4P265MB6464:EE_ X-MS-Office365-Filtering-Correlation-Id: da49c94a-19b9-495a-e357-08dad70ab07e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U/oe65gUR2QvFohHte7+xrvXAGI1rbM4C1WvHN/FJRzBTlkVYOpX9t7vIHiSJjRu9dJoeve+oyQmdgLv4BPjYMi8N17oICFzZStTQSZjwYkEL9GgxyX3tSOZlqOUe+BcjiXCzLndnnc78l1lPfebVa6uyCpBerX0VhysJnoOMhcYP4hcBC0ANOEUgGzAIYwoQqnmpeJoxJTEa6a7m9ShA+EZpZZn8ThJlvq9p/Mw4RDHAJzWyWz5dLv6JfM+by86K39qiCkrIZaILSu979srvHQUSAJdXt6A+QlgPwEChoWg5UOzuRyjW8OWRrNxsA8m2lcOWKviapjNtMy2R9rERH9yBMw/qNyYaI6arcMwFW++FWIuFtJBCmr82oPE3BV+ptmwwhFJFMqbSQgTGvvZ/dglNGwV9FiRlXjGCuc2qgYrIVKZ7MMuBOr+f01/zl2dcR0Ae79J2LaHzUAXRH/QJELgUHBFYAKtV3OwiCMXwV727yhAbcyTHUR5UeDH22JmVXeBvEUq3oMKQivWZ8JcLgD9LcsPOJuKu9cgORf29mWbY5aj2kdnw6bKSeVjU37FLgNRq5pGkUL4G0yGOwCG4eSL4PcKekd8s/h1iVOLTrgRXFWCapsCq8gg3ITfHmHRkfnvzZSKqq6ehS93aYaQWBGJN3WvXLwtlRrucvYT0V0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(376002)(366004)(346002)(136003)(396003)(39830400003)(451199015)(36756003)(38100700002)(86362001)(8936002)(2906002)(4326008)(41300700001)(5660300002)(83380400001)(478600001)(966005)(66476007)(66556008)(6486002)(316002)(2616005)(66946007)(110136005)(8676002)(1076003)(6666004)(186003)(55236004)(26005)(6512007)(6506007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ndrWK5/P2T+gpSd8DUW8crakHKye4icV1PpR1QvYOKkA4vb2mEn7MSwW6Vpg2LOZMRbhe2RtH8Vfa0lnpgpGvSbZJ+K36DpJjeEGZuuNjMLGFSwk6kYRj17RFEwOG8YC3nlK0reA5RHvljv7BcOolegdA6O+N0zuPzc7eu/+ln3rDNP0TFtZephJcox69E/hFJ10PT13j83YpZ3+5BrCYq/x7Zr9DN3iqORwNcrSiPn2WpbPjMuhol3fqSsHF56g5idW1ZQlQ5ihNfxwCxcqCB/4DwfhMQGDfrm1rD3//GokWkwpQTX8SeM1B7khtQfwGoEaVX4yPoPMAa5Fw9Jlmm8K2JK18UhWRgHQh+4B4wnwPbQyticRg8Q3bN5/kurlz0Mf/l8g2R77BxGk9RPbP6j3NO6LN2V/jewXjPw6Xm7Cz3G8x+ysQ3twEqMkNqUxbuT3E7qB69BGsbxjoixVb7c3CcCY0lnNzvNzjFnJSsuJ8s6G5bdWF5Tc7+2y/d9HbkJtoW0nbr59OLF8mxAutfQ48q8PXFqkjWXJuXs2e24m4xzfphSkVqVrSkM1QiLHCC4yfRlEeXWOI2BxSO/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AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2022 21:50:15.2731 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PdNVIlu39xAwXvsT8qUMrLZSkSOtD6EsFkl12IkY3ZiCrH03BvtDZOjCl+Cdr7KyDr63NcK83n0AsPiLGTJeSw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO4P265MB6464 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751412863307919948?= X-GMAIL-MSGID: =?utf-8?q?1751413136853246687?= |
Series |
[v4] rust: compiler_builtins: make stubs non-global
|
|
Commit Message
Gary Guo
Dec. 5, 2022, 9:50 p.m. UTC
Currently we define a number of stubs for compiler-builtin intrinsics that compiled libcore generates. The defined stubs are weak so they will not conflict with genuine implementation of these intrinsics, but their effect is global and will cause non-libcore code that accidently generate these intrinsics calls compile and bug on runtime. Instead of defining a stub that can affect all code, this patch uses objcopy's `--redefine-sym` flag to redirect these calls (from libcore only) to a prefixed version (e.g. redirect `__multi3` to `__rust_multi3`), so we can define panciking stubs that are only visible to libcore. This patch was previously discussed on GitHub [1]. This approach was also independently proposed by Nick Desaulniers in [2]. Link: https://github.com/Rust-for-Linux/linux/pull/779 [1] Link: https://lore.kernel.org/lkml/CAKwvOdkc0Qhwu=gfe1+H23TnAa6jnO6A3ZCO687dH6mSrATmDA@mail.gmail.com/ Suggested-by: Nick Desaulniers <ndesaulniers@google.com> Acked-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Gary Guo <gary@garyguo.net> --- rust/Makefile | 14 ++++++++++++++ rust/compiler_builtins.rs | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-)
Comments
On Mon, Dec 05, 2022 at 09:50:00PM +0000, Gary Guo wrote: > Currently we define a number of stubs for compiler-builtin intrinsics > that compiled libcore generates. The defined stubs are weak so they will > not conflict with genuine implementation of these intrinsics, but their > effect is global and will cause non-libcore code that accidently > generate these intrinsics calls compile and bug on runtime. > > Instead of defining a stub that can affect all code, this patch uses > objcopy's `--redefine-sym` flag to redirect these calls (from libcore > only) to a prefixed version (e.g. redirect `__multi3` to `__rust_multi3`), > so we can define panciking stubs that are only visible to libcore. > > This patch was previously discussed on GitHub [1]. This approach was also > independently proposed by Nick Desaulniers in [2]. > > Link: https://github.com/Rust-for-Linux/linux/pull/779 [1] > Link: https://lore.kernel.org/lkml/CAKwvOdkc0Qhwu=gfe1+H23TnAa6jnO6A3ZCO687dH6mSrATmDA@mail.gmail.com/ > Suggested-by: Nick Desaulniers <ndesaulniers@google.com> > Acked-by: Nick Desaulniers <ndesaulniers@google.com> > Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Wei Liu <wei.liu@kernel.org> It seems that the only difference between v3 and v4 is Nick's ack. You can put a changelog by adding a `---` section -- it will be stripped by git-am automatically. Thanks, Wei.
diff --git a/rust/Makefile b/rust/Makefile index ff70c4c916f8..aed6f7eca36f 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -359,8 +359,22 @@ rust-analyzer: $(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) \ $(RUST_LIB_SRC) > $(objtree)/rust-project.json +redirect-intrinsics = \ + __eqsf2 __gesf2 __lesf2 __nesf2 __unordsf2 \ + __unorddf2 \ + __muloti4 __multi3 \ + __udivmodti4 __udivti3 __umodti3 + +ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) + # These intrinsics are defined for ARM64 and RISCV64 + redirect-intrinsics += \ + __ashrti3 \ + __ashlti3 __lshrti3 +endif + $(obj)/core.o: private skip_clippy = 1 $(obj)/core.o: private skip_flags = -Dunreachable_pub +$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) $(obj)/core.o: private rustc_target_flags = $(core-cfgs) $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs $(obj)/target.json FORCE $(call if_changed_dep,rustc_library) diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs index f8f39a3e6855..43378357ece9 100644 --- a/rust/compiler_builtins.rs +++ b/rust/compiler_builtins.rs @@ -28,7 +28,7 @@ macro_rules! define_panicking_intrinsics( ($reason: tt, { $($ident: ident, )* }) => { $( #[doc(hidden)] - #[no_mangle] + #[export_name = concat!("__rust", stringify!($ident))] pub extern "C" fn $ident() { panic!($reason); } @@ -61,3 +61,6 @@ define_panicking_intrinsics!("`u128` should not be used", { __udivti3, __umodti3, }); + +// NOTE: if you are adding a new intrinsic here, you should also add it to +// `redirect-intrinsics` in `rust/Makefile`.