Commit 4e6bd4a3 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'rust-fixes-6.12-2' of https://github.com/Rust-for-Linux/linux

Pull rust fixes from Miguel Ojeda:
 "Toolchain and infrastructure:

   - Fix several issues with the 'rustc-option' macro. It includes a
     refactor from Masahiro of three '{cc,rust}-*' macros, which is not
     a fix but avoids repeating the same commands (which would be
     several lines in the case of 'rustc-option').

   - Fix conditions for 'CONFIG_HAVE_CFI_ICALL_NORMALIZE_INTEGERS'. It
     includes the addition of 'CONFIG_RUSTC_LLVM_VERSION', which is not
     a fix but is needed for the actual fix.

  And a trivial grammar fix"

* tag 'rust-fixes-6.12-2' of https://github.com/Rust-for-Linux/linux:
  cfi: fix conditions for HAVE_CFI_ICALL_NORMALIZE_INTEGERS
  kbuild: rust: add `CONFIG_RUSTC_LLVM_VERSION`
  kbuild: fix issues with rustc-option
  kbuild: refactor cc-option-yn, cc-disable-warning, rust-option-yn macros
  lib/Kconfig.debug: fix grammar in RUST_BUILD_ASSERT_ALLOW
parents 3d5ad2d4 8b8ca9c2
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -838,7 +838,7 @@ config CFI_CLANG
config CFI_ICALL_NORMALIZE_INTEGERS
	bool "Normalize CFI tags for integers"
	depends on CFI_CLANG
	depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS
	depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
	help
	  This option normalizes the CFI tags for integer types so that all
	  integer types of the same size and signedness receive the same CFI
@@ -851,21 +851,19 @@ config CFI_ICALL_NORMALIZE_INTEGERS

	  This option is necessary for using CFI with Rust. If unsure, say N.

config HAVE_CFI_ICALL_NORMALIZE_INTEGERS
	def_bool !GCOV_KERNEL && !KASAN
	depends on CFI_CLANG
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
	def_bool y
	depends on $(cc-option,-fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers)
	help
	  Is CFI_ICALL_NORMALIZE_INTEGERS supported with the set of compilers
	  currently in use?
	# With GCOV/KASAN we need this fix: https://github.com/llvm/llvm-project/pull/104826
	depends on CLANG_VERSION >= 190000 || (!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)

	  This option defaults to false if GCOV or KASAN is enabled, as there is
	  an LLVM bug that makes normalized integers tags incompatible with
	  KASAN and GCOV. Kconfig currently does not have the infrastructure to
	  detect whether your rustc compiler contains the fix for this bug, so
	  it is assumed that it doesn't. If your compiler has the fix, you can
	  explicitly enable this option in your config file. The Kconfig logic
	  needed to detect this will be added in a future kernel release.
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
	def_bool y
	depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
	depends on RUSTC_VERSION >= 107900
	# With GCOV/KASAN we need this fix: https://github.com/rust-lang/rust/pull/129373
	depends on (RUSTC_LLVM_VERSION >= 190000 && RUSTC_VERSION >= 108200) || \
		(!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)

config CFI_PERMISSIVE
	bool "Use CFI in permissive mode"
+6 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ config LLD_VERSION

config RUSTC_VERSION
	int
	default $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
	default $(rustc-version)
	help
	  It does not depend on `RUST` since that one may need to use the version
	  in a `depends on`.
@@ -78,6 +78,10 @@ config RUST_IS_AVAILABLE
	  In particular, the Makefile target 'rustavailable' is useful to check
	  why the Rust toolchain is not being detected.

config RUSTC_LLVM_VERSION
	int
	default $(rustc-llvm-version)

config CC_CAN_LINK
	bool
	default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT
@@ -1946,7 +1950,7 @@ config RUST
	depends on !GCC_PLUGIN_RANDSTRUCT
	depends on !RANDSTRUCT
	depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
	depends on !CFI_CLANG || RUSTC_VERSION >= 107900 && HAVE_CFI_ICALL_NORMALIZE_INTEGERS
	depends on !CFI_CLANG || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
	select CFI_ICALL_NORMALIZE_INTEGERS if CFI_CLANG
	depends on !CALL_PADDING || RUSTC_VERSION >= 108100
	depends on !KASAN_SW_TAGS
+1 −1
Original line number Diff line number Diff line
@@ -3060,7 +3060,7 @@ config RUST_BUILD_ASSERT_ALLOW
	bool "Allow unoptimized build-time assertions"
	depends on RUST
	help
	  Controls how are `build_error!` and `build_assert!` handled during build.
	  Controls how `build_error!` and `build_assert!` are handled during the build.

	  If calls to them exist in the binary, it may indicate a violated invariant
	  or that the optimizer failed to verify the invariant during compilation.
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$
m32-flag := $(cc-option-bit,-m32)
m64-flag := $(cc-option-bit,-m64)

rustc-version := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))

# $(rustc-option,<flag>)
# Return y if the Rust compiler supports <flag>, n otherwise
# Calls to this should be guarded so that they are not evaluated if
+7 −7
Original line number Diff line number Diff line
@@ -53,13 +53,11 @@ cc-option = $(call __cc-option, $(CC),\

# cc-option-yn
# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
cc-option-yn = $(call try-run,\
	$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
cc-option-yn = $(if $(call cc-option,$1),y,n)

# cc-disable-warning
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
cc-disable-warning = $(call try-run,\
	$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
cc-disable-warning = $(if $(call cc-option,-W$(strip $1)),-Wno-$(strip $1))

# gcc-min-version
# Usage: cflags-$(call gcc-min-version, 70100) += -foo
@@ -75,8 +73,11 @@ ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))

# __rustc-option
# Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage)
# TODO: remove RUSTC_BOOTSTRAP=1 when we raise the minimum GNU Make version to 4.4
__rustc-option = $(call try-run,\
	$(1) $(2) $(3) --crate-type=rlib /dev/null --out-dir=$$TMPOUT -o "$$TMP",$(3),$(4))
	echo '#![allow(missing_docs)]#![feature(no_core)]#![no_core]' | RUSTC_BOOTSTRAP=1\
	$(1) --sysroot=/dev/null $(filter-out --sysroot=/dev/null,$(2)) $(3)\
	--crate-type=rlib --out-dir=$(TMPOUT) --emit=obj=- - >/dev/null,$(3),$(4))

# rustc-option
# Usage: rustflags-y += $(call rustc-option,-Cinstrument-coverage,-Zinstrument-coverage)
@@ -85,5 +86,4 @@ rustc-option = $(call __rustc-option, $(RUSTC),\

# rustc-option-yn
# Usage: flag := $(call rustc-option-yn,-Cinstrument-coverage)
rustc-option-yn = $(call try-run,\
	$(RUSTC) $(KBUILD_RUSTFLAGS) $(1) --crate-type=rlib /dev/null --out-dir=$$TMPOUT -o "$$TMP",y,n)
rustc-option-yn = $(if $(call rustc-option,$1),y,n)
Loading