Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5164600rwb; Sun, 4 Dec 2022 15:50:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf4sz7ofM+S0MxsrmAXfNzSzHw472HqS8WIa4pn3I7ZV1eF4rtbNaXFV4/3YCi8qtnabAeJh X-Received: by 2002:a17:903:252:b0:189:d3b:6201 with SMTP id j18-20020a170903025200b001890d3b6201mr63570063plh.153.1670197822192; Sun, 04 Dec 2022 15:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670197822; cv=none; d=google.com; s=arc-20160816; b=peZuUW9bKuUM8tqpsKPdy/aajhlWtG5dmj2doNEYouDTp08Dcg+oF25DINQGYBr843 Mhr4So62hN/dSZjDsvnE19IaZ+d9eD5VowSXDWx9KgZSTWz4PeqOvWGH80gZZPOifkBE F/TQB9uODuwhMDphUffmaO3D2SV3/sj9KzuJ55Qos9XVtIO73K/k/mk0wJVaBWA3nnVe tqGeUYJuQSyi/TPJK8JuKOhcgmpphVbvrZ0mbj0je79wDW2+g1STXQ2DJMaVE04A2feG Ms2lAKP5sgW9w+mk5/gnZh4SUDfvTX64da69vC/hVw967F20N2elYf8pEkHYo0edVpdr ymzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=60KRWbfLpgb9ykw8m3+leQoSYUWkACl+x4S1nlYbkmM=; b=rWtSFG2K4FyROaGVjBGw/EIJUP8ORI6efNOmpm/i5w1WaqamLu2rUT+G7/XsqOQ6qR zfyN5Y6bYgkUVcazgyEBRQbPN5axTLmfxwrQ3rBzEvJv+h4PS4Kg4Ke4GMU+WBXnPsEn xB/MibnLSVYtQnnf4MdYY6mdQBfls2ODE6uxL2rCcKPcw2GmjIaV0Ylic4k2cIzplArC PgtQSXlAngxtQuybf/T9WCHXWnTG9NaDUU1L4rbtu2lWZzVN2128gaa1WE4wbMfmofM4 WLaHQ9W6mXzJLqRLxHpRGTWPFbACdQOKJyVgQ72InC5M7cIYZEobB34penvn5+qotPlW 1MnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p8DvGEoi; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a170903245000b00186ab01ecd5si14898707pls.219.2022.12.04.15.50.10; Sun, 04 Dec 2022 15:50:22 -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=@gmail.com header.s=20210112 header.b=p8DvGEoi; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbiLDWuT (ORCPT + 82 others); Sun, 4 Dec 2022 17:50:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbiLDWuR (ORCPT ); Sun, 4 Dec 2022 17:50:17 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 971FCFAC4; Sun, 4 Dec 2022 14:50:13 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id s8so15932867lfc.8; Sun, 04 Dec 2022 14:50:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=60KRWbfLpgb9ykw8m3+leQoSYUWkACl+x4S1nlYbkmM=; b=p8DvGEoipdmOFLlZibH0ymdIRuNVTVsGM4sZoybpffizTogdsFzbMA7LQmilBP961P heValp+vHjVs6/lu47qD9koaPd3KK2Ku0BVlzzf8N7tr7Yg6rRGHasWpR+M6ot8EKOn+ uLq+kCxFUNcQFWz19NiTBR5zmM4SWIwEQ7uRMsvZfr18FAPXC6BNdvWdvz9wH2dY5zmf WHlNg+OzzyLs82c2m2x7LZlJt3555Z0tCVTnbLkqKiOQFwIqUDVIEVoVdW0RmdG6msVh mGieZ4rCfn9aMClRi0mufTKAVBJLblauvAdDo+PgjT2+iwTJh0eexty62gN/JmxdaXaG r+zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=60KRWbfLpgb9ykw8m3+leQoSYUWkACl+x4S1nlYbkmM=; b=yRtRuGOgCs/b7C9NiHmFR/wMAkI8oKYLxRpLLhjj12LbuPgu0Zms4zPCSXMEtcYOkD Ij0d6WpGglZ9qTTk9URo3zacCn1WufZq6ivBckkw6ghF6LOc+TKANylq0cmPxxrsRp5f yW8P3sPq7W2L6ECjSvm5BnuOMHfY8o9wtR01s6DJrcuaBuu+EdG/f57DcYj4Nmb/kpw4 SYQpveoonaDbYIdFTIdKB+wLOVvlF68GW+PxVmDUtxPX2uD9qdtrLLDJL78BflTcVPgr PS6KcWzrNfYFEPaKTuKMyQaO87LPyVGRWY4Lf3wxcYeFJAefVlga/o5Qa6nFXvSNve68 oIxw== X-Gm-Message-State: ANoB5pnYM9PqhZ8+ioCZ94hsWFSJ2k1wJHo8rOHSoB8cTqhwQcHv6kw2 zUTUepofyhvNcJ6/Xd6yhTiZHPJRNm6nmrkv/OR9UDV+49TZ2w== X-Received: by 2002:a05:6512:4014:b0:4a2:3cf6:985e with SMTP id br20-20020a056512401400b004a23cf6985emr19782556lfb.29.1670194211285; Sun, 04 Dec 2022 14:50:11 -0800 (PST) MIME-Version: 1.0 References: <20221204-compiler-builtin-v1-0-0730c7e573d5@garyguo.net> In-Reply-To: <20221204-compiler-builtin-v1-0-0730c7e573d5@garyguo.net> From: Alex Gaynor Date: Sun, 4 Dec 2022 17:49:59 -0500 Message-ID: Subject: Re: [PATCH] rust: make compiler-builtin stubs non-global To: Gary Guo Cc: Miguel Ojeda , Wedson Almeida Filho , Boqun Feng , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: X-Mailing-List: linux-kernel@vger.kernel.org Can you add a comment to compiler_builtins.rs reminding people that if they add an additional intrinsic, they may also need to add it to redirect-intrinsics in the Makefile? Alex On Sun, Dec 4, 2022 at 5:44 PM 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. > > Signed-off-by: Gary Guo > --- > This patch was previous discussed on GitHub. > > Link: https://github.com/Rust-for-Linux/linux/pull/779 > > To: Miguel Ojeda > To: Alex Gaynor > To: Wedson Almeida Filho > To: Boqun Feng > To: Bj=C3=B6rn Roy Baron > Cc: rust-for-linux@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > --- > rust/Makefile | 14 ++++++++++++++ > rust/compiler_builtins.rs | 2 +- > 2 files changed, 15 insertions(+), 1 deletion(-) > > 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) $(obj= tree) \ > $(RUST_LIB_SRC) > $(objtree)/rust-project.json > > +redirect-intrinsics =3D \ > + __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 +=3D \ > + __ashrti3 \ > + __ashlti3 __lshrti3 > +endif > + > $(obj)/core.o: private skip_clippy =3D 1 > $(obj)/core.o: private skip_flags =3D -Dunreachable_pub > +$(obj)/core.o: private rustc_objcopy =3D $(foreach sym,$(redirect-intrin= sics),--redefine-sym $(sym)=3D__rust$(sym)) > $(obj)/core.o: private rustc_target_flags =3D $(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..1f05f93f2187 100644 > --- a/rust/compiler_builtins.rs > +++ b/rust/compiler_builtins.rs > @@ -28,7 +28,7 @@ macro_rules! define_panicking_intrinsics( > ($reason: tt, { $($ident: ident, )* }) =3D> { > $( > #[doc(hidden)] > - #[no_mangle] > + #[export_name =3D concat!("__rust", stringify!($ident))] > pub extern "C" fn $ident() { > panic!($reason); > } > > --- > base-commit: b9ecf9b9ac5969d7b7ea786ce5c76e24246df2c5 > change-id: 20221204-compiler-builtin-bb03aa6c4400 > > Best regards, > -- > Gary Guo --=20 All that is necessary for evil to succeed is for good people to do nothing.