diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-06-07 20:21:43 -0400 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-06-08 05:55:36 -0400 |
commit | 315bab4e972d9795529b764718d475492db40c0f (patch) | |
tree | 33812e1783c3c1ae78f250abbf4aa00ff535d67b /Makefile | |
parent | c90fca951e90ba470a3dc6087667edffcf8db21b (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-- | Makefile | 54 |
1 files changed, 30 insertions, 24 deletions
@@ -442,8 +442,6 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE | |||
442 | export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL | 442 | export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL |
443 | export KBUILD_ARFLAGS | 443 | export KBUILD_ARFLAGS |
444 | 444 | ||
445 | export 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 |
515 | endif | 513 | endif |
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. | ||
519 | CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1) | ||
520 | |||
517 | ifeq ($(config-targets),1) | 521 | ifeq ($(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' |
525 | include arch/$(SRCARCH)/Makefile | 529 | include arch/$(SRCARCH)/Makefile |
526 | export KBUILD_DEFCONFIG KBUILD_KCONFIG | 530 | export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT |
527 | 531 | ||
528 | config: scripts_basic outputmakefile FORCE | 532 | config: scripts_basic outputmakefile FORCE |
529 | $(Q)$(MAKE) $(build)=scripts/kconfig $@ | 533 | $(Q)$(MAKE) $(build)=scripts/kconfig $@ |
@@ -585,12 +589,32 @@ virt-y := virt/ | |||
585 | endif # KBUILD_EXTMOD | 589 | endif # KBUILD_EXTMOD |
586 | 590 | ||
587 | ifeq ($(dot-config),1) | 591 | ifeq ($(dot-config),1) |
588 | # Read in config | ||
589 | -include include/config/auto.conf | 592 | -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 | ||
590 | 612 | ||
613 | ifeq ($(dot-config),1) | ||
591 | ifeq ($(KBUILD_EXTMOD),) | 614 | ifeq ($(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 | |||
622 | include/config/auto.conf: ; | 646 | include/config/auto.conf: ; |
623 | endif # $(dot-config) | 647 | endif # $(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 | ||
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 | |||
643 | KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) | 649 | KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) |
644 | KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) | 650 | KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) |
645 | KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) | 651 | KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) |