[PATCH 3/4] gcov: add MC/DC condition coverage support

Sasha Levin posted 4 patches 3 weeks, 2 days ago
[PATCH 3/4] gcov: add MC/DC condition coverage support
Posted by Sasha Levin 3 weeks, 2 days ago
Add CONFIG_GCOV_CONDITION_COVERAGE option to enable GCC's MC/DC
condition coverage instrumentation (-fcondition-coverage). MC/DC is
required by safety standards such as DO-178C and ISO 26262.

Add -fcondition-coverage and -Wno-error=coverage-too-many-conditions
to CFLAGS_GCOV when enabled. Both flags are gated on the config option
to avoid Clang warnings about unknown options.

Also add -fcondition-coverage to CFLAGS_REMOVE in the x86 UML vDSO
Makefile to prevent instrumentation of userspace vDSO code.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 Makefile                  |  3 +++
 arch/x86/um/vdso/Makefile |  4 ++--
 kernel/gcov/Kconfig       | 15 +++++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 2b15f0b4a0cb5..5b0657cd3e534 100644
--- a/Makefile
+++ b/Makefile
@@ -807,6 +807,9 @@ CFLAGS_GCOV	:= -fprofile-arcs -ftest-coverage
 ifdef CONFIG_CC_IS_GCC
 CFLAGS_GCOV	+= -fno-tree-loop-im
 endif
+ifdef CONFIG_GCOV_CONDITION_COVERAGE
+CFLAGS_GCOV	+= -fcondition-coverage -Wno-error=coverage-too-many-conditions
+endif
 export CFLAGS_GCOV
 
 # The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
diff --git a/arch/x86/um/vdso/Makefile b/arch/x86/um/vdso/Makefile
index 8a7c8b37cb6eb..3c8909f96a4c0 100644
--- a/arch/x86/um/vdso/Makefile
+++ b/arch/x86/um/vdso/Makefile
@@ -44,8 +44,8 @@ $(vobjs): KBUILD_CFLAGS += $(CFL)
 #
 # vDSO code runs in userspace and -pg doesn't help with profiling anyway.
 #
-CFLAGS_REMOVE_vdso-note.o = -pg -fprofile-arcs -ftest-coverage
-CFLAGS_REMOVE_um_vdso.o = -pg -fprofile-arcs -ftest-coverage
+CFLAGS_REMOVE_vdso-note.o = -pg -fprofile-arcs -ftest-coverage -fcondition-coverage
+CFLAGS_REMOVE_um_vdso.o = -pg -fprofile-arcs -ftest-coverage -fcondition-coverage
 
 #
 # The DSO images are built using a special linker script.
diff --git a/kernel/gcov/Kconfig b/kernel/gcov/Kconfig
index 04f4ebdc3cf59..7939c8f5ced3c 100644
--- a/kernel/gcov/Kconfig
+++ b/kernel/gcov/Kconfig
@@ -52,4 +52,19 @@ config GCOV_PROFILE_ALL
 	larger and run slower. Also be sure to exclude files from profiling
 	which are not linked to the kernel image to prevent linker errors.
 
+config GCOV_CONDITION_COVERAGE
+	bool "Enable MC/DC condition coverage instrumentation"
+	depends on GCOV_KERNEL
+	depends on CC_HAS_CONDITION_COVERAGE
+	default n
+	help
+	This option adds Modified Condition/Decision Coverage (MC/DC)
+	instrumentation using GCC's -fcondition-coverage flag. MC/DC
+	coverage data can be viewed using gcov --conditions.
+
+	MC/DC is required by safety standards such as DO-178C (avionics)
+	and ISO 26262 (automotive).
+
+	This increases instrumentation overhead. If unsure, say N.
+
 endmenu
-- 
2.51.0