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 /scripts/Makefile.gcc-plugins | |
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>
Diffstat (limited to 'scripts/Makefile.gcc-plugins')
-rw-r--r-- | scripts/Makefile.gcc-plugins | 79 |
1 files changed, 22 insertions, 57 deletions
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 |