Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1008036rwb; Tue, 27 Sep 2022 07:20:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wJNOBpFf572j1hjwgF1cJhGJb/xp5g8xF3wHRJcHgMTgRwCdlcro/6004bo6QT1xgRWEQ X-Received: by 2002:a17:902:f688:b0:179:e82e:2dec with SMTP id l8-20020a170902f68800b00179e82e2decmr4381315plg.25.1664288408933; Tue, 27 Sep 2022 07:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664288408; cv=none; d=google.com; s=arc-20160816; b=zLoDmnRZAFHLw+87VbJwl7LntsGITtJh+UqgPx1b9p8a2sfxP0cixDZQKs/0ywy3+4 IKlVjfqA3YNW+SFxGGtz0Q1Xqtyx0QKAV2Hsw3OELSqMuJ0OfRAABvFyth+bopJicN9s Lzcm6MzWcXXNLXMrxr43vxE8zrvK6pGT4rr+aCvWz3lzwDRr8v0lt6MX63XivxVQY374 HA6Uo3dR0JQguBTDp3LP0ru8d8A4085ri+TrM74Hqa4t2lXv79DEAqAorYW64omNHhW7 z5XFaZsNg34xSxykKkuxBw/jMl5WYxzkmvWFGUIkgdz3esEZpwpOnVyI9riBDFSw6EqC 5G9g== 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=cyQ493+qq8u5o0+OcE/gkfbDmQvy3QlTcbXNbqvwxY4=; b=Xts3wye/atIhtY4uEUGCoOjwew2VQNp7VnaR5PUALE3FSPTnh6YH3uFzaTOOmXZJwb xRL7QrZEEGptShjBjuWCkSluWpGOS7LMiLYE5lhSR//wrV6Z9AXvLcRekDxZ/JlBs1yh CqW3YJSSM1rKRmrZiqiZeERlZ5zOHC3b9Mx+OAGALDphE8w+9TUJ55kGEhRw2UScIQgW eDz5aSffvfmN69uooXJRDqI+aqsedFgSED+rrcWWDJC2Em7mmwxbA6T35rh/2Hk3xTYk 97NnpJZ0KhUxDkDnIWwdQK8jGsESlT5PreR2AQgvurOvQbkjN3pzAn49W9OvoyMUOEGJ JinA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SW1KrfLb; 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 jc22-20020a17090325d600b00176db576db9si1802879plb.275.2022.09.27.07.19.55; Tue, 27 Sep 2022 07:20:08 -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=SW1KrfLb; 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 S232684AbiI0NSu (ORCPT + 99 others); Tue, 27 Sep 2022 09:18:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232608AbiI0NRQ (ORCPT ); Tue, 27 Sep 2022 09:17:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 804EB2DABB; Tue, 27 Sep 2022 06:16: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 dfw.source.kernel.org (Postfix) with ESMTPS id 1F4AD61988; Tue, 27 Sep 2022 13:16:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27D73C43470; Tue, 27 Sep 2022 13:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664284592; bh=RbO4atE4NWF7KW8nDvEGob+G/CG2Xc5lBvbCfINS0VE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SW1KrfLbyWiP3mO6obsKCYthtyxSTEB3jWT3SoACvuDjdqZGIaWPXiObe4xHoLHuJ eK3Zxkx7o7Ejw71qhXsa62ATwfPNJKneQUogyrNaD7oWKV/L8Zuq/jl0m5tNrfVFKx gMLnP+EJZlvJPk05eGeL3dEzNF1gjBz/SnlFsN5Mt+2DviW7BsqISRoWDAMJUdLWJD pxt93fhmcJ80lIFEfByj2rJEjfYEkbzapG6GJ+ZfNQgUdclHsY3imZBkYsHyM32Xwa ykpHq0PsLfhPOmnw/YN7CkjYIwmiPN/XfSGPMjHU6vlk045wW0wN6kbuF8ApDn4k/H 0hLZV7afM8raA== 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 , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Sven Van Asbroeck , Gary Guo , Boqun Feng , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= Subject: [PATCH v10 09/27] rust: add `compiler_builtins` crate Date: Tue, 27 Sep 2022 15:14:40 +0200 Message-Id: <20220927131518.30000-10-ojeda@kernel.org> In-Reply-To: <20220927131518.30000-1-ojeda@kernel.org> References: <20220927131518.30000-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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. Reviewed-by: Kees Cook 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.3