Skip to content

Commit ce6ed1c

Browse files
committed
kbuild: rebuild GCC plugins when the compiler is upgraded
Linus reported a build error due to the GCC plugin incompatibility when the compiler is upgraded. [1] GCC plugins are tied to a particular GCC version. So, they must be rebuilt when the compiler is upgraded. This seems to be a long-standing flaw since the initial support of GCC plugins. Extend commit 8b59cd8 ("kbuild: ensure full rebuild when the compiler is updated"), so that GCC plugins are covered by the compiler upgrade detection. [1]: https://lore.kernel.org/lkml/CAHk-=wieoN5ttOy7SnsGwZv+Fni3R6m-Ut=oxih6bbZ28G+4dw@mail.gmail.com/ Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org>
1 parent 1f09af0 commit ce6ed1c

5 files changed

Lines changed: 20 additions & 6 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ USERINCLUDE := \
479479
-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
480480
-I$(srctree)/include/uapi \
481481
-I$(objtree)/include/generated/uapi \
482+
-include $(srctree)/include/linux/compiler-version.h \
482483
-include $(srctree)/include/linux/kconfig.h
483484

484485
# Use LINUXINCLUDE when you must reference the include/ directory.

include/linux/compiler-version.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#ifdef __LINUX_COMPILER_VERSION_H
4+
#error "Please do not include <linux/compiler-version.h>. This is done by the build system."
5+
#endif
6+
#define __LINUX_COMPILER_VERSION_H
7+
8+
/*
9+
* This header exists to force full rebuild when the compiler is upgraded.
10+
*
11+
* When fixdep scans this, it will find this string "CONFIG_CC_VERSION_TEXT"
12+
* and add dependency on include/config/cc/version/text.h, which is touched
13+
* by Kconfig when the version string from the compiler changes.
14+
*/

include/linux/kconfig.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#ifndef __LINUX_KCONFIG_H
33
#define __LINUX_KCONFIG_H
44

5-
/* CONFIG_CC_VERSION_TEXT (Do not delete this comment. See help in Kconfig) */
6-
75
#include <generated/autoconf.h>
86

97
#ifdef CONFIG_CPU_BIG_ENDIAN

init/Kconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ config CC_VERSION_TEXT
2020
When the compiler is updated, Kconfig will be invoked.
2121

2222
- Ensure full rebuild when the compiler is updated
23-
include/linux/kconfig.h contains this option in the comment line so
24-
fixdep adds include/config/cc/version/text.h into the auto-generated
25-
dependency. When the compiler is updated, syncconfig will touch it
26-
and then every file will be rebuilt.
23+
include/linux/compiler-version.h contains this option in the comment
24+
line so fixdep adds include/config/cc/version/text.h into the
25+
auto-generated dependency. When the compiler is updated, syncconfig
26+
will touch it and then every file will be rebuilt.
2727

2828
config CC_IS_GCC
2929
def_bool $(success,test "$(cc-name)" = GCC)

scripts/gcc-plugins/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ always-y += $(GCC_PLUGIN)
2222
GCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin)
2323

2424
plugin_cxxflags = -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \
25+
-include $(srctree)/include/linux/compiler-version.h \
2526
-I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++11 \
2627
-fno-rtti -fno-exceptions -fasynchronous-unwind-tables \
2728
-ggdb -Wno-narrowing -Wno-unused-variable \

0 commit comments

Comments
 (0)