Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5181618pxb; Sun, 13 Feb 2022 10:40:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAOQkRaCudQTSWIorB8UHkfEKYQcW0QIjPf5OsugcFEs+ekoIYpXAulZSvPRMXDQTHBXci X-Received: by 2002:a17:903:185:: with SMTP id z5mr8493672plg.71.1644777647825; Sun, 13 Feb 2022 10:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644777647; cv=none; d=google.com; s=arc-20160816; b=zI8cQ4MS6ZVqwyWoXAc+SEFfloQu2hWbo4SFE4hyIgn98VZULDsvyxYEVBWB23EzOp mV5lqBRgYLId6sj2OGGtLu6tGToXEp+gWtgq/aLRs/MOKVMrdawc3QstIROoLutU0D/1 HW18ui36RKZ1/yumO0htcWmvaA5iXrqJAexChEUEGEN2mWd0UO8QTwkQWrm9O8j2bYHY b7bHono1byo+0YJOLoCqQVYDI86zggjpAgSX/2jUFbFAuSOV42DJdbYL0igjUvoc6PpE kxuG1fJBRKevFW1G6T+g29y771w9z4o5TngIQbtqiXZCeG4JOSb9TnZn+jSS6mG+3i5m nD+Q== 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=YXNspB7oVBwnr+WYVVsJzjOdAR6FtWbdt6HcY71uiNU=; b=XAUX+W6v6rvllxSvahwSGfP1C5YFm96vrbtosL/ZtMzktVhvKoeomoWC9SV4CEzFqx lS3/DRd7SAim69p+7xLWPyuSmiaz3Oo8kRRk+0l+yrALmhmzS3LbWjc0NSyzSNmnY+9E F3N6mhDMTwT0IdfTv4j6hbwj8qt0u/vwFvwDxVCZSTHE5/CpxsG/a9viRWmzmLleisw7 brNWcBT2jFXrh9PIxmZxo2aalPhPAx1ew7jSflm5xt1VeybVDfPPMupgxBXH1DqdF8Cg nZ40nMknYeESyVFvRV+dFvIwycMSVHc190zrqaETOP60ap8f9VM/HI6yUuQ7QbX0Y864 8J1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J00XU75W; 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 u11si31763851pgp.314.2022.02.13.10.40.30; Sun, 13 Feb 2022 10:40:47 -0800 (PST) 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=J00XU75W; 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 S235464AbiBLNFm (ORCPT + 99 others); Sat, 12 Feb 2022 08:05:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232461AbiBLNFf (ORCPT ); Sat, 12 Feb 2022 08:05:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE7C226AF9; Sat, 12 Feb 2022 05:05:22 -0800 (PST) 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 F32B260E9A; Sat, 12 Feb 2022 13:05:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B641C36AE2; Sat, 12 Feb 2022 13:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644671121; bh=Di4mwje8+RhmgN7c9XcjMHtGn4piSBr1VjnN0XzxP/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J00XU75WYGtsftINIjrSgmRRvgk+KMg3xlkGVvko3HTKEZy/Xum7oAe2+Pfgekqoi cChewpu9r2JyAelhceDBA8Y+inV9AJOy/MC8rUWIug5/S3QAeC6DTz9ahykfb0hyGY T/x7XwN4AfZjo9h/UJjsmvE056K/prIooy//bzWewoNCum4KGQe7ruyCA6HmmV3GBu hDwTXBwWJHKTC3NLnhNbWqDe+C7zOuXKPA0WVPkyirFjprKjFD09bL93WL7q2gHEFr oOfAoHa8x2sDWTIiSOjSIpu9G3dKAGFuZSzfWuLx8/UqtVjewc3EANXJ81OV10A4UZ ZkqXIHtRWpC/w== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Sven Van Asbroeck , Gary Guo Subject: [PATCH v4 05/20] rust: add `compiler_builtins` crate Date: Sat, 12 Feb 2022 14:03:31 +0100 Message-Id: <20220212130410.6901-6-ojeda@kernel.org> In-Reply-To: <20220212130410.6901-1-ojeda@kernel.org> References: <20220212130410.6901-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 | 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..80ca4c0dcd24 --- /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 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!("`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.35.1