Skip to content

Commit 5241ab4

Browse files
committed
kbuild: initialize CLANG_FLAGS correctly in the top Makefile
CLANG_FLAGS is initialized by the following line: CLANG_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%)) ..., which is run only when CROSS_COMPILE is set. Some build targets (bindeb-pkg etc.) recurse to the top Makefile. When you build the kernel with Clang but without CROSS_COMPILE, the same compiler flags such as -no-integrated-as are accumulated into CLANG_FLAGS. If you run 'make CC=clang' and then 'make CC=clang bindeb-pkg', Kbuild will recompile everything needlessly due to the build command change. Fix this by correctly initializing CLANG_FLAGS. Fixes: 238bcbc ("kbuild: consolidate Clang compiler flags") Cc: <stable@vger.kernel.org> # v5.0+ Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com> Acked-by: Nick Desaulniers <ndesaulniers@google.com>
1 parent 6224455 commit 5241ab4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ KBUILD_CFLAGS_MODULE := -DMODULE
472472
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
473473
KBUILD_LDFLAGS :=
474474
GCC_PLUGINS_CFLAGS :=
475+
CLANG_FLAGS :=
475476

476477
export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
477478
export CPP AR NM STRIP OBJCOPY OBJDUMP PAHOLE KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
@@ -519,7 +520,7 @@ endif
519520

520521
ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
521522
ifneq ($(CROSS_COMPILE),)
522-
CLANG_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%))
523+
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
523524
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
524525
CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
525526
GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)

0 commit comments

Comments
 (0)