Skip to content

Commit 4e6bd4a

Browse files
committed
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
2 parents 3d5ad2d + 8b8ca9c commit 4e6bd4a

File tree

6 files changed

+51
-24
lines changed

6 files changed

+51
-24
lines changed

arch/Kconfig

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ config CFI_CLANG
838838
config CFI_ICALL_NORMALIZE_INTEGERS
839839
bool "Normalize CFI tags for integers"
840840
depends on CFI_CLANG
841-
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS
841+
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
842842
help
843843
This option normalizes the CFI tags for integer types so that all
844844
integer types of the same size and signedness receive the same CFI
@@ -851,21 +851,19 @@ config CFI_ICALL_NORMALIZE_INTEGERS
851851

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

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

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

870868
config CFI_PERMISSIVE
871869
bool "Use CFI in permissive mode"

init/Kconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ config LLD_VERSION
6262

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

81+
config RUSTC_LLVM_VERSION
82+
int
83+
default $(rustc-llvm-version)
84+
8185
config CC_CAN_LINK
8286
bool
8387
default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT
@@ -1946,7 +1950,7 @@ config RUST
19461950
depends on !GCC_PLUGIN_RANDSTRUCT
19471951
depends on !RANDSTRUCT
19481952
depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
1949-
depends on !CFI_CLANG || RUSTC_VERSION >= 107900 && HAVE_CFI_ICALL_NORMALIZE_INTEGERS
1953+
depends on !CFI_CLANG || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
19501954
select CFI_ICALL_NORMALIZE_INTEGERS if CFI_CLANG
19511955
depends on !CALL_PADDING || RUSTC_VERSION >= 108100
19521956
depends on !KASAN_SW_TAGS

lib/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,7 @@ config RUST_BUILD_ASSERT_ALLOW
30603060
bool "Allow unoptimized build-time assertions"
30613061
depends on RUST
30623062
help
3063-
Controls how are `build_error!` and `build_assert!` handled during build.
3063+
Controls how `build_error!` and `build_assert!` are handled during the build.
30643064

30653065
If calls to them exist in the binary, it may indicate a violated invariant
30663066
or that the optimizer failed to verify the invariant during compilation.

scripts/Kconfig.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$
6565
m32-flag := $(cc-option-bit,-m32)
6666
m64-flag := $(cc-option-bit,-m64)
6767

68+
rustc-version := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
69+
rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))
70+
6871
# $(rustc-option,<flag>)
6972
# Return y if the Rust compiler supports <flag>, n otherwise
7073
# Calls to this should be guarded so that they are not evaluated if

scripts/Makefile.compiler

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ cc-option = $(call __cc-option, $(CC),\
5353

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

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

6462
# gcc-min-version
6563
# 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))
7573

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

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

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

scripts/rustc-llvm-version.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Usage: $ ./rustc-llvm-version.sh rustc
5+
#
6+
# Print the LLVM version that the Rust compiler uses in a 6 digit form.
7+
8+
# Convert the version string x.y.z to a canonical up-to-6-digits form.
9+
get_canonical_version()
10+
{
11+
IFS=.
12+
set -- $1
13+
echo $((10000 * $1 + 100 * $2 + $3))
14+
}
15+
16+
if output=$("$@" --version --verbose 2>/dev/null | grep LLVM); then
17+
set -- $output
18+
get_canonical_version $3
19+
else
20+
echo 0
21+
exit 1
22+
fi

0 commit comments

Comments
 (0)