Rust fixes for v6.12 (2nd)

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.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEPjU5OPd5QIZ9jqqOGXyLc2htIW0FAmcS5LkACgkQGXyLc2ht
 IW07ghAAxP94zqWzf8bQ4IIgTYrV9WSqR9vMpd31VAPknRJjGUq5dehFxiQxDJ5X
 ibMcpyja8V1CGeOh4qthLJAD/OGw+ANafjLfHM/l9cQRx1uwLEac3h4/YR1x52Ep
 al3ISewhbs3cjko2aa6Gnym3hdYizqkKY9Bca6kvo7k4ZRRmWT3sKAsle6rV93Hw
 q9AjC40XC8iy2VYv/JPvP1zcr3T7ZzCrs3ELG8sLSeR0gZZEmI3e3FOWWHcRlVRa
 uig4SSPvhHVssG8k64CHmzUtVQCApuJuzQGG72Ozs4V5Xxk86ZRE0XzyMXaw15nu
 Mm8s+hDxsFXfESQg0GMCVQ7wnGFSuvRwK3sWALltXmqtGQxkYgcJ3mYtu0sP8p51
 VIzDIomdUfGLxk+sDn7Lnl5PrSLaetUd94nr5qCMmfb2/7/kSaB4aHmML+8ZHCn5
 I4TQONL/pVmmRm97HFaAFOzCaGRWfVoIzQ/cRaQhqK+qrTfRjyFcsMzN+Flp5A58
 c3AgnTVlm4pPqtlLQ1z9BiGYT50dI0fHBOQiisogGsZwwMUqzEMOnbZjbhS/HKSp
 FG8hu/OyzIsNnNqOfQZN4DSTyf4qfIuyTmFM1OAel8zllCwlxy5F2hVp/opwH3/y
 On6CW0lunUBzCXZZ+byWudo7Vg8YpMVHATLqp9FHZpJb8JK688w=
 =Y7fL
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2024-10-19 08:32:47 -07:00
commit 4e6bd4a33a
6 changed files with 51 additions and 24 deletions

View File

@ -838,7 +838,7 @@ config CFI_CLANG
config CFI_ICALL_NORMALIZE_INTEGERS config CFI_ICALL_NORMALIZE_INTEGERS
bool "Normalize CFI tags for integers" bool "Normalize CFI tags for integers"
depends on CFI_CLANG depends on CFI_CLANG
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
help help
This option normalizes the CFI tags for integer types so that all This option normalizes the CFI tags for integer types so that all
integer types of the same size and signedness receive the same CFI 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. This option is necessary for using CFI with Rust. If unsure, say N.
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
def_bool !GCOV_KERNEL && !KASAN def_bool y
depends on CFI_CLANG
depends on $(cc-option,-fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers) depends on $(cc-option,-fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers)
help # With GCOV/KASAN we need this fix: https://github.com/llvm/llvm-project/pull/104826
Is CFI_ICALL_NORMALIZE_INTEGERS supported with the set of compilers depends on CLANG_VERSION >= 190000 || (!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
currently in use?
This option defaults to false if GCOV or KASAN is enabled, as there is config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
an LLVM bug that makes normalized integers tags incompatible with def_bool y
KASAN and GCOV. Kconfig currently does not have the infrastructure to depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
detect whether your rustc compiler contains the fix for this bug, so depends on RUSTC_VERSION >= 107900
it is assumed that it doesn't. If your compiler has the fix, you can # With GCOV/KASAN we need this fix: https://github.com/rust-lang/rust/pull/129373
explicitly enable this option in your config file. The Kconfig logic depends on (RUSTC_LLVM_VERSION >= 190000 && RUSTC_VERSION >= 108200) || \
needed to detect this will be added in a future kernel release. (!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
config CFI_PERMISSIVE config CFI_PERMISSIVE
bool "Use CFI in permissive mode" bool "Use CFI in permissive mode"

View File

@ -62,7 +62,7 @@ config LLD_VERSION
config RUSTC_VERSION config RUSTC_VERSION
int int
default $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC)) default $(rustc-version)
help help
It does not depend on `RUST` since that one may need to use the version It does not depend on `RUST` since that one may need to use the version
in a `depends on`. in a `depends on`.
@ -78,6 +78,10 @@ config RUST_IS_AVAILABLE
In particular, the Makefile target 'rustavailable' is useful to check In particular, the Makefile target 'rustavailable' is useful to check
why the Rust toolchain is not being detected. why the Rust toolchain is not being detected.
config RUSTC_LLVM_VERSION
int
default $(rustc-llvm-version)
config CC_CAN_LINK config CC_CAN_LINK
bool bool
default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT 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 !GCC_PLUGIN_RANDSTRUCT
depends on !RANDSTRUCT depends on !RANDSTRUCT
depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE 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 select CFI_ICALL_NORMALIZE_INTEGERS if CFI_CLANG
depends on !CALL_PADDING || RUSTC_VERSION >= 108100 depends on !CALL_PADDING || RUSTC_VERSION >= 108100
depends on !KASAN_SW_TAGS depends on !KASAN_SW_TAGS

View File

@ -3060,7 +3060,7 @@ config RUST_BUILD_ASSERT_ALLOW
bool "Allow unoptimized build-time assertions" bool "Allow unoptimized build-time assertions"
depends on RUST depends on RUST
help 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 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. or that the optimizer failed to verify the invariant during compilation.

View File

@ -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) m32-flag := $(cc-option-bit,-m32)
m64-flag := $(cc-option-bit,-m64) 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>) # $(rustc-option,<flag>)
# Return y if the Rust compiler supports <flag>, n otherwise # Return y if the Rust compiler supports <flag>, n otherwise
# Calls to this should be guarded so that they are not evaluated if # Calls to this should be guarded so that they are not evaluated if

View File

@ -53,13 +53,11 @@ cc-option = $(call __cc-option, $(CC),\
# cc-option-yn # cc-option-yn
# Usage: flag := $(call cc-option-yn,-march=winchip-c6) # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
cc-option-yn = $(call try-run,\ cc-option-yn = $(if $(call cc-option,$1),y,n)
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
# cc-disable-warning # cc-disable-warning
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
cc-disable-warning = $(call try-run,\ cc-disable-warning = $(if $(call cc-option,-W$(strip $1)),-Wno-$(strip $1))
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
# gcc-min-version # gcc-min-version
# Usage: cflags-$(call gcc-min-version, 70100) += -foo # 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 # __rustc-option
# Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage) # 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,\ __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 # rustc-option
# Usage: rustflags-y += $(call rustc-option,-Cinstrument-coverage,-Zinstrument-coverage) # Usage: rustflags-y += $(call rustc-option,-Cinstrument-coverage,-Zinstrument-coverage)
@ -85,5 +86,4 @@ rustc-option = $(call __rustc-option, $(RUSTC),\
# rustc-option-yn # rustc-option-yn
# Usage: flag := $(call rustc-option-yn,-Cinstrument-coverage) # Usage: flag := $(call rustc-option-yn,-Cinstrument-coverage)
rustc-option-yn = $(call try-run,\ rustc-option-yn = $(if $(call rustc-option,$1),y,n)
$(RUSTC) $(KBUILD_RUSTFLAGS) $(1) --crate-type=rlib /dev/null --out-dir=$$TMPOUT -o "$$TMP",y,n)

22
scripts/rustc-llvm-version.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# Usage: $ ./rustc-llvm-version.sh rustc
#
# Print the LLVM version that the Rust compiler uses in a 6 digit form.
# Convert the version string x.y.z to a canonical up-to-6-digits form.
get_canonical_version()
{
IFS=.
set -- $1
echo $((10000 * $1 + 100 * $2 + $3))
}
if output=$("$@" --version --verbose 2>/dev/null | grep LLVM); then
set -- $output
get_canonical_version $3
else
echo 0
exit 1
fi