-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BACKPORT: kcov: test compiler capability in Kconfig and correct depen…
…dency Work around missing cc-option support in Kconfig by checking required compiler flags in Makefile. (Upstream commit 5aadfde.) As Documentation/kbuild/kconfig-language.txt notes, 'select' should be be used with care - it forces a lower limit of another symbol, ignoring the dependency. Currently, KCOV can select GCC_PLUGINS even if arch does not select HAVE_GCC_PLUGINS. This could cause the unmet direct dependency. Now that Kconfig can test compiler capability, let's handle this in a more sophisticated way. There are two ways to enable KCOV; use the compiler that natively supports -fsanitize-coverage=trace-pc, or build the SANCOV plugin if the compiler has ability to build GCC plugins. Hence, the correct dependency for KCOV is: depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS You do not need to build the SANCOV plugin if the compiler already supports -fsanitize-coverage=trace-pc. Hence, the select should be: select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC With this, GCC_PLUGIN_SANCOV is selected only when necessary, so scripts/Makefile.gcc-plugins can be cleaner. I also cleaned up Kconfig and scripts/Makefile.kcov as well. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Kees Cook <keescook@chromium.org> Change-Id: Iad9110eb7b6ecef6dfcec38cf483699c1b85af01 Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Bug: 147413187
- Loading branch information
1 parent
0f0fe8e
commit c093b58
Showing
4 changed files
with
33 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
ifdef CONFIG_KCOV | ||
CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) | ||
ifeq ($(CONFIG_KCOV_ENABLE_COMPARISONS),y) | ||
CFLAGS_KCOV += $(call cc-option,-fsanitize-coverage=trace-cmp,) | ||
|
||
ifeq ($(call cc-option, -fsanitize-coverage=trace-pc -Werror),) | ||
ifneq ($(CONFIG_COMPILE_TEST),y) | ||
$(error Cannot use CONFIG_KCOV: \ | ||
-fsanitize-coverage=trace-pc is not supported by compiler) | ||
endif | ||
endif | ||
|
||
ifdef CONFIG_KCOV_ENABLE_COMPARISONS | ||
ifeq ($(call cc-option, -fsanitize-coverage=trace-cmp -Werror),) | ||
ifneq ($(CONFIG_COMPILE_TEST),y) | ||
$(error Cannot use CONFIG_KCOV_ENABLE_COMPARISONS: \ | ||
-fsanitize-coverage=trace-cmp is not supported by compiler) | ||
endif | ||
endif | ||
endif | ||
|
||
kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc | ||
kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp | ||
kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so | ||
|
||
export CFLAGS_KCOV := $(kcov-flags-y) | ||
|
||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters