From patchwork Mon Jul 1 18:36:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13718541 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 105BB16FF47; Mon, 1 Jul 2024 18:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859024; cv=none; b=n1vZQBq8qU4pBWkqRRWqMcekkMSa7q2vjvsjPbGrLt7Odd9PvDVzOM1Y++bN9oi6ylrstJTUKrf0i26tmKJxIW+P6JjJXssVBCW8NIWD65Vh1NePU5/PO8DFwd1Au1mc9i89WJHtlrdKYDtXIWWoz9qRYEb315XT26xn90IbsCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859024; c=relaxed/simple; bh=tP2HDN4TTaXAnnWUMMPiix526ZI8EAisK4CECsr1ppc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gioZYe8ZG7WsoucDmlpZX94ORTuINsdGm3BE2oxV/E9BNloq7CBB3M4P//Ben0mGq5w7l1ImYugIOkadm8LqcxGPVyipfJ2Bcsb8si6i7xEoTQqacyb5fuKh2DtjpOvknEum6Hzg1roc6sBu6CWSJIm4wjlgPLZ3vRedn1RORQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kIUprjZO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kIUprjZO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4B17C4AF0A; Mon, 1 Jul 2024 18:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719859023; bh=tP2HDN4TTaXAnnWUMMPiix526ZI8EAisK4CECsr1ppc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kIUprjZO8piOWDu2TFZ1/ng5KmWLRXlQTziabtx1lcJ/Qax6DeJlUTcj6POglNAnH r+aJEwf/rXbwfzHJL+5tMi9QxnAVetsqvyaQU0mwvHYy9DO2fpzBm+DKzCFZ6PM/D6 A7enPIRZOzpUMDqc4Ojur9hdIITkzutXGhkcWAoCmzBqh1uKwT5KB987K+796qlTW4 ISHVn6334vZB8wSUfMbmW8cE8mOcu8MrDtHXikoWMZrHij0hjaMliPKUGT8O1lj7kD FkXUhQ4YfwZlG0cuyMrJEKfl612CGUD35n5On6jViAgFvJEyoGAlt1C6p4uHTQa9x6 tBIY9dPBiDggA== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Masahiro Yamada , Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org Subject: [PATCH 04/13] rust: relax most deny-level lints to warnings Date: Mon, 1 Jul 2024 20:36:14 +0200 Message-ID: <20240701183625.665574-5-ojeda@kernel.org> In-Reply-To: <20240701183625.665574-1-ojeda@kernel.org> References: <20240701183625.665574-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since we are starting to support several Rust toolchains, lints (including Clippy ones) now may behave differently and lint groups may include new lints. Therefore, to maximize the chances a given version works, relax some deny-level lints to warnings. It may also make our lives a bit easier while developing new code or refactoring. To be clear, the requirements for in-tree code are still the same, since Rust code still needs to be warning-free (patches should be clean under `WERROR=y`) and the set of lints is not changed. `unsafe_op_in_unsafe_fn` is left unmodified, i.e. as an error, since 1) it is simple enough that it should not have false positives (unlike e.g. `rust_2018_idioms`'s `explicit_outlives_requirements`) and 2) it is becoming the default in the language (warn-by-default in Rust 2024 [1] and ideally an error later on) and thus it should also be very well tested. Link: https://github.com/rust-lang/rust/pull/112038 [1] Signed-off-by: Miguel Ojeda Reviewed-by: Finn Behrens --- Makefile | 22 +++++++++++----------- rust/Makefile | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4d36f943b3b1..056176a55d63 100644 --- a/Makefile +++ b/Makefile @@ -461,17 +461,17 @@ KBUILD_USERLDFLAGS := $(USERLDFLAGS) # host programs. export rust_common_flags := --edition=2021 \ -Zbinary_dep_depinfo=y \ - -Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \ - -Dunreachable_pub -Dnon_ascii_idents \ + -Dunsafe_op_in_unsafe_fn -Wrust_2018_idioms \ + -Wunreachable_pub -Wnon_ascii_idents \ -Wmissing_docs \ - -Drustdoc::missing_crate_level_docs \ - -Dclippy::correctness -Dclippy::style \ - -Dclippy::suspicious -Dclippy::complexity \ - -Dclippy::perf \ - -Dclippy::let_unit_value -Dclippy::mut_mut \ - -Dclippy::needless_bitwise_bool \ - -Dclippy::needless_continue \ - -Dclippy::no_mangle_with_rust_abi \ + -Wrustdoc::missing_crate_level_docs \ + -Wclippy::correctness -Wclippy::style \ + -Wclippy::suspicious -Wclippy::complexity \ + -Wclippy::perf \ + -Wclippy::let_unit_value -Wclippy::mut_mut \ + -Wclippy::needless_bitwise_bool \ + -Wclippy::needless_continue \ + -Wclippy::no_mangle_with_rust_abi \ -Wclippy::dbg_macro KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS) @@ -573,7 +573,7 @@ KBUILD_RUSTFLAGS := $(rust_common_flags) \ -Csymbol-mangling-version=v0 \ -Crelocation-model=static \ -Zfunction-sections=n \ - -Dclippy::float_arithmetic + -Wclippy::float_arithmetic KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := diff --git a/rust/Makefile b/rust/Makefile index f70d5e244fee..4c03e53d3084 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -421,7 +421,7 @@ ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) endif $(obj)/core.o: private skip_clippy = 1 -$(obj)/core.o: private skip_flags = -Dunreachable_pub +$(obj)/core.o: private skip_flags = -Wunreachable_pub $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) $(obj)/core.o: private rustc_target_flags = $(core-cfgs) $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE @@ -435,7 +435,7 @@ $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE +$(call if_changed_dep,rustc_library) $(obj)/alloc.o: private skip_clippy = 1 -$(obj)/alloc.o: private skip_flags = -Dunreachable_pub +$(obj)/alloc.o: private skip_flags = -Wunreachable_pub $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs) $(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib.rs $(obj)/compiler_builtins.o FORCE +$(call if_changed_dep,rustc_library) From patchwork Mon Jul 1 18:36:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13718542 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7D8116F273; Mon, 1 Jul 2024 18:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859028; cv=none; b=NUi+c8btXLbstDLfCcogp0kndONB6xqdwsoQUV2yrPgjaVPHtCu/5WIdH2REOQEIoPkE7qqZz2CHIxG1l+Qs8FzbBQM4Ea1wZ7EnZ/is8hiAJKM8gs9fXQVRpAsOr4aPwD9ljbtr4zxhqyhTajq1JuitYC4N/utmQeW1qMkgwPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859028; c=relaxed/simple; bh=OMurDCisKjAllrHkCPJ/1qS7Xxemz+3k0gh+ghbhMAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SN+SzqsiZIl1ZnjLHFNp3Kv8RPkgm23H/TZ91vglF9L3u23QEiR+MKpywOr2oen1fsdxjjpG+aL/wjVLDomh8IZvNWNqBUNs4vVd2u7lRxkeAXNQlEtywpUDIA5Yh7SXjss61HfDsbw3bEIFpar/MdJKj+OjgiaSIVadfedkQAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GrZ6dsTs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GrZ6dsTs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 996A9C4AF0C; Mon, 1 Jul 2024 18:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719859028; bh=OMurDCisKjAllrHkCPJ/1qS7Xxemz+3k0gh+ghbhMAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GrZ6dsTsVGz9WjzTPMaz73LfWAQDl6VlNpXXpqbAt9NmsT9eky7xzxvQWP5P7jHlm T4J8BP3oIALDO5pHzU7//fOJQvYjbN7YxrBqropcGfuHzSvu5ESroSHBW84miKkiss RmHon2B1YtjBZbPcJI3eckyX6irPYRuy7j0i61faR6Fk2vzuMpcWalSoC+p8P10RGL In1cHf7KvtbluHaFWDHRBce01gwPbaUOV6ApFjgeuumySuTbG0ZskKbkNKELnJw4qB tPQ1YNA/may9x2Mu7Fy8gCOR3WAE+U6BaoLjL+g0nqxqhvJUyYSwaMJxU98PvIgGqU d22kAB2UIN6FQ== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Masahiro Yamada , Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org Subject: [PATCH 05/13] rust: simplify Clippy warning flags set Date: Mon, 1 Jul 2024 20:36:15 +0200 Message-ID: <20240701183625.665574-6-ojeda@kernel.org> In-Reply-To: <20240701183625.665574-1-ojeda@kernel.org> References: <20240701183625.665574-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 All Clippy lint groups that we enable, except `correctness`, have a default `warn` level, thus they may be removed now that we relaxed all lints to `warn`. Moreover, Clippy provides an `all` lint group that covers the groups we enable by default. Thus just use `all` instead -- the only change is that, if Clippy introduces a new lint group or splits an existing one, we will cover that one automatically. In addition, `let_unit_value` is in `style` since Rust 1.62.0, thus it does not need to be enabled manually. Signed-off-by: Miguel Ojeda Reviewed-by: Finn Behrens --- Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 056176a55d63..3f43f03f855e 100644 --- a/Makefile +++ b/Makefile @@ -465,10 +465,8 @@ export rust_common_flags := --edition=2021 \ -Wunreachable_pub -Wnon_ascii_idents \ -Wmissing_docs \ -Wrustdoc::missing_crate_level_docs \ - -Wclippy::correctness -Wclippy::style \ - -Wclippy::suspicious -Wclippy::complexity \ - -Wclippy::perf \ - -Wclippy::let_unit_value -Wclippy::mut_mut \ + -Wclippy::all \ + -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ -Wclippy::needless_continue \ -Wclippy::no_mangle_with_rust_abi \ From patchwork Mon Jul 1 18:36:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13718543 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F79E172762; Mon, 1 Jul 2024 18:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859055; cv=none; b=XCop/B2Fbl7cr3CVsLyg0/pQ4vIAnqRw7aFrUM9M9JB8dPeTEu5wwXBz1Hh4+O2kBvRJ2O2h0ZgpuqYpRpNCCV1BWdiZpAhN5oohjuzv9Qzbck/2qv8i6iT9hzV68i+oKi7TN1mgAIePLOVTiZc+xZcaETBosEbM+msbVQsFSn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859055; c=relaxed/simple; bh=i7Bpv+VkURk8Dn67Vw4shxE1NjlQlY/Yr/USg4ZFdIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EGC5VOcbszzPH4zC8Go33v2PHDirjHe2EojrwkWObHCwY7ltmV8/KO4J0CSLF4aExfA8DdLy56seqHUhrRaMwu9rA/ZwEK1/9g4TornaRQFG7+RtY0op/AmpHMGN5UghMdaUbW4atBAvt3CI8F/hdXl9sIwmF5i2eODZYuRd9G4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ev3LeNfS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ev3LeNfS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADBD8C4AF0A; Mon, 1 Jul 2024 18:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719859054; bh=i7Bpv+VkURk8Dn67Vw4shxE1NjlQlY/Yr/USg4ZFdIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ev3LeNfSuNuWP66VnIObsN5piFJIp+D9E1BVdCRjKtmgAUSmWejmivQVa6syEA/6b 4HdnTuQa9hVxh+jwAInPsBA/EH0jwdwRKYR/Yz2mQv5FD1n5TazevfxgGyky5dyIFz sw5MDEPXrHPjcKiuTV7F7C5bvFT53QdPRrlcZi7v3S+Cahv30HiSccvs2JQyrCysuw 4/3kzN5l/sAhi87uEq9GX23J/86zIRgcnKQr9EkDY2ImtD6DIQfiy86+KnY0V8Lv8A Lwedkso4XTmSMhzNxXJQrVRve2+FtUH5y5NMIwEYcNFKE+8AuOYqqhKk9ykF3H+WUn CFnA6ZC+BFfsg== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Masahiro Yamada , Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org Subject: [PATCH 11/13] kbuild: rust: add `rustc-version` support Date: Mon, 1 Jul 2024 20:36:21 +0200 Message-ID: <20240701183625.665574-12-ojeda@kernel.org> In-Reply-To: <20240701183625.665574-1-ojeda@kernel.org> References: <20240701183625.665574-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we are starting to support several Rust versions, introduce `rustc-version` support, mimicking the C side: - `scripts/rustc-version.sh`, that mimics the other version scripts (with one more digit, e.g. Rust 1.79.0 is 107900). - `rustc-{info,name,version}` Kbuild macros. - `CONFIG_RUSTC_VERSION` Kconfig symbol that calls `rustc-version`. - `rustc-min-version` Kbuild macro that uses `CONFIG_RUSTC_VERSION`. With these, we can easily support flags conditionally depending on `rustc`'s version -- a user comes in the next patch. Another user will be the `-Ctarget-feature=+reserve-x18`/`-Zfixed-x18` arm64 flags [1]. Link: https://lore.kernel.org/rust-for-linux/20240305-shadow-call-stack-v2-1-c7b4a3f4d616@google.com/ [1] Signed-off-by: Miguel Ojeda Reviewed-by: Finn Behrens --- init/Kconfig | 6 +++++ scripts/Kconfig.include | 6 +++++ scripts/Makefile.compiler | 4 +++ scripts/rustc-version.sh | 52 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100755 scripts/rustc-version.sh diff --git a/init/Kconfig b/init/Kconfig index 94e20d3b99d4..7d344f248785 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1920,6 +1920,12 @@ config RUST If unsure, say N. +config RUSTC_VERSION + int + depends on RUST + default $(rustc-version) + default 0 + config RUSTC_VERSION_TEXT string depends on RUST diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index 3ee8ecfb8c04..82ab889725db 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -45,6 +45,12 @@ $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this C compiler is not cc-name := $(shell,set -- $(cc-info) && echo $1) cc-version := $(shell,set -- $(cc-info) && echo $2) +# Get the Rust compiler name, version, and error out if it is not supported. +rustc-info := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC)) +$(error-if,$(success,test -z "$(rustc-info)"),Sorry$(comma) this Rust compiler is not supported.) +rustc-name := $(shell,set -- $(rustc-info) && echo $1) +rustc-version := $(shell,set -- $(rustc-info) && echo $2) + # Get the assembler name, version, and error out if it is not supported. as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS)) $(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.) diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler index 92be0c9a13ee..17eaa085b59c 100644 --- a/scripts/Makefile.compiler +++ b/scripts/Makefile.compiler @@ -69,6 +69,10 @@ gcc-min-version = $(call test-ge, $(CONFIG_GCC_VERSION), $1) # Usage: cflags-$(call clang-min-version, 110000) += -foo clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1) +# rustc-min-version +# Usage: rustflags-$(call rustc-min-version, 107900) += -foo +rustc-min-version = $(call test-ge, $(CONFIG_RUSTC_VERSION), $1) + # ld-option # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) diff --git a/scripts/rustc-version.sh b/scripts/rustc-version.sh new file mode 100755 index 000000000000..4e658fd55ae6 --- /dev/null +++ b/scripts/rustc-version.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Print the Rust compiler name and its version in a 5 or 6-digit form. +# Also, perform the minimum version check. + +set -e + +# Convert the version string x.y.z to a canonical up-to-7-digits form. +# +# Note that this function uses one more digit (compared to other +# instances in other version scripts) to give a bit more space to +# `rustc` since it will reach 1.100.0 in late 2026. +get_canonical_version() +{ + IFS=. + set -- $1 + echo $((100000 * $1 + 100 * $2 + $3)) +} + +orig_args="$@" + +set -- $("$@" --version) + +name=$1 + +min_tool_version=$(dirname $0)/min-tool-version.sh + +case "$name" in +rustc) + version=$2 + min_version=$($min_tool_version rustc) + ;; +*) + echo "$orig_args: unknown Rust compiler" >&2 + exit 1 + ;; +esac + +rustcversion=$(get_canonical_version $version) +min_rustcversion=$(get_canonical_version $min_version) + +if [ "$rustcversion" -lt "$min_rustcversion" ]; then + echo >&2 "***" + echo >&2 "*** Rust compiler is too old." + echo >&2 "*** Your $name version: $version" + echo >&2 "*** Minimum $name version: $min_version" + echo >&2 "***" + exit 1 +fi + +echo $name $rustcversion From patchwork Mon Jul 1 18:36:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13718544 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2A7F16F900; Mon, 1 Jul 2024 18:37:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859060; cv=none; b=YfOzSWZ4VIUlYNC3Ns4ih1HVP38hn+e+zdMAYDwhq2HGtGhPkg+oeuVwtycxjB8VpOTwEbsUNFpniU86cKlygdCkpqPVs9w3P1Xlne2pzt2HyNy35I6dtofiBBOMOraYEKHsrT0lcxpg2qPOQ58Ta5DUEaMsetOPHzLzGnnbrHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719859060; c=relaxed/simple; bh=2XqbItBT6W0jpAHdXZZnJ/RMQas8XvOvkK61Z6nFi38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=arnQm6ZBMeMRZYBIrc793nrQx9RZZjsCuPn40CrgYmAjGSw1LXy2/VrO9FZnBTmrg73lbG2ZChhGWRai5xL1T7Itx28ndUQ3ICLltTE2nFIBdNayKGMaWNapIECvvhEuv4llEQMAz8aHaWThjIpPby3vxN5ks72yVwC/N9pwes8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ie3BKoZp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ie3BKoZp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B194C4AF0D; Mon, 1 Jul 2024 18:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719859059; bh=2XqbItBT6W0jpAHdXZZnJ/RMQas8XvOvkK61Z6nFi38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ie3BKoZpSSbHPwvXlAwrIkj76dFHILSWUSrvJQjDG5wSUJeaNtdAiWB3o4oxIA744 0YANQaccGhL9ybuNh8J0pab4q6wFgljh/vZgfKPjJ1xv2uphVNXtB1586BF3kyoO2T WVXHEkKBlhHR3+eFBBt/I+nPjRPTYpEFLevS53C8zw3ORLKYa9ZUlGAQhSCJFij4wy sWa7c7saZP7EVdDoY7apvC6xsTLiTEJdMw6wS3gQyzCMQP/lGN8BnUfRN8S8IjjW5/ /qiUZKSdGBB+RcdiGDOLZFZlxPX+EX7COBYEoaqTnkbQDKudtRvWL8fV0jmceWcMPw A37Wid+wDjVMg== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , linux-kbuild@vger.kernel.org Subject: [PATCH 12/13] rust: support the new `-Zub-checks` flag Date: Mon, 1 Jul 2024 20:36:22 +0200 Message-ID: <20240701183625.665574-13-ojeda@kernel.org> In-Reply-To: <20240701183625.665574-1-ojeda@kernel.org> References: <20240701183625.665574-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rust 1.79.0 has introduced a new codegen flag, `-Zub-checks` [1], to allow to independently configure (from `-Cdebug-assertions`) whether the extra runtime checks for UB are emitted, in a similar fashion to `-Coverflow-checks`. This allows to configure the kernel with only the UB checks enabled, but not the `debug_assert!`s; or vice versa, e.g. [2]. It also showcases how `RUSTC_VERSION` and the Kbuild macros, introduced in the previous commit, can be used. Link: https://github.com/rust-lang/compiler-team/issues/725 [1] Link: https://godbolt.org/z/jY69ezx5K [2] Signed-off-by: Miguel Ojeda Reviewed-by: Finn Behrens --- Makefile | 9 +++++++-- lib/Kconfig.debug | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3f43f03f855e..c0cb5c237c26 100644 --- a/Makefile +++ b/Makefile @@ -820,10 +820,15 @@ KBUILD_CFLAGS += -Os KBUILD_RUSTFLAGS += -Copt-level=s endif -# Always set `debug-assertions` and `overflow-checks` because their default -# depends on `opt-level` and `debug-assertions`, respectively. +# Always set `debug-assertions` because its default depends on `opt-level`. KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n) + +# Always set `overflow-checks` and `ub-checks` because their default depends on +# `debug-assertions`. KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n) +ifeq ($(call rustc-min-version, 107900),y) +KBUILD_RUSTFLAGS += -Zub-checks=$(if $(CONFIG_RUST_UNDEFINED_BEHAVIOR_CHECKS),y,n) +endif # Tell gcc to never replace conditional load with a non-conditional one ifdef CONFIG_CC_IS_GCC diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 59b6765d86b8..6b4f512f9e13 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -3020,6 +3020,24 @@ config RUST_OVERFLOW_CHECKS If unsure, say Y. +config RUST_UNDEFINED_BEHAVIOR_CHECKS + bool "Undefined Behavior checks" + depends on RUST && RUSTC_VERSION >= 107900 + help + Enables rustc's `-Zub-checks` codegen option. + + This flag allows you to control whether additional runtime checks that + detect some causes of Undefined Behavior at runtime will be emitted. + When enabled, a Rust panic will occur if UB is detected. + + All checks are generated on a best-effort basis; even if there is a check + implemented for some cause of Undefined Behavior, it may be possible for + the check to not fire. + + Note that this will apply to all Rust code, including `core`. + + If unsure, say N. + config RUST_BUILD_ASSERT_ALLOW bool "Allow unoptimized build-time assertions" depends on RUST