Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3294794lfo; Mon, 23 May 2022 00:57:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk81nzkSPhKOEZTx0k9xfoEt2v06Um8mkA5Mz7LvxxcfMXfIIk/aR8UjW7lq/16U5gXbJx X-Received: by 2002:a17:902:f64c:b0:156:7ceb:b579 with SMTP id m12-20020a170902f64c00b001567cebb579mr21137254plg.73.1653292643369; Mon, 23 May 2022 00:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653292643; cv=none; d=google.com; s=arc-20160816; b=EJRe8ZjpMhW6Sb8wWcaxyA3XAivK/Rqjswt2dPwzABryZumbgoZgUKsHphWzzI69vn oFsHLGbKOG2T7+oHdnidpH6cInNrlQRaG1RFyyKHVMFJXisXmw3ruVEGE4T+TMsM3J0+ 7UE+Pp1VcTZAdEdVqacpDvjteC2hyB7YjJOcy66MarPzraaKvhzYXB+rHHXDESV3BXFS TAqHn2iOwXAf/RGgvF+TUqR8FmLXYA9ycZwnxNdjuEVYEKVwnXzH6n55SRW/NsRCepSo GjIBZnqa5iQNIFt4xMeXkcMJ1oqDq/EVMtuJ74TPWWP/t11OD2OufMYwFnkoGgBk+7Kk LTuA== 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=murT9UyJG/JnB+N436D9k+f3SuE4/fl6JqUkuI5zWSw=; b=ZzGydbcvSEK4dH6ofrRfTYuxqqK8BDnOjRmjdND32AwXy/AbMAP3lXQX0pkTi3rggH KFR2pLsLYEzEPDUnR0biQ893pkypIG+AkqpSdwjuq/0jnm3dK1VjEB6ibQ7dPdt9iApF vNxWHKCmhPyo1M/b6fkEdYrRnEWV85LjCDB05b6PbAF5Q2R9W7aPnguRCCe3CpRaaBOf Tr1/4+m72GR8UlbIQVo5MO7UO14G9zC89AOm/VCVbkwlrPJwh4aKzgPrrXu5PMPF5lvr ha19pCrVarJTbfdPL7yiLctRg0RGdyF73x8fcG8hW3FxxnF4lT2me5YDsic2q2XFWbQP PZNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VInw0gGO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d4-20020a170902854400b0016170d637e9si8994991plo.437.2022.05.23.00.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:57:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VInw0gGO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 CAAB444775; Sun, 22 May 2022 23:57:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348259AbiEWCDr (ORCPT + 99 others); Sun, 22 May 2022 22:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352286AbiEWCDX (ORCPT ); Sun, 22 May 2022 22:03:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 592DD35DF6; Sun, 22 May 2022 19:03:18 -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 ams.source.kernel.org (Postfix) with ESMTPS id 02C71B80EA1; Mon, 23 May 2022 02:03:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D35FC36AE3; Mon, 23 May 2022 02:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653271395; bh=07frGEXymAghPkvplZhERpWTKuHZcKtB5BOg3V+bwpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VInw0gGOixbGoi3wcU4nx+vG3u8rcyALDmHNHN2ZMpdklAfhYy8iYvRKfmW5fkfqp EjQSdFeaCbiayLINTF7fhkHCJeZehMg+Ali/XrPkVTjeCfCv8onfFmCE+2lsv7K/Fz 6e+e9VmoBqqPiVRBlVGOP91wGnAlWXfnT4+i8ivq8X/yNJFznGJY3k3zE26C/xHYyG eS8JHCa3DgZh2zgAFgfnbe32B502KkHzs/Nn6mGZA1eNC9sUUz1eqoq9RlaxACStou fYq4UfvF14b6pqIxGOahjYY9nn5/crNb9JE67wat3vojz8PuZAjES4tswfdMK2zj1U S++3AjppJ8JEw== 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 v7 06/25] rust: add `compiler_builtins` crate Date: Mon, 23 May 2022 04:01:19 +0200 Message-Id: <20220523020209.11810-7-ojeda@kernel.org> In-Reply-To: <20220523020209.11810-1-ojeda@kernel.org> References: <20220523020209.11810-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.36.1