kbuild: ensure full rebuild when the compiler is updated
PATCH 1/2 kbuild: ensure full rebuild when the compiler is updated
Commit 21c54b774744 ("kconfig: show compiler version text in the top comment") added the environment variable, CC_VERSION_TEXT in the comment of the top Kconfig file. It can detect the compiler update, and invoke the syncconfig because all environment variables referenced in Kconfig files are recorded in include/config/auto.conf.cmd
This commit makes it a CONFIG option in order to ensure the full rebuild when the compiler is updated.
This works like as follows:
include/config/kconfig.h contains "CONFIG_CC_VERSION_TEXT" in the comment block.
The top Makefile specifies "-include $(srctree)/include/linux/kconfig.h" to guarantee it is included from all kernel source files.
fixdep parses every source file and all headers included from it, searching for words prefixed with "CONFIG_". Then, fixdep finds CONFIG_CC_VERSION_TEXT in include/config/kconfig.h and adds include/config/cc/version/text.h into every .*.cmd file.
When the compiler is updated, syncconfig is invoked since the environment variable is referenced. CONFIG_CC_VERSION_TEXT is updated to the new version string, and include/config/cc/version/text.h is touched.
In the next rebuild, Make rebuilds every files since the timestamp of include/config/cc/version/text.h is newer than that of target.
---
Kconfig | 2 -- include/linux/kconfig.h | 9 +++++++++ init/Kconfig | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-)
Kconfig +0 -2
@@ -5,8 +5,6 @@ # mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration" -comment "Compiler: $(CC_VERSION_TEXT)" - source "scripts/Kconfig.include" source "init/Kconfig"
include/linux/kconfig.h +9 -0
@@ -2,6 +2,15 @@#ifndef __LINUX_KCONFIG_H#define __LINUX_KCONFIG_H +/* +* Do not remove this comment block. This contains "CONFIG_CC_VERSION_TEXT" +* to ensure the full rebuild when the compiler is updated. +* +* fixdep parses this header, which is included by every kernel source file, +* and adds include/config/cc/version/text.h to the dependency in .*.cmd files. +* When the compiler is updated, syncconfig touches it so every file is rebuilt. +*/ +#include <generated/autoconf.h> #ifdef CONFIG_CPU_BIG_ENDIAN
init/Kconfig +12 -0
@@ -8,6 +8,18 @@ config DEFCONFIG_LIST default "/boot/config-$(shell,uname -r)" default "arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG)" +config CC_VERSION_TEXT + string + default "$(CC_VERSION_TEXT)" + help + There two purposes for this entry: + + 1. Reference the environment variable, CC_VERSION_TEXT, so Kconfig + is invoked if the compiler is updated. + + 2. Touch include/config/cc/version/text.h to force the full rebuild + if the compiler is updated. See comment in include/linux/kconfig.h + config CC_IS_GCC def_bool $(success,$(CC) --version | head -n 1 | grep -q gcc)
Signature · 1 line
2.25.1
PATCH 2/2 kbuild: use -MMD instead of -MD to exclude system headers from dependency
This omits system header files from the generated header dependency.
System headers are not updated unless you upgrade the compiler. Nor do they contain CONFIG options, so fixdep does not need to parse them.
Having said that, the effect of this optimization will be small because the kernel code generally does not include system headers except <stdarg.h>.
Host programs include a lot of system headers, but there are not so many host programs.
Theoretically, fixdep does not need to parse *.d files for host programs because host programs should not contain CONFIG options in the first place. Kbuild re-uses if_changed_dep for host programs, though I do not think it is a big deal.
At first, keeping system headers in .*.cmd files might be useful to detect the compiler update, but there is no guarantee that <stdarg.h> is included from every file. So, I implemented a more reliable way in the previous commit.
---
scripts/Kbuild.include | 2 +- scripts/Makefile.host | 4 ++-- scripts/Makefile.lib | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
scripts/Kbuild.include +1 -1
@@ -16,7 +16,7 @@ pound := \# dot-target = $(dir $@).$(notdir $@) ### -# The temporary file to save gcc -MD generated dependencies must not +# The temporary file to save gcc -MMD generated dependencies must not # contain a comma depfile = $(subst $(comma),_,$(dot-target).d)
scripts/Makefile.host +2 -2
@@ -88,8 +88,8 @@ _hostcxx_flags += -I $(objtree)/$(obj) endif endif -hostc_flags = -Wp,-MD,$(depfile) $(_hostc_flags) -hostcxx_flags = -Wp,-MD,$(depfile) $(_hostcxx_flags) +hostc_flags = -Wp,-MMD,$(depfile) $(_hostc_flags) +hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags) ##### # Compile programs on the host
scripts/Makefile.lib +4 -4
@@ -171,22 +171,22 @@ modkern_aflags = $(if $(part-of-module), \ $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)) -c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ +c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ -include $(srctree)/include/linux/compiler_types.h \ $(_c_flags) $(modkern_cflags) \ $(basename_flags) $(modname_flags) -a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ +a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(_a_flags) $(modkern_aflags) -cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ +cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(_cpp_flags) ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes -dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ +dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \ $(addprefix -I,$(DTC_INCLUDE)) \ -undef -D__DTS__
Signature · 1 line
2.25.1