Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1895882rwb; Fri, 5 Aug 2022 09:29:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR41r1sW06tNzRSQv41HGFBEZODIjylm/5Ocaf2cVoYjNuKHCYOOLK6ILKMF0qHnr6gslffB X-Received: by 2002:a63:89c1:0:b0:41d:112:2167 with SMTP id v184-20020a6389c1000000b0041d01122167mr3872648pgd.437.1659716963341; Fri, 05 Aug 2022 09:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659716963; cv=none; d=google.com; s=arc-20160816; b=FgSZqFjn+PaQKJodGMfvfuVnue0NgxiSn+yN16ehJn84XIALvzzrVOfB0atI79w3Th Q+ExYzHVz8IaADG+qXMjPp9jAL3kKwLMXt30ijBsGpnWVHJXSTLiPOq6OB8bHjLSuiFw 6Swbg8/azCYE3+ON5+zHAXwPHdHQhoI1oDCaq/QB3TmPiRXEx/jhzoIg8Fu6hr8b/JP/ yK/kVPMUFXOGL2GCwl6YMZnAQALns7IFw7lSo1a7DblYycrHHJlh8TaUZvq+GDPnupJp MXDpULhfXmUiDaYBDnWoultv4e/MveSQ0qdHl1HmKPa25/Njal89oSCCqhad7EAauDMc 7ieQ== 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=b5c4pDOfN0tJ06pnZs2mhwqW7mSmAlASNUDAfjr8d5M=; b=vPJ29pkSqhzCizkpj1HqpPOzltD6DD13Mai1dUsC5cW6SKWVZ8FNGif7Gr4+7jfR2G To7KjAiV4IM15YjiWRskw2Z3sJ/WVmB7e23yFBd5JNScLrxeisktk37wJnpvTATDPrJT xD45XI19Ptb83QKy7Qwo4cd9Jz5F2IqnuLZ/1jF1VTHf2/0Ksa1r/VJNttAvCCM7MyTN P4Rv9o2GOgM7ZFRJT7kE+RkIU/GjSEqGC/SSHirzqt85T+Y9/ON0hfHi91LdyvmtdAPd cBtMlmFPEamMIiMr8Y6NZLf+qnAwdGX/sHy9NP6hvU0pIlGjLG27sopRIrrTpUUndYJN OU7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KZgzX49s; 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 w11-20020a63474b000000b0041ccdd4ae76si3620458pgk.372.2022.08.05.09.29.09; Fri, 05 Aug 2022 09:29:23 -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=KZgzX49s; 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 S241112AbiHEPoa (ORCPT + 99 others); Fri, 5 Aug 2022 11:44:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241217AbiHEPnu (ORCPT ); Fri, 5 Aug 2022 11:43:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F25965C9C5; Fri, 5 Aug 2022 08:43:34 -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 78810B82985; Fri, 5 Aug 2022 15:43:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51A84C433B5; Fri, 5 Aug 2022 15:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659714212; bh=A6iE9dGgpooXK06FIGFB3nx2/DurNoGR1fSLObr1bQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZgzX49sIoma/oq+oM86hibh1+DLLsdbrN30c7vQAL8ecBntUNuwLkuRbuYMjBZSc /BlIdONU8gm35OhBTI3P0kmdk41LAeuZL1cF7SPR/orYeDsVzY0x3gHCYCjdM0MO6f HlOoezdJvUi4+QqID+wBClI0Bl94jkXqkNF0BtaqR3DV5Zex/wmszPrDVMEcygY8Np FtipzN2RXDv2MnMbo8maTboPnOHHyi7cuYuMZ4GkBgt3KnboM9WzegZd/8fTA9+BMD 5SJZxm0N6yc2FOJRXWF7lo/CsjB4CpfVSQkUsX8CBqr2C/pmkrA5+CjV5Y76eqIRth nlwt8tipIi8mw== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, patches@lists.linux.dev, Jarkko Sakkinen , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Sven Van Asbroeck , Gary Guo , Boqun Feng , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= Subject: [PATCH v9 09/27] rust: add `compiler_builtins` crate Date: Fri, 5 Aug 2022 17:41:54 +0200 Message-Id: <20220805154231.31257-10-ojeda@kernel.org> In-Reply-To: <20220805154231.31257-1-ojeda@kernel.org> References: <20220805154231.31257-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,T_SCC_BODY_TEXT_LINE 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 | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 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..f8f39a3e6855 --- /dev/null +++ b/rust/compiler_builtins.rs @@ -0,0 +1,63 @@ +// 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, +}); -- 2.37.1