Skip to content

Commit 69ce955

Browse files
agnersMrRob0-X
authored andcommitted
kbuild: allow to use GCC toolchain not in Clang search path
commit ef8c4ed9db80261f397f0c0bf723684601ae3b52 upstream. When using a GCC cross toolchain which is not in a compiled in Clang search path, Clang reverts to the system assembler and linker. This leads to assembler or linker errors, depending on which tool is first used for a given architecture. It seems that Clang is not searching $PATH for a matching assembler or linker. Make sure that Clang picks up the correct assembler or linker by passing the cross compilers bin directory as search path. This allows to use Clang provided by distributions with GCC toolchains not in /usr/bin. Link: ClangBuiltLinux/linux#78 Signed-off-by: Stefan Agner <[email protected]> Reviewed-and-tested-by: Nick Desaulniers <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> [nc: Adjust context] Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Change-Id: I3bc0f10512f7f932a43a9cdf55579e4fec3da230
1 parent 88c0bb2 commit 69ce955

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

Makefile

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -607,37 +607,19 @@ all: vmlinux
607607

608608
ifeq ($(cc-name),clang)
609609
ifneq ($(CROSS_COMPILE),)
610-
CLANG_TRIPLE ?= $(CROSS_COMPILE)
611610
CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
612-
GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..)
611+
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
612+
CLANG_PREFIX := --prefix=$(GCC_TOOLCHAIN_DIR)
613+
GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
613614
endif
614615
ifneq ($(GCC_TOOLCHAIN),)
615616
CLANG_GCC_TC := --gcc-toolchain=$(GCC_TOOLCHAIN)
616617
endif
617-
KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
618-
KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
619-
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
620-
KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
621-
KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
622-
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
623-
KBUILD_CFLAGS += $(call cc-disable-warning, duplicate-decl-specifier)
624-
KBUILD_CFLAGS += $(call cc-disable-warning, pointer-bool-conversion)
625-
# Quiet clang warning: comparison of unsigned expression < 0 is always false
626-
KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
627-
# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
628-
# source of a reference will be _MergedGlobals and not on of the whitelisted names.
629-
# See modpost pattern 2
630-
KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
631-
KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
618+
KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
619+
KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
632620
KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
633621
KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
634-
else
635-
636-
# These warnings generated too much noise in a regular build.
637-
# Use make W=1 to enable them (see scripts/Makefile.build)
638-
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
639622
endif
640-
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
641623

642624
include $(srctree)/arch/$(SRCARCH)/Makefile
643625

@@ -733,6 +715,25 @@ ifdef CONFIG_RKP_CFP_ROPP
733715
KBUILD_CFLAGS += -ffixed-x16 -ffixed-x17
734716
endif
735717

718+
ifeq ($(cc-name),clang)
719+
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
720+
KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
721+
KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
722+
# Quiet clang warning: comparison of unsigned expression < 0 is always false
723+
KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
724+
# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
725+
# source of a reference will be _MergedGlobals and not on of the whitelisted names.
726+
# See modpost pattern 2
727+
KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
728+
KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
729+
else
730+
731+
# These warnings generated too much noise in a regular build.
732+
# Use make W=1 to enable them (see scripts/Makefile.build)
733+
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
734+
endif
735+
736+
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
736737
ifdef CONFIG_FRAME_POINTER
737738
KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
738739
else

0 commit comments

Comments
 (0)