Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2304175imn; Mon, 1 Aug 2022 20:01:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4A7rSFS5XM1S3X189qBtx8nOgKJMfuIPZpMLKsK3VJu91WlBFmWz+WTCCTScIWD3ZhLTE X-Received: by 2002:a05:6a00:cc9:b0:52a:b63a:4e5 with SMTP id b9-20020a056a000cc900b0052ab63a04e5mr19148456pfv.59.1659409262240; Mon, 01 Aug 2022 20:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659409262; cv=none; d=google.com; s=arc-20160816; b=C41l0R2FJDTHQaL3S6dtdS0BWEtsVfM+RlII05srNqdBpm2+0T23wQuGFKlIAX6TJz 67193vTvNWmskVXql4Z/EZkhoGKyXRHaE7FvUYpPsj0+Z2hjkFulFhT2FYv7gnxFsMYJ 3Z7aKi9c6Vc+oYp1MVxGvcSjev4mEEtaW89TaM0ihOesTQS5EBH3K6Kf8ev/fwTWZexH RLeSvJHTwqp4eVBMfrVyM64azvbEcbaFapFc77ElHFa+7yvFzXSw5v0V5p4EJiPC8MU5 tHCVgVggH4UK2IFtjkJ1cSRAim1HtiVDn7Ofc65kRsakoaI3VF/FJxJSKY+hA81kB2Xs Frng== 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=P3qqCzPQlEQ4NgDqmcHoDxdAuQK1Jp07PX2EHks0YSU=; b=DYTX4ukUDvnWvV0APkfqyxxlYAVza5N8oXIUenEvgqrbLZO+iSN1COssFQOubU7+ja CsfwNoCgaCuIc69mNwYbZ+WvbNA0fYxLwcnr2ziK265A23Jv2zr3z5KtKC044pfg2jKb rmtS1JMBH2qL836xZRecv+dZWsmstAkSFoe8S0Pxi5U0NRQhLH54gJdYkdWRGm1YA7yJ Ya1YzgCOVCfxvh5dd1q6I+R9fCYD1y97jc7Bdxbv9P7Hy/PzpuSrqIBtwT3NRWDdWM6+ uXlEMSeSxDnKfQ8T7hJoR2hyIbjcMEV40b8CfWBkN0Y+tABYPG2DmeY9WiflctJ0XV/F ngGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bHRMWJBK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd32-20020a056a0027a000b0052518706849si8595729pfb.206.2022.08.01.20.00.45; Mon, 01 Aug 2022 20:01:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bHRMWJBK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235693AbiHBBwq (ORCPT + 99 others); Mon, 1 Aug 2022 21:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235630AbiHBBwW (ORCPT ); Mon, 1 Aug 2022 21:52:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9964481C8; Mon, 1 Aug 2022 18:52:10 -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 77DBFB81910; Tue, 2 Aug 2022 01:52:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFE7AC433D7; Tue, 2 Aug 2022 01:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659405128; bh=83+vP03xffNc1asLJOUpvf/HaJj9CQbs0t4g75FXjqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bHRMWJBKqbrDNLsUSIGjotB/msVb4rZnzitC6YAhd109uZy9jD3B70SdE+wWzUrIX yiIgCce2UBIFR6NtLmgJ9RTB69D1x25fNDugC+k5tpdqDNSDdd0Ux9q6ZOwAGmC5XW dEOSLd2qg00RMrEiRONUClUbrQn8/kTXy+FdlzxBu/JkOaXB1OKUP02G83UB/UNaSn TO4DzprFkaWUQyH7pqxp70WKepn2gqRAwQ3gJpyiR1vy+/vC+7FdP8yA1lr65DCdyi MCPf9Fo0VUelPMgyht+RQABmbSUQQyF3SEPjkurqNlX6g8PxFq5W9g0Fv+mfIuuq3Z VDk30n7OGv/+g== 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 v8 10/31] rust: add `compiler_builtins` crate Date: Tue, 2 Aug 2022 03:49:57 +0200 Message-Id: <20220802015052.10452-11-ojeda@kernel.org> In-Reply-To: <20220802015052.10452-1-ojeda@kernel.org> References: <20220802015052.10452-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 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..e57011b7c3da --- /dev/null +++ b/rust/compiler_builtins.rs @@ -0,0 +1,79 @@ +// 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!("`f32` should not be used", { + __eqsf2, + __gesf2, + __lesf2, + __nesf2, + __unordsf2, +}); + +define_panicking_intrinsics!("`f64` should not be used", { + __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!("`f32` should not be used", { + __aeabi_fcmpeq, + __aeabi_fcmpun, +}); + +#[cfg(target_arch = "arm")] +define_panicking_intrinsics!("`f64` should not be used", { + __aeabi_dcmpun, +}); + +#[cfg(target_arch = "arm")] +define_panicking_intrinsics!("`u64` division/modulo should not be used", { + __aeabi_uldivmod, +}); -- 2.37.1