Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4600459iob; Sun, 8 May 2022 18:48:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjO4/isIIjaxsz3Nw/PWGQb5h7+Ys9vL49jO1MKEqaRbRUuRXFNwq3tqSt8juP3Vq/4Lw5 X-Received: by 2002:a17:90b:3e84:b0:1dc:5942:af0e with SMTP id rj4-20020a17090b3e8400b001dc5942af0emr15659428pjb.61.1652060891276; Sun, 08 May 2022 18:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652060891; cv=none; d=google.com; s=arc-20160816; b=i3jY1/jee1cuAls0F8egYvGGzAyeM7VIHQLeqwGoeIrRthUUTvwr3UAT6Rapec15+I byzF8M/QACpT/GKI8qsN96b55Fq6t1ymyzFwrRVUTaXdT4rQXVcInvWxdVadvHGu9Rc3 rCETx0/+93M2KBKXkEgp53mWlw0i28CIsiue3snD47K2bAFgOvIH4Cc8+ad4H3zrECMm n7GbfMRNd6JCNkOSyCXiLP1coCxEPcCd0rBWoRIPgZDU2ZXx0j6+FUMjX7Yi4UOu5Xla kRAVUBlwC+PnItzrAPPrrGai2nWRcAegRQWnUl5B2m8uSv/aoRctKTZaDP/fOZL7NJdU nMuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vFMTTtCCbugP5ibACr6+oV2Db753ussTYq+vsuaY6Lg=; b=UWOX0PE2eWJm7vnBHZCZGuszcM+QkL04aLW36Gxw6hgaIlnea2PKDP8nBsEbnFNZTf dLuram2UT6yB8L1MX7Mfrw5mGI/ehL/7CQpdEmBq3RtpxSMutaLBoTL72R+QOU1E0GWJ wf2OpALWxYdPkil7N8PdkwREenfPtlZJrDIbi3TdeVts4eYkAQHCjJRBWnjPUdxTKMlo TFcaJNBwMKDrVbztiXkrEmyhSuFVSrr17tMzjihyx3/K8fLmgSTMGrSxLwMHuVlkNuDK O7AA5iETMlb1fY0iPUO3tyy8TevruW30pbO1psse4FPg8YyRUbfEWggG5bzT1Z/iv/RY Y/ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wnpj3pUY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s4-20020a170902ea0400b00158eb28cb9dsi11632296plg.254.2022.05.08.18.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 18:48:11 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wnpj3pUY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E8CD41980; Sun, 8 May 2022 18:48:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445634AbiEGFbj (ORCPT + 99 others); Sat, 7 May 2022 01:31:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445577AbiEGFaY (ORCPT ); Sat, 7 May 2022 01:30:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 433BE6A066; Fri, 6 May 2022 22:26:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BC90360A21; Sat, 7 May 2022 05:26:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D901C385A5; Sat, 7 May 2022 05:26:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651901176; bh=l6bGgj98vMo07Oh2nm6ap2x1Djx2VIyP1PyvH9kWWBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wnpj3pUYFpuIfBlSzUUzPA+ZsGo18qAeAGsWUcdaEqGUz2/7aXPXvW4xHeyWmJgCn zDC7ubBqVGBL/vk2cCtMtAVAxoXUXpftbY7qPnV8YUW9Tyd4IUc97IfpRdn48FU9d5 fafBRmcERO/W7VSAdWq8pygaoustSHsN+qFisFnT84StQVnlj3/V1gVwYkmLsW+nTA 0EzOjcvC5yvIAKnnIIhuxfHRpgW+NNiaYlQLI3Ue33d+lVu7OMbfqmfwjhyszNnQHK rkXAsvO2obbrXLDtViWeioeLPTkS1tVHXp+llD2oakXKqOIbP27CRdfmoAlFLqyr1C lxjxyLojjAwKA== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jarkko Sakkinen , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Sven Van Asbroeck , Gary Guo Subject: [PATCH v6 06/23] rust: add `compiler_builtins` crate Date: Sat, 7 May 2022 07:24:04 +0200 Message-Id: <20220507052451.12890-7-ojeda@kernel.org> In-Reply-To: <20220507052451.12890-1-ojeda@kernel.org> References: <20220507052451.12890-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Rust provides `compiler_builtins` as a port of LLVM's `compiler-rt`. Since we do not need the vast majority of them, we avoid the dependency by providing our own crate. Co-developed-by: Alex Gaynor Signed-off-by: Alex Gaynor Co-developed-by: Wedson Almeida Filho Signed-off-by: Wedson Almeida Filho Co-developed-by: Sven Van Asbroeck Signed-off-by: Sven Van Asbroeck Co-developed-by: Gary Guo Signed-off-by: Gary Guo Signed-off-by: Miguel Ojeda --- rust/compiler_builtins.rs | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 rust/compiler_builtins.rs diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs new file mode 100644 index 000000000000..80ca4c0dcd24 --- /dev/null +++ b/rust/compiler_builtins.rs @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Our own `compiler_builtins`. +//! +//! Rust provides [`compiler_builtins`] as a port of LLVM's [`compiler-rt`]. +//! Since we do not need the vast majority of them, we avoid the dependency +//! by providing this file. +//! +//! At the moment, some builtins are required that should not be. For instance, +//! [`core`] has 128-bit integers functionality which we should not be compiling +//! in. We will work with upstream [`core`] to provide feature flags to disable +//! the parts we do not need. For the moment, we define them to [`panic!`] at +//! runtime for simplicity to catch mistakes, instead of performing surgery +//! on `core.o`. +//! +//! In any case, all these symbols are weakened to ensure we do not override +//! those that may be provided by the rest of the kernel. +//! +//! [`compiler_builtins`]: https://github.com/rust-lang/compiler-builtins +//! [`compiler-rt`]: https://compiler-rt.llvm.org/ + +#![feature(compiler_builtins)] +#![compiler_builtins] +#![no_builtins] +#![no_std] + +macro_rules! define_panicking_intrinsics( + ($reason: tt, { $($ident: ident, )* }) => { + $( + #[doc(hidden)] + #[no_mangle] + pub extern "C" fn $ident() { + panic!($reason); + } + )* + } +); + +define_panicking_intrinsics!("`i128` should not be used", { + __ashrti3, + __muloti4, + __multi3, +}); + +define_panicking_intrinsics!("`u128` should not be used", { + __ashlti3, + __lshrti3, + __udivmodti4, + __udivti3, + __umodti3, +}); + +#[cfg(target_arch = "arm")] +define_panicking_intrinsics!("`u64` division/modulo should not be used", { + __aeabi_uldivmod, + __mulodi4, +}); -- 2.35.3