Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gcc-plugins: Force full rebuild when plugins change

There was no dependency between the plugins changing and the rest of the
kernel being built. This could cause strange behaviors as instrumentation
could vary between targets depending on when they were built.

Generate a new header file, gcc-plugins.h, any time the GCC plugins
change. Include the header file in compiler-version.h when its associated
feature name, GCC_PLUGINS, is defined. This will be picked up by fixdep
and force rebuilds where needed.

Add a generic "touch" kbuild command, which will be used again in
a following patch. Add a "normalize_path" string helper to make the
"TOUCH" output less ugly.

Link: https://lore.kernel.org/r/20250503184623.2572355-1-kees@kernel.org
Tested-by: Nicolas Schier <n.schier@avm.de>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
Signed-off-by: Kees Cook <kees@kernel.org>

Kees Cook 0cecd37d 5e88c48c

+34 -1
+11
include/linux/compiler-version.h
··· 12 12 * and add dependency on include/config/CC_VERSION_TEXT, which is touched 13 13 * by Kconfig when the version string from the compiler changes. 14 14 */ 15 + 16 + /* Additional tree-wide dependencies start here. */ 17 + 18 + /* 19 + * If any of the GCC plugins change, we need to rebuild everything that 20 + * was built with them, as they may have changed their behavior and those 21 + * behaviors may need to be synchronized across all translation units. 22 + */ 23 + #ifdef GCC_PLUGINS 24 + #include <generated/gcc-plugins.h> 25 + #endif
+1 -1
scripts/Makefile.gcc-plugins
··· 38 38 39 39 # All the plugin CFLAGS are collected here in case a build target needs to 40 40 # filter them out of the KBUILD_CFLAGS. 41 - GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 41 + GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) -DGCC_PLUGINS 42 42 export GCC_PLUGINS_CFLAGS 43 43 44 44 # Add the flags to the build!
+18
scripts/Makefile.lib
··· 296 296 $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3)))) 297 297 endef 298 298 299 + # Remove ".." and "." from a path, without using "realpath" 300 + # Usage: 301 + # $(call normalize_path,path/to/../file) 302 + define normalize_path 303 + $(strip $(eval elements :=) \ 304 + $(foreach elem,$(subst /, ,$1), \ 305 + $(if $(filter-out .,$(elem)), \ 306 + $(if $(filter ..,$(elem)), \ 307 + $(eval elements := $(wordlist 2,$(words $(elements)),x $(elements))), \ 308 + $(eval elements := $(elements) $(elem))))) \ 309 + $(subst $(space),/,$(elements))) 310 + endef 311 + 299 312 # Build commands 300 313 # =========================================================================== 301 314 # These are shared by some Makefile.* files. ··· 355 342 356 343 $(obj)/%: $(src)/%_shipped 357 344 $(call cmd,copy) 345 + 346 + # Touch a file 347 + # =========================================================================== 348 + quiet_cmd_touch = TOUCH $(call normalize_path,$@) 349 + cmd_touch = touch $@ 358 350 359 351 # Commands useful for building a boot image 360 352 # ===========================================================================
+4
scripts/gcc-plugins/Makefile
··· 66 66 67 67 $(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE 68 68 $(call if_changed_dep,plugin_cxx_o_c) 69 + 70 + $(obj)/../../include/generated/gcc-plugins.h: $(plugin-single) $(plugin-multi) FORCE 71 + $(call if_changed,touch) 72 + always-y += ../../include/generated/gcc-plugins.h