diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-05-28 05:22:06 -0400 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-06-10 20:16:22 -0400 |
commit | 59f53855babf757ac7be19995670ab884aaf9b71 (patch) | |
tree | 482e47560c10f6d2a180cbf55d8cc196f7f6922b | |
parent | 8034c2fb1225979b1cc9b9a12fa8094ca10b4fc3 (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/Kconfig | 10 | ||||
-rw-r--r-- | scripts/Kconfig.include | 3 | ||||
-rw-r--r-- | scripts/Makefile.gcc-plugins | 79 | ||||
-rw-r--r-- | scripts/gcc-plugins/Makefile | 1 |
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 | ||
401 | preferred-plugin-hostcc := $(if-success,[ $(gcc-version) -ge 40800 ],$(HOSTCXX),$(HOSTCC)) | ||
402 | |||
403 | config 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 | |||
401 | config HAVE_GCC_PLUGINS | 410 | config HAVE_GCC_PLUGINS |
402 | bool | 411 | bool |
403 | help | 412 | help |
@@ -407,6 +416,7 @@ config HAVE_GCC_PLUGINS | |||
407 | menuconfig GCC_PLUGINS | 416 | menuconfig 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 |
27 | ld-option = $(success,$(LD) -v $(1)) | 27 | ld-option = $(success,$(LD) -v $(1)) |
28 | |||
29 | # gcc version including patch level | ||
30 | gcc-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 |
2 | ifdef CONFIG_GCC_PLUGINS | 2 | gcc-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 | 4 | gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so |
11 | gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN | 5 | gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN |
12 | ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY | 6 | ifdef 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 | 8 | endif |
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 | 10 | gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so |
31 | gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN | 11 | gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so |
32 | gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) += -fplugin-arg-randomize_layout_plugin-performance-mode | 12 | gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) += -fplugin-arg-structleak_plugin-verbose |
13 | gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) += -fplugin-arg-structleak_plugin-byref-all | ||
14 | gcc-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)) | 16 | gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so |
17 | gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN | ||
18 | gcc-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 | 20 | GCC_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),) | 22 | export GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR |
40 | # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication. | 23 | export 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) | 26 | GCC_PLUGINS_CFLAGS := $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFLAGS)) |
46 | GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) | ||
47 | endif | ||
48 | 27 | ||
49 | # If plugins aren't supported, abort the build before hard-to-read compiler | 28 | KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) |
50 | # errors start getting spewed by the main build. | 29 | GCC_PLUGIN := $(gcc-plugin-y) |
51 | PHONY += gcc-plugins-check | 30 | GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) |
52 | gcc-plugins-check: FORCE | ||
53 | ifdef 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 | ||
64 | endif | ||
65 | @: | ||
66 | 31 | ||
67 | # Actually do the build, if requested. | 32 | # Actually do the build, if requested. |
68 | PHONY += gcc-plugins | 33 | PHONY += gcc-plugins |
69 | gcc-plugins: scripts_basic gcc-plugins-check | 34 | gcc-plugins: scripts_basic |
70 | ifdef CONFIG_GCC_PLUGINS | 35 | ifdef CONFIG_GCC_PLUGINS |
71 | $(Q)$(MAKE) $(build)=scripts/gcc-plugins | 36 | $(Q)$(MAKE) $(build)=scripts/gcc-plugins |
72 | endif | 37 | endif |
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 |
2 | PLUGINCC := $(CONFIG_PLUGIN_HOSTCC:"%"=%) | ||
2 | GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin) | 3 | GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin) |
3 | 4 | ||
4 | ifeq ($(PLUGINCC),$(HOSTCC)) | 5 | ifeq ($(PLUGINCC),$(HOSTCC)) |