summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-06-07 20:21:43 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-06-08 05:55:36 -0400
commit315bab4e972d9795529b764718d475492db40c0f (patch)
tree33812e1783c3c1ae78f250abbf4aa00ff535d67b /Makefile
parentc90fca951e90ba470a3dc6087667edffcf8db21b (diff)
kbuild: fix endless syncconfig in case arch Makefile sets CROSS_COMPILE
Commit 21c54b774744 ("kconfig: show compiler version text in the top comment") was intended to detect the compiler upgrade, but Geert reported a breakage on the m68k build. The compiler upgrade is detected by the change of the environment variable, CC_VERSION_TEXT, which contains the first line of the output from $(CC) --version. Currently, this works well when CROSS_COMPILE is given via the environment variable or the Make command line. However, some architectures such as m68k can specify CROSS_COMPILE from arch/$(SRCARCH)/Makefile as well. In this case, "make ARCH=m68k" ends up with endless syncconfig loop. $ make ARCH=m68k defconfig *** Default configuration is based on 'multi_defconfig' # # configuration written to .config # $ make ARCH=m68k scripts/kconfig/conf --syncconfig Kconfig scripts/kconfig/conf --syncconfig Kconfig scripts/kconfig/conf --syncconfig Kconfig scripts/kconfig/conf --syncconfig Kconfig Things are happening like this: Because arch/$(SRCARCH)/Makefile is included after CC_VERSION_TEXT is set, it contains the host compiler version in the defconfig phase. To create or update auto.conf, the following line is triggered: include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig This recurses the top Makefile after arch/$(SRCARCH)/Makefile is included. CROSS_COMPILE is set to a m68k toolchain prefix and exported to the recursed Make. Then, syncconfig is invoked with the target compiler version in CC_VERSION_TEXT. The Make will restart because auto.conf and auto.conf.cmd have been updated. At this point, CROSS_COMPILE is reset, so CC_VERSION_TEXT is set to the host compiler version again. Then, syncconfig is triggered due to the change of CC_VERSION_TEXT. This loop continues eternally. To fix this problem, $(CC_VERSION_TEXT) must be evaluated only after arch/$(SRCARCH)/Makefile. Setting it earlier is OK as long as it is defined by using the '=' operator instead of ':='. For the defconfig phase, $(CC_VERSION_TEXT) is evaluated when Kbuild descends into scripts/kconfig/, so it contains the target compiler version correctly. include/config/auto.conf.cmd references $(CC_VERSION_TEXT) as well, so it must be included after arch/$(SRCARCH)/Makefile. Fixes: 21c54b774744 ("kconfig: show compiler version text in the top comment") Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile54
1 files changed, 30 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index 019a5a020606..747edaf11559 100644
--- a/Makefile
+++ b/Makefile
@@ -442,8 +442,6 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
442export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL 442export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
443export KBUILD_ARFLAGS 443export KBUILD_ARFLAGS
444 444
445export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1)
446
447# When compiling out-of-tree modules, put MODVERDIR in the module 445# When compiling out-of-tree modules, put MODVERDIR in the module
448# tree rather than in the kernel tree. The kernel tree might 446# tree rather than in the kernel tree. The kernel tree might
449# even be read-only. 447# even be read-only.
@@ -514,6 +512,12 @@ ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/cc-can-link.sh $(CC)), y)
514 export CC_CAN_LINK 512 export CC_CAN_LINK
515endif 513endif
516 514
515# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
516# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
517# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
518# and from include/config/auto.conf.cmd to detect the compiler upgrade.
519CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1)
520
517ifeq ($(config-targets),1) 521ifeq ($(config-targets),1)
518# =========================================================================== 522# ===========================================================================
519# *config targets only - make sure prerequisites are updated, and descend 523# *config targets only - make sure prerequisites are updated, and descend
@@ -523,7 +527,7 @@ ifeq ($(config-targets),1)
523# KBUILD_DEFCONFIG may point out an alternative default configuration 527# KBUILD_DEFCONFIG may point out an alternative default configuration
524# used for 'make defconfig' 528# used for 'make defconfig'
525include arch/$(SRCARCH)/Makefile 529include arch/$(SRCARCH)/Makefile
526export KBUILD_DEFCONFIG KBUILD_KCONFIG 530export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
527 531
528config: scripts_basic outputmakefile FORCE 532config: scripts_basic outputmakefile FORCE
529 $(Q)$(MAKE) $(build)=scripts/kconfig $@ 533 $(Q)$(MAKE) $(build)=scripts/kconfig $@
@@ -585,12 +589,32 @@ virt-y := virt/
585endif # KBUILD_EXTMOD 589endif # KBUILD_EXTMOD
586 590
587ifeq ($(dot-config),1) 591ifeq ($(dot-config),1)
588# Read in config
589-include include/config/auto.conf 592-include include/config/auto.conf
593endif
594
595# The all: target is the default when no target is given on the
596# command line.
597# This allow a user to issue only 'make' to build a kernel including modules
598# Defaults to vmlinux, but the arch makefile usually adds further targets
599all: vmlinux
600
601CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
602 $(call cc-option,-fno-tree-loop-im) \
603 $(call cc-disable-warning,maybe-uninitialized,)
604export CFLAGS_GCOV CFLAGS_KCOV
605
606# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
607# values of the respective KBUILD_* variables
608ARCH_CPPFLAGS :=
609ARCH_AFLAGS :=
610ARCH_CFLAGS :=
611include arch/$(SRCARCH)/Makefile
590 612
613ifeq ($(dot-config),1)
591ifeq ($(KBUILD_EXTMOD),) 614ifeq ($(KBUILD_EXTMOD),)
592# Read in dependencies to all Kconfig* files, make sure to run 615# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
593# oldconfig if changes are detected. 616# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
617# because some architectures define CROSS_COMPILE there.
594-include include/config/auto.conf.cmd 618-include include/config/auto.conf.cmd
595 619
596# To avoid any implicit rule to kick in, define an empty command 620# To avoid any implicit rule to kick in, define an empty command
@@ -622,24 +646,6 @@ else
622include/config/auto.conf: ; 646include/config/auto.conf: ;
623endif # $(dot-config) 647endif # $(dot-config)
624 648
625# The all: target is the default when no target is given on the
626# command line.
627# This allow a user to issue only 'make' to build a kernel including modules
628# Defaults to vmlinux, but the arch makefile usually adds further targets
629all: vmlinux
630
631CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
632 $(call cc-option,-fno-tree-loop-im) \
633 $(call cc-disable-warning,maybe-uninitialized,)
634export CFLAGS_GCOV CFLAGS_KCOV
635
636# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
637# values of the respective KBUILD_* variables
638ARCH_CPPFLAGS :=
639ARCH_AFLAGS :=
640ARCH_CFLAGS :=
641include arch/$(SRCARCH)/Makefile
642
643KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) 649KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
644KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) 650KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
645KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) 651KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)