Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kcov: rust: add flags for KCOV with Rust

Rust code is currently not instrumented properly when KCOV is enabled.
Thus, add the relevant flags to perform instrumentation correctly. This
is necessary for efficient fuzzing of Rust code.

The sanitizer-coverage features of LLVM have existed for long enough
that they are available on any LLVM version supported by rustc, so we do
not need any Kconfig feature detection. The coverage level is set to 3,
as that is the level needed by trace-pc.

We do not instrument `core` since when we fuzz the kernel, we are
looking for bugs in the kernel, not the Rust stdlib.

Link: https://lkml.kernel.org/r/20250501-rust-kcov-v2-1-b71e83e9779f@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Co-developed-by: Matthew Maurer <mmaurer@google.com>
Signed-off-by: Matthew Maurer <mmaurer@google.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Tested-by: Aleksandr Nogikh <nogikh@google.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Bill Wendling <morbo@google.com>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Trevor Gross <tmgross@umich.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Alice Ryhl and committed by
Andrew Morton
3bf67171 5a789772

+10
+1
rust/Makefile
··· 492 492 ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) 493 493 $(obj)/core.o: scripts/target.json 494 494 endif 495 + KCOV_INSTRUMENT_core.o := n 495 496 496 497 $(obj)/compiler_builtins.o: private skip_gendwarfksyms = 1 497 498 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
+6
scripts/Makefile.kcov
··· 3 3 kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp 4 4 kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so 5 5 6 + kcov-rflags-y += -Cpasses=sancov-module 7 + kcov-rflags-y += -Cllvm-args=-sanitizer-coverage-level=3 8 + kcov-rflags-y += -Cllvm-args=-sanitizer-coverage-trace-pc 9 + kcov-rflags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -Cllvm-args=-sanitizer-coverage-trace-compares 10 + 6 11 export CFLAGS_KCOV := $(kcov-flags-y) 12 + export RUSTFLAGS_KCOV := $(kcov-rflags-y)
+3
scripts/Makefile.lib
··· 169 169 _c_flags += $(if $(patsubst n%,, \ 170 170 $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(if $(is-kernel-object),$(CONFIG_KCOV_INSTRUMENT_ALL))), \ 171 171 $(CFLAGS_KCOV)) 172 + _rust_flags += $(if $(patsubst n%,, \ 173 + $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(if $(is-kernel-object),$(CONFIG_KCOV_INSTRUMENT_ALL))), \ 174 + $(RUSTFLAGS_KCOV)) 172 175 endif 173 176 174 177 #