16b90bd4bSEmese Revfyifdef CONFIG_GCC_PLUGINS 26b90bd4bSEmese Revfy __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC)) 36b90bd4bSEmese Revfy PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)") 46b90bd4bSEmese Revfy 5543c37cbSEmese Revfy SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so 6543c37cbSEmese Revfy 70dae776cSEmese Revfy gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so 8543c37cbSEmese Revfy 938addce8SEmese Revfy gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so 1038addce8SEmese Revfy gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN 11*7b4010edSAndrew Donnellan ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY 1238addce8SEmese Revfy DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable 1338addce8SEmese Revfy endif 1438addce8SEmese Revfy 15543c37cbSEmese Revfy ifdef CONFIG_GCC_PLUGIN_SANCOV 16543c37cbSEmese Revfy ifeq ($(CFLAGS_KCOV),) 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 20543c37cbSEmese Revfy ifneq ($(PLUGINCC),) 21543c37cbSEmese Revfy CFLAGS_KCOV := $(SANCOV_PLUGIN) 22543c37cbSEmese Revfy else 23543c37cbSEmese Revfy $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler) 24543c37cbSEmese Revfy endif 25543c37cbSEmese Revfy endif 26543c37cbSEmese Revfy endif 27543c37cbSEmese Revfy 2865d59ec8SEmese Revfy GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 296b90bd4bSEmese Revfy 3038addce8SEmese Revfy export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR 3138addce8SEmese Revfy export SANCOV_PLUGIN DISABLE_LATENT_ENTROPY_PLUGIN 326b90bd4bSEmese Revfy 33ed58c0e9SKees Cook ifneq ($(PLUGINCC),) 34543c37cbSEmese Revfy # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication. 35543c37cbSEmese Revfy GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS)) 366b90bd4bSEmese Revfy endif 376b90bd4bSEmese Revfy 386b90bd4bSEmese Revfy KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) 396b90bd4bSEmese Revfy GCC_PLUGIN := $(gcc-plugin-y) 40caefd8c9SEmese Revfy GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) 416b90bd4bSEmese Revfyendif 42ed58c0e9SKees Cook 43ed58c0e9SKees Cook# If plugins aren't supported, abort the build before hard-to-read compiler 44ed58c0e9SKees Cook# errors start getting spewed by the main build. 45ed58c0e9SKees CookPHONY += gcc-plugins-check 46ed58c0e9SKees Cookgcc-plugins-check: FORCE 47ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS 48ed58c0e9SKees Cook ifeq ($(PLUGINCC),) 49ed58c0e9SKees Cook ifneq ($(GCC_PLUGINS_CFLAGS),) 50ed58c0e9SKees Cook ifeq ($(call cc-ifversion, -ge, 0405, y), y) 51ed58c0e9SKees Cook $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true 52ed58c0e9SKees Cook @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1 53ed58c0e9SKees Cook else 54ed58c0e9SKees 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 55ed58c0e9SKees Cook endif 56ed58c0e9SKees Cook endif 57ed58c0e9SKees Cook endif 58ed58c0e9SKees Cookendif 59ed58c0e9SKees Cook @: 60ed58c0e9SKees Cook 61ed58c0e9SKees Cook# Actually do the build, if requested. 62ed58c0e9SKees CookPHONY += gcc-plugins 63ed58c0e9SKees Cookgcc-plugins: scripts_basic gcc-plugins-check 64ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS 65ed58c0e9SKees Cook $(Q)$(MAKE) $(build)=scripts/gcc-plugins 66ed58c0e9SKees Cookendif 67ed58c0e9SKees Cook @: 68