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 9543c37cbSEmese Revfy ifdef CONFIG_GCC_PLUGIN_SANCOV 10543c37cbSEmese Revfy ifeq ($(CFLAGS_KCOV),) 11543c37cbSEmese Revfy # It is needed because of the gcc-plugin.sh and gcc version checks. 12543c37cbSEmese Revfy gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so 13543c37cbSEmese Revfy 14543c37cbSEmese Revfy ifneq ($(PLUGINCC),) 15543c37cbSEmese Revfy CFLAGS_KCOV := $(SANCOV_PLUGIN) 16543c37cbSEmese Revfy else 17543c37cbSEmese Revfy $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler) 18543c37cbSEmese Revfy endif 19543c37cbSEmese Revfy endif 20543c37cbSEmese Revfy endif 21543c37cbSEmese Revfy 2265d59ec8SEmese Revfy GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 236b90bd4bSEmese Revfy 24*caefd8c9SEmese Revfy export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR SANCOV_PLUGIN 256b90bd4bSEmese Revfy 26ed58c0e9SKees Cook ifneq ($(PLUGINCC),) 27543c37cbSEmese Revfy # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication. 28543c37cbSEmese Revfy GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS)) 296b90bd4bSEmese Revfy endif 306b90bd4bSEmese Revfy 316b90bd4bSEmese Revfy KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) 326b90bd4bSEmese Revfy GCC_PLUGIN := $(gcc-plugin-y) 33*caefd8c9SEmese Revfy GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) 346b90bd4bSEmese Revfyendif 35ed58c0e9SKees Cook 36ed58c0e9SKees Cook# If plugins aren't supported, abort the build before hard-to-read compiler 37ed58c0e9SKees Cook# errors start getting spewed by the main build. 38ed58c0e9SKees CookPHONY += gcc-plugins-check 39ed58c0e9SKees Cookgcc-plugins-check: FORCE 40ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS 41ed58c0e9SKees Cook ifeq ($(PLUGINCC),) 42ed58c0e9SKees Cook ifneq ($(GCC_PLUGINS_CFLAGS),) 43ed58c0e9SKees Cook ifeq ($(call cc-ifversion, -ge, 0405, y), y) 44ed58c0e9SKees Cook $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true 45ed58c0e9SKees Cook @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1 46ed58c0e9SKees Cook else 47ed58c0e9SKees 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 48ed58c0e9SKees Cook endif 49ed58c0e9SKees Cook endif 50ed58c0e9SKees Cook endif 51ed58c0e9SKees Cookendif 52ed58c0e9SKees Cook @: 53ed58c0e9SKees Cook 54ed58c0e9SKees Cook# Actually do the build, if requested. 55ed58c0e9SKees CookPHONY += gcc-plugins 56ed58c0e9SKees Cookgcc-plugins: scripts_basic gcc-plugins-check 57ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS 58ed58c0e9SKees Cook $(Q)$(MAKE) $(build)=scripts/gcc-plugins 59ed58c0e9SKees Cookendif 60ed58c0e9SKees Cook @: 61