Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3278550pxv; Sun, 4 Jul 2021 13:30:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3KrwbvynY13MmlWa0ZDfH0salR4HfGDJrrt6X/NFK44DcCg8GcppAu7v50C6WCEsoiX3K X-Received: by 2002:a05:6602:1348:: with SMTP id i8mr9130836iov.208.1625430654103; Sun, 04 Jul 2021 13:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625430654; cv=none; d=google.com; s=arc-20160816; b=ge2N6muyUh2rO0sNARU4RRjSrMVaqgd1nJNwspN5QqZEC0r6dhAzXW2/8IdYph9AIj RedYB5DRNnZCQxL3rSW8ZEJd15AiPq4PfhXs1lVmZADPGYFDQ2kvyhqbKpCSRxQC06x1 6vxjHoV7tE5kzfL4fO/9viAIEP7mGw33YvGEUNV7TxaawnalYhJN9DUMUIxN3c2qzp0D c832yZqQT9fDZXBf0d0WNrllXLoLIXmD6UpoDAK28mibnef1tfBHUshCB18CkL2OMpv7 QyG9peE3uf5FCduwX30jy/4+Zy66ZJRe3+z/CM7YSXIVV9dEXBmERTekWumUKuzDHQkv /cmw== 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=wGdb+HCgI9bvq875EYTe7nvd2EM/5I071JpgIrAGeFY=; b=cjqSbJwkoYTjeNQpvX7hvUMuu4Wg6DikzIda8Qzt0pQlfBhPQgpAJ8fVrveBqe/IZN O8RN9YHOqzijivpMpwa7DDLSttN0GjdSnGGr44cCBt4JiIsJFOpBufnxhFE4fpEwc7FZ fhGKtDIGCy3UhQxF1R4OAw0EhGkXdWCDgFSY0ZsG7IGOxVz9E4o0FHErIbgaFi+UcWji gQlirb3TCGt1wBT3yZEAc07smMR8n/Qa6b756rbXSk+mDue/idUYFYC2BohPQ96Wr8v4 WrpBwobcZC5YNX3K0TWdebgiUzQYL8j+KJg5he1v5PjTxsRKB3B4X1A1B0AAZ8EB5/2V gO/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="lt+8b4/T"; 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 c11si40887iob.102.2021.07.04.13.30.42; Sun, 04 Jul 2021 13:30:54 -0700 (PDT) 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="lt+8b4/T"; 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 S230081AbhGDUbf (ORCPT + 99 others); Sun, 4 Jul 2021 16:31:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:37010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230085AbhGDUbe (ORCPT ); Sun, 4 Jul 2021 16:31:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB67B613F1; Sun, 4 Jul 2021 20:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625430539; bh=5IkH6k57x0wQb/2rxknod94WvBdKBrDhSDQRHRqz02o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lt+8b4/T5pa/QK+60/9K1nxKFduCfTeJAIn5OhECkM988lh1qnwLbWxyPwK2x1JvU NTXBn0g7WkSs2t9ebNBDrvCpC2q1HimRMBPcCK3qEZV1wmn3C0tIPbv8LZQiHPz09G pWJuy+jzHRh0gP4HrQxL7KEFCUzUqTGfqKFspguhMUj+ewBeMUaGGLS0qyR0OsvH8A agkX+nyadmMilWcdc84ktdDYKUenKRkn+HSub+rBitRK6CPUOuhY2xWPf3N3ZqZG91 wYL60BtYGt0Us+vBzypVSr2JDkVEDQsbCNs5w7PLeJj7TH6ApRrHPqyszsGXNRcLYa Dyh4CesXSMb6Q== From: ojeda@kernel.org 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 , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Boqun Feng , Sumera Priyadarsini , Michael Ellerman , Sven Van Asbroeck , Gary Guo , Boris-Chengbiao Zhou , Fox Chen , Ayaan Zaidi , Douglas Su , Yuki Okushi Subject: [PATCH 06/17] rust: add `compiler_builtins` crate Date: Sun, 4 Jul 2021 22:27:45 +0200 Message-Id: <20210704202756.29107-7-ojeda@kernel.org> In-Reply-To: <20210704202756.29107-1-ojeda@kernel.org> References: <20210704202756.29107-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miguel Ojeda 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: Geoffrey Thomas Signed-off-by: Geoffrey Thomas Co-developed-by: Finn Behrens Signed-off-by: Finn Behrens Co-developed-by: Adam Bratschi-Kaye Signed-off-by: Adam Bratschi-Kaye Co-developed-by: Wedson Almeida Filho Signed-off-by: Wedson Almeida Filho Co-developed-by: Boqun Feng Signed-off-by: Boqun Feng Co-developed-by: Sumera Priyadarsini Signed-off-by: Sumera Priyadarsini Co-developed-by: Michael Ellerman Signed-off-by: Michael Ellerman Co-developed-by: Sven Van Asbroeck Signed-off-by: Sven Van Asbroeck Co-developed-by: Gary Guo Signed-off-by: Gary Guo Co-developed-by: Boris-Chengbiao Zhou Signed-off-by: Boris-Chengbiao Zhou Co-developed-by: Fox Chen Signed-off-by: Fox Chen Co-developed-by: Ayaan Zaidi Signed-off-by: Ayaan Zaidi Co-developed-by: Douglas Su Signed-off-by: Douglas Su Co-developed-by: Yuki Okushi Signed-off-by: Yuki Okushi Signed-off-by: Miguel Ojeda --- rust/compiler_builtins.rs | 146 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 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 00000000000..cb4bbf7be4e --- /dev/null +++ b/rust/compiler_builtins.rs @@ -0,0 +1,146 @@ +// 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!("`f32` should not be used", { + __addsf3, + __addsf3vfp, + __aeabi_fcmpeq, + __aeabi_ul2f, + __divsf3, + __divsf3vfp, + __eqsf2, + __eqsf2vfp, + __fixsfdi, + __fixsfsi, + __fixsfti, + __fixunssfdi, + __fixunssfsi, + __fixunssfti, + __floatdisf, + __floatsisf, + __floattisf, + __floatundisf, + __floatunsisf, + __floatuntisf, + __gesf2, + __gesf2vfp, + __gtsf2, + __gtsf2vfp, + __lesf2, + __lesf2vfp, + __ltsf2, + __ltsf2vfp, + __mulsf3, + __mulsf3vfp, + __nesf2, + __nesf2vfp, + __powisf2, + __subsf3, + __subsf3vfp, + __unordsf2, +}); + +define_panicking_intrinsics!("`f64` should not be used", { + __adddf3, + __adddf3vfp, + __aeabi_dcmpeq, + __aeabi_ul2d, + __divdf3, + __divdf3vfp, + __eqdf2, + __eqdf2vfp, + __fixdfdi, + __fixdfsi, + __fixdfti, + __fixunsdfdi, + __fixunsdfsi, + __fixunsdfti, + __floatdidf, + __floatsidf, + __floattidf, + __floatundidf, + __floatunsidf, + __floatuntidf, + __gedf2, + __gedf2vfp, + __gtdf2, + __gtdf2vfp, + __ledf2, + __ledf2vfp, + __ltdf2, + __ltdf2vfp, + __muldf3, + __muldf3vfp, + __nedf2, + __nedf2vfp, + __powidf2, + __subdf3, + __subdf3vfp, + __unorddf2, +}); + +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, +}); + +extern "C" { + fn rust_helper_BUG() -> !; +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo<'_>) -> ! { + unsafe { + rust_helper_BUG(); + } +} -- 2.32.0