Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1615181pxp; Thu, 17 Mar 2022 12:46:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2Hxv+Atg/oacqw8PZegcSJOEPVkIOwcqHPmgqW0omui1Kcly3jEeXFFJhhy8gPQ5AwQVj X-Received: by 2002:a63:ea51:0:b0:380:7c35:188e with SMTP id l17-20020a63ea51000000b003807c35188emr4978923pgk.607.1647546411302; Thu, 17 Mar 2022 12:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647546411; cv=none; d=google.com; s=arc-20160816; b=CWqmmrneoN/c1tcnOe+ADc0TXfOFTVipQ2w2/BnYiFEtX2YkjXHd09XrYusx0V7GIR 8wpyIqknvZln7CIglUm8xWC55nQjfyIjddJQ3jq2so22vxM0o4jw8u506M0E/c9mdzI0 JkhUdU6GSPGU58ANYT9D5lvUsr/uiz9cJ6WYqj4j0LasIjhC589xvgH9Qc8mHcu8be3p zWsM9t5IrtTkZovdEqWI4Nc4SduakCK2/bT2yQVj3JGubF26rCHWK5gJs/XeJCKLroqt p2yBN9/6Q/UAzRNpm03LbbNX4nUg00MZ+ghWaBK4Q8MS1o461OwU+yLNk8QZR+pQyv0E hGYQ== 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=YXNspB7oVBwnr+WYVVsJzjOdAR6FtWbdt6HcY71uiNU=; b=OMzsFo1vB/7ANkffqgbfAlY8t3P7xEk+MFLL4uSk844ptBsMuL2VSfXlXZL3DQUHqP LEdqUdKPmKsFP2+JNg3TYG4eIQKp4WsKUn7bFVsapDt2Bvdcb87EvOqjoggV7g1SYXPN NkJbWjL81Obi70LwfNHI9SuVWiQt1HicaIbjjqRDpAqHNXzLVLj8mh52j8LTV8GhZe8H CIyCSbzoekjltJfveXLe5c4vd0jZS/AYjXiThuDZaM8zriiQiUuv0WXp4dz/nAHTg3WD 8v+JAWp5MwtO77ei1yz9ggQAsOM+bU7Jnx45ScBji2OZSjT311huFAS+vjhK/pLnHGZJ oSJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Egcb0JuG; 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 m7-20020a654387000000b003816043ef62si3125944pgp.343.2022.03.17.12.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:46:51 -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=Egcb0JuG; 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 E9658FA23D; Thu, 17 Mar 2022 12:44:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236360AbiCQSNM (ORCPT + 99 others); Thu, 17 Mar 2022 14:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237295AbiCQSMx (ORCPT ); Thu, 17 Mar 2022 14:12:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E77721F746; Thu, 17 Mar 2022 11:11:32 -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 099116163F; Thu, 17 Mar 2022 18:11:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 107B6C340E9; Thu, 17 Mar 2022 18:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647540691; bh=Di4mwje8+RhmgN7c9XcjMHtGn4piSBr1VjnN0XzxP/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Egcb0JuGyYexsB2gG/vpvVov03TnZum0ksC5JFifeGvpTGTr0aX6dnA5W7+214Bu1 4nVhEEREacJSr9+LS784vSyntJo9SpNyATPAd4vdP1YnJpnOSt61CgGx6SVGlFTfFI fox4FLP9VH9V4IyulX9445QLYbG6EaO9/vwdWicT6cKGGmMlo4ap9zG+ElXkeQlUZd nXzUXbC3ism/CEnwR4rUhfGjwSrolVXxy6kng+8jJX8I1MK/Bny7bAeuqGD5qSA/9K 2+pBOl/0ydoskakOHd8K7CX32qiNVbDsy6fuG4RqSsntfpqqDhW4IAyaFE1puc4JF0 zwAqU2/mG/Efg== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Sven Van Asbroeck , Gary Guo Subject: [PATCH v5 05/20] rust: add `compiler_builtins` crate Date: Thu, 17 Mar 2022 19:09:53 +0100 Message-Id: <20220317181032.15436-6-ojeda@kernel.org> In-Reply-To: <20220317181032.15436-1-ojeda@kernel.org> References: <20220317181032.15436-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.8 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.1