xref: /linux/scripts/Makefile.gcc-plugins (revision 5aadfdeb8de001ca04d500586e3b033404c28617)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
26b90bd4bSEmese Revfyifdef CONFIG_GCC_PLUGINS
36b90bd4bSEmese Revfy  __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))
46b90bd4bSEmese Revfy  PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)")
56b90bd4bSEmese Revfy
6543c37cbSEmese Revfy  SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
7543c37cbSEmese Revfy
80dae776cSEmese Revfy  gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY)	+= cyc_complexity_plugin.so
9543c37cbSEmese Revfy
1038addce8SEmese Revfy  gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)	+= latent_entropy_plugin.so
1138addce8SEmese Revfy  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)	+= -DLATENT_ENTROPY_PLUGIN
127b4010edSAndrew Donnellan  ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
1338addce8SEmese Revfy    DISABLE_LATENT_ENTROPY_PLUGIN			+= -fplugin-arg-latent_entropy_plugin-disable
1438addce8SEmese Revfy  endif
1538addce8SEmese Revfy
16543c37cbSEmese Revfy  ifdef CONFIG_GCC_PLUGIN_SANCOV
17543c37cbSEmese Revfy      # It is needed because of the gcc-plugin.sh and gcc version checks.
18543c37cbSEmese Revfy      gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV)           += sancov_plugin.so
19543c37cbSEmese Revfy
20*5aadfdebSMasahiro Yamada      ifeq ($(PLUGINCC),)
21543c37cbSEmese Revfy        $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler)
22543c37cbSEmese Revfy      endif
23543c37cbSEmese Revfy  endif
24543c37cbSEmese Revfy
25c61f13eaSKees Cook  gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK)	+= structleak_plugin.so
26c61f13eaSKees Cook  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE)	+= -fplugin-arg-structleak_plugin-verbose
27f7dd2507SArd Biesheuvel  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL)	+= -fplugin-arg-structleak_plugin-byref-all
28c61f13eaSKees Cook  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK)	+= -DSTRUCTLEAK_PLUGIN
29c61f13eaSKees Cook
30313dd1b6SKees Cook  gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT)	+= randomize_layout_plugin.so
31313dd1b6SKees Cook  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT)	+= -DRANDSTRUCT_PLUGIN
32313dd1b6SKees Cook  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE)	+= -fplugin-arg-randomize_layout_plugin-performance-mode
33313dd1b6SKees Cook
3465d59ec8SEmese Revfy  GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
356b90bd4bSEmese Revfy
3638addce8SEmese Revfy  export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR
37*5aadfdebSMasahiro Yamada  export DISABLE_LATENT_ENTROPY_PLUGIN
386b90bd4bSEmese Revfy
39ed58c0e9SKees Cook  ifneq ($(PLUGINCC),)
40543c37cbSEmese Revfy    # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication.
41543c37cbSEmese Revfy    GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS))
426b90bd4bSEmese Revfy  endif
436b90bd4bSEmese Revfy
446b90bd4bSEmese Revfy  KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
456b90bd4bSEmese Revfy  GCC_PLUGIN := $(gcc-plugin-y)
46caefd8c9SEmese Revfy  GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y)
476b90bd4bSEmese Revfyendif
48ed58c0e9SKees Cook
49ed58c0e9SKees Cook# If plugins aren't supported, abort the build before hard-to-read compiler
50ed58c0e9SKees Cook# errors start getting spewed by the main build.
51ed58c0e9SKees CookPHONY += gcc-plugins-check
52ed58c0e9SKees Cookgcc-plugins-check: FORCE
53ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS
54ed58c0e9SKees Cook  ifeq ($(PLUGINCC),)
55ed58c0e9SKees Cook    ifneq ($(GCC_PLUGINS_CFLAGS),)
5665c059bcSAndrew Donnellan      # Various gccs between 4.5 and 5.1 have bugs on powerpc due to missing
5765c059bcSAndrew Donnellan      # header files. gcc <= 4.6 doesn't work at all, gccs from 4.8 to 5.1 have
5865c059bcSAndrew Donnellan      # issues with 64-bit targets.
5965c059bcSAndrew Donnellan      ifeq ($(ARCH),powerpc)
6065c059bcSAndrew Donnellan        ifeq ($(call cc-ifversion, -le, 0501, y), y)
6165c059bcSAndrew Donnellan	  @echo "Cannot use CONFIG_GCC_PLUGINS: plugin support on gcc <= 5.1 is buggy on powerpc, please upgrade to gcc 5.2 or newer" >&2 && exit 1
6265c059bcSAndrew Donnellan        endif
6365c059bcSAndrew Donnellan      endif
64ed58c0e9SKees Cook      ifeq ($(call cc-ifversion, -ge, 0405, y), y)
65ed58c0e9SKees Cook	$(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true
66ed58c0e9SKees Cook	@echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1
67ed58c0e9SKees Cook      else
68ed58c0e9SKees Cook	@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
69ed58c0e9SKees Cook      endif
70ed58c0e9SKees Cook    endif
71ed58c0e9SKees Cook  endif
72ed58c0e9SKees Cookendif
73ed58c0e9SKees Cook	@:
74ed58c0e9SKees Cook
75ed58c0e9SKees Cook# Actually do the build, if requested.
76ed58c0e9SKees CookPHONY += gcc-plugins
77ed58c0e9SKees Cookgcc-plugins: scripts_basic gcc-plugins-check
78ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS
79ed58c0e9SKees Cook	$(Q)$(MAKE) $(build)=scripts/gcc-plugins
80ed58c0e9SKees Cookendif
81ed58c0e9SKees Cook	@:
82