Skip to content

Commit 0cecd37

Browse files
committed
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/[email protected] Tested-by: Nicolas Schier <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 5e88c48 commit 0cecd37

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

include/linux/compiler-version.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@
1212
* and add dependency on include/config/CC_VERSION_TEXT, which is touched
1313
* by Kconfig when the version string from the compiler changes.
1414
*/
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

scripts/Makefile.gcc-plugins

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export DISABLE_STACKLEAK_PLUGIN
3838

3939
# All the plugin CFLAGS are collected here in case a build target needs to
4040
# 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
4242
export GCC_PLUGINS_CFLAGS
4343

4444
# Add the flags to the build!

scripts/Makefile.lib

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ $(foreach m, $1, \
296296
$(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
297297
endef
298298

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+
299312
# Build commands
300313
# ===========================================================================
301314
# These are shared by some Makefile.* files.
@@ -343,6 +356,11 @@ quiet_cmd_copy = COPY $@
343356
$(obj)/%: $(src)/%_shipped
344357
$(call cmd,copy)
345358

359+
# Touch a file
360+
# ===========================================================================
361+
quiet_cmd_touch = TOUCH $(call normalize_path,$@)
362+
cmd_touch = touch $@
363+
346364
# Commands useful for building a boot image
347365
# ===========================================================================
348366
#

scripts/gcc-plugins/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ quiet_cmd_plugin_cxx_o_c = HOSTCXX $@
6666

6767
$(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE
6868
$(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

0 commit comments

Comments
 (0)