summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 05:22:06 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-06-10 20:16:22 -0400
commit59f53855babf757ac7be19995670ab884aaf9b71 (patch)
tree482e47560c10f6d2a180cbf55d8cc196f7f6922b
parent8034c2fb1225979b1cc9b9a12fa8094ca10b4fc3 (diff)
gcc-plugins: test plugin support in Kconfig and clean up Makefile
Run scripts/gcc-plugin.sh from Kconfig so that users can enable GCC_PLUGINS only when the compiler supports building plugins. Kconfig defines a new symbol, PLUGIN_HOSTCC. This will contain the compiler (g++ or gcc) used for building plugins, or empty if the plugin can not be supported at all. This allows us to remove all ugly testing in Makefile.gcc-plugins. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Acked-by: Kees Cook <keescook@chromium.org>
-rw-r--r--arch/Kconfig10
-rw-r--r--scripts/Kconfig.include3
-rw-r--r--scripts/Makefile.gcc-plugins79
-rw-r--r--scripts/gcc-plugins/Makefile1
4 files changed, 36 insertions, 57 deletions
diff --git a/arch/Kconfig b/arch/Kconfig
index 2c7c3cf8adfc..e4a47d640a87 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -398,6 +398,15 @@ config SECCOMP_FILTER
398 398
399 See Documentation/prctl/seccomp_filter.txt for details. 399 See Documentation/prctl/seccomp_filter.txt for details.
400 400
401preferred-plugin-hostcc := $(if-success,[ $(gcc-version) -ge 40800 ],$(HOSTCXX),$(HOSTCC))
402
403config PLUGIN_HOSTCC
404 string
405 default "$(shell,$(srctree)/scripts/gcc-plugin.sh "$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")"
406 help
407 Host compiler used to build GCC plugins. This can be $(HOSTCXX),
408 $(HOSTCC), or a null string if GCC plugin is unsupported.
409
401config HAVE_GCC_PLUGINS 410config HAVE_GCC_PLUGINS
402 bool 411 bool
403 help 412 help
@@ -407,6 +416,7 @@ config HAVE_GCC_PLUGINS
407menuconfig GCC_PLUGINS 416menuconfig GCC_PLUGINS
408 bool "GCC plugins" 417 bool "GCC plugins"
409 depends on HAVE_GCC_PLUGINS 418 depends on HAVE_GCC_PLUGINS
419 depends on PLUGIN_HOSTCC != ""
410 depends on !COMPILE_TEST 420 depends on !COMPILE_TEST
411 help 421 help
412 GCC plugins are loadable modules that provide extra features to the 422 GCC plugins are loadable modules that provide extra features to the
diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index bf7c0c9fa3a4..dad5583451af 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -25,3 +25,6 @@ cc-option = $(success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null)
25# $(ld-option,<flag>) 25# $(ld-option,<flag>)
26# Return y if the linker supports <flag>, n otherwise 26# Return y if the linker supports <flag>, n otherwise
27ld-option = $(success,$(LD) -v $(1)) 27ld-option = $(success,$(LD) -v $(1))
28
29# gcc version including patch level
30gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//')
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 32bdf184eced..c961b9a65d11 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -1,72 +1,37 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2ifdef CONFIG_GCC_PLUGINS 2gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
3 __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))
4 PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)")
5
6 SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
7
8 gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
9 3
10 gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so 4gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so
11 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN 5gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN
12 ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY 6ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
13 DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable 7 DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable
14 endif 8endif
15
16 ifdef CONFIG_GCC_PLUGIN_SANCOV
17 # It is needed because of the gcc-plugin.sh and gcc version checks.
18 gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
19
20 ifeq ($(PLUGINCC),)
21 $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler)
22 endif
23 endif
24
25 gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so
26 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) += -fplugin-arg-structleak_plugin-verbose
27 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) += -fplugin-arg-structleak_plugin-byref-all
28 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += -DSTRUCTLEAK_PLUGIN
29 9
30 gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so 10gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
31 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN 11gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so
32 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) += -fplugin-arg-randomize_layout_plugin-performance-mode 12gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) += -fplugin-arg-structleak_plugin-verbose
13gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) += -fplugin-arg-structleak_plugin-byref-all
14gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += -DSTRUCTLEAK_PLUGIN
33 15
34 GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 16gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so
17gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN
18gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) += -fplugin-arg-randomize_layout_plugin-performance-mode
35 19
36 export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR 20GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
37 export DISABLE_LATENT_ENTROPY_PLUGIN
38 21
39 ifneq ($(PLUGINCC),) 22export GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR
40 # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication. 23export DISABLE_LATENT_ENTROPY_PLUGIN
41 GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS))
42 endif
43 24
44 KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) 25# sancov_plugin.so can be only in CFLAGS_KCOV because avoid duplication.
45 GCC_PLUGIN := $(gcc-plugin-y) 26GCC_PLUGINS_CFLAGS := $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFLAGS))
46 GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y)
47endif
48 27
49# If plugins aren't supported, abort the build before hard-to-read compiler 28KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
50# errors start getting spewed by the main build. 29GCC_PLUGIN := $(gcc-plugin-y)
51PHONY += gcc-plugins-check 30GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y)
52gcc-plugins-check: FORCE
53ifdef CONFIG_GCC_PLUGINS
54 ifeq ($(PLUGINCC),)
55 ifneq ($(GCC_PLUGINS_CFLAGS),)
56 ifeq ($(call cc-ifversion, -ge, 0405, y), y)
57 $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true
58 @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1
59 else
60 @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc version does not support plugins, you should upgrade it to at least gcc 4.5" >&2 && exit 1
61 endif
62 endif
63 endif
64endif
65 @:
66 31
67# Actually do the build, if requested. 32# Actually do the build, if requested.
68PHONY += gcc-plugins 33PHONY += gcc-plugins
69gcc-plugins: scripts_basic gcc-plugins-check 34gcc-plugins: scripts_basic
70ifdef CONFIG_GCC_PLUGINS 35ifdef CONFIG_GCC_PLUGINS
71 $(Q)$(MAKE) $(build)=scripts/gcc-plugins 36 $(Q)$(MAKE) $(build)=scripts/gcc-plugins
72endif 37endif
diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
index ea465799ced5..326254653bd0 100644
--- a/scripts/gcc-plugins/Makefile
+++ b/scripts/gcc-plugins/Makefile
@@ -1,4 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2PLUGINCC := $(CONFIG_PLUGIN_HOSTCC:"%"=%)
2GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin) 3GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
3 4
4ifeq ($(PLUGINCC),$(HOSTCC)) 5ifeq ($(PLUGINCC),$(HOSTCC))