Skip to content

Commit 315bab4

Browse files
committed
kbuild: fix endless syncconfig in case arch Makefile sets CROSS_COMPILE
Commit 21c54b7 ("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: 21c54b7 ("kconfig: show compiler version text in the top comment") Reported-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]>
1 parent c90fca9 commit 315bab4

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

Makefile

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
442442
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
443443
export KBUILD_ARFLAGS
444444

445-
export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1)
446-
447445
# When compiling out-of-tree modules, put MODVERDIR in the module
448446
# tree rather than in the kernel tree. The kernel tree might
449447
# even be read-only.
@@ -514,6 +512,12 @@ ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/cc-can-link.sh $(CC)), y)
514512
export CC_CAN_LINK
515513
endif
516514

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.
519+
CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1)
520+
517521
ifeq ($(config-targets),1)
518522
# ===========================================================================
519523
# *config targets only - make sure prerequisites are updated, and descend
@@ -523,7 +527,7 @@ ifeq ($(config-targets),1)
523527
# KBUILD_DEFCONFIG may point out an alternative default configuration
524528
# used for 'make defconfig'
525529
include arch/$(SRCARCH)/Makefile
526-
export KBUILD_DEFCONFIG KBUILD_KCONFIG
530+
export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
527531

528532
config: scripts_basic outputmakefile FORCE
529533
$(Q)$(MAKE) $(build)=scripts/kconfig $@
@@ -585,12 +589,32 @@ virt-y := virt/
585589
endif # KBUILD_EXTMOD
586590

587591
ifeq ($(dot-config),1)
588-
# Read in config
589592
-include include/config/auto.conf
593+
endif
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
599+
all: vmlinux
600+
601+
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
602+
$(call cc-option,-fno-tree-loop-im) \
603+
$(call cc-disable-warning,maybe-uninitialized,)
604+
export 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
608+
ARCH_CPPFLAGS :=
609+
ARCH_AFLAGS :=
610+
ARCH_CFLAGS :=
611+
include arch/$(SRCARCH)/Makefile
590612

613+
ifeq ($(dot-config),1)
591614
ifeq ($(KBUILD_EXTMOD),)
592-
# Read in dependencies to all Kconfig* files, make sure to run
593-
# oldconfig if changes are detected.
615+
# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
616+
# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
617+
# because some architectures define CROSS_COMPILE there.
594618
-include include/config/auto.conf.cmd
595619

596620
# To avoid any implicit rule to kick in, define an empty command
@@ -622,24 +646,6 @@ else
622646
include/config/auto.conf: ;
623647
endif # $(dot-config)
624648

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
629-
all: vmlinux
630-
631-
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
632-
$(call cc-option,-fno-tree-loop-im) \
633-
$(call cc-disable-warning,maybe-uninitialized,)
634-
export 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
638-
ARCH_CPPFLAGS :=
639-
ARCH_AFLAGS :=
640-
ARCH_CFLAGS :=
641-
include arch/$(SRCARCH)/Makefile
642-
643649
KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
644650
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
645651
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)

0 commit comments

Comments
 (0)