Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2732814pxb; Mon, 17 Jan 2022 04:48:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxylfjlg3rtSFJj14uqMcBPGaATi79Nc3hrxe6hsCWbO7Wxy+/ieE0tPwNKHOK/2tdqtUb8 X-Received: by 2002:a62:3893:0:b0:4ba:7246:4830 with SMTP id f141-20020a623893000000b004ba72464830mr21164119pfa.30.1642423708969; Mon, 17 Jan 2022 04:48:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642423708; cv=none; d=google.com; s=arc-20160816; b=nuVrVdL585HWnf8OZFR/fQNTZkH+c3hb2bcr611fQ7XywyP7tf4eS0FKw82w6w6ZBi S3WGWgDuzGAOwhDy3A03Jn+O/3ZTXvtq8M9oMmFNoHT6QLc4+McQNojBWc1pnOlbD7Us 9LGxbdKuyqoN+VSkilo21Oy9zCZdj/EGnJBiytLkMYE+MEGYIyGq0JUz6/VF/vyRQ6gm isbYptk0ETkrnVOPAdY3CAhWCC4yNXR9Tw4/s4OuoY1psdAtfNza35lHkW84MpjfZ8Jt G7LwsxrIOsZCmP6SU4hyMizzMwrfBaKuqX2xXUqzavXwktbwv/sRUM7wJWQQuc/thAC3 PKtQ== 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=nF9V4SCeBxyebjJuWaz8y7tNaeLGOEkMtViz/XfR72M=; b=ISJ1j/8GXLlV23MNRvRanFB538k7F8+y4I9XJPtkueyQq7fZDHybA1HhuLXGu8Cm5c RBUCaKEEuJjD0taJzmQYo5EABmcJ0CipY74xPgQtDfeEx6GPUfSsT9sHwRx+akd8Lcxq 3YE9U1Iu3Fq/E1o5vL3Yurirl/aTOq7ZmNuc40Sii5zKDKWItvYlNazPLQUlwKaFCVVF 413skdUKUARdjW4hvIfvZ178WXu7HZSReYS4yYkQGQvzZL2o6pzr9hC+0ribFfl8c2aN jpUAYkUHHbO/cxXpelFzb2wAV0CTpkH2ix4DRpKRFWlbKh+4LSR70g75jx6BsltsoDtt PVsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CbPE7Hai; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si14533798pfm.146.2022.01.17.04.48.16; Mon, 17 Jan 2022 04:48:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CbPE7Hai; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233037AbiAQFec (ORCPT + 99 others); Mon, 17 Jan 2022 00:34:32 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:40512 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232491AbiAQFeV (ORCPT ); Mon, 17 Jan 2022 00:34:21 -0500 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 BBCBA60C89; Mon, 17 Jan 2022 05:34:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB649C36AE3; Mon, 17 Jan 2022 05:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642397660; bh=5rvLt8iTF9Dmq3X82Bebuph+mMdfztG70mDfiFGUy7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbPE7HairgHanSaTbPq/aKrAi871ml7Ofy6uu6TrelXX2+5cmSWxVm+TBKbMhuZZ6 JzB6bxvVlkiyNKlOQi0ak3w6U6pQ6L1VbARuTUhpEs6NSgEFOE4SrjexTT9CBk9P9I SxTF3kS+ua7pali+kXkwjRdZ7TQclISQbsof0zsTZL/cMFLZJo+iZGSBxJ3hzohhOn l/gqA6ZC8humDMYY8SlyUfM4v5NeJ9mRM0njUcUmp0wJI8lrK0wbilaasBmJmxcZ5L xxxBMVcDBTHxoFNQtaKT/ILyoGqD2XbEANYHwkKaekz6UcepW7jZpZ94FY73q8T9t0 a4rPjsFBOluuw== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Sven Van Asbroeck , Gary Guo Subject: [PATCH v3 05/19] rust: add `compiler_builtins` crate Date: Mon, 17 Jan 2022 06:33:35 +0100 Message-Id: <20220117053349.6804-6-ojeda@kernel.org> In-Reply-To: <20220117053349.6804-1-ojeda@kernel.org> References: <20220117053349.6804-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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..a5a0be72591b --- /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 floating-point 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.34.1