Skip to content

Commit 7fd9fd4

Browse files
10ne1borkmann
authored andcommitted
tools: Fix unavoidable GCC call in Clang builds
In ChromeOS and Gentoo we catch any unwanted mixed Clang/LLVM and GCC/binutils usage via toolchain wrappers which fail builds. This has revealed that GCC is called unconditionally in Clang configured builds to populate GCC_TOOLCHAIN_DIR. Allow the user to override CLANG_CROSS_FLAGS to avoid the GCC call - in our case we set the var directly in the ebuild recipe. In theory Clang could be able to autodetect these settings so this logic could be removed entirely, but in practice as the commit cebdb73 ("tools: Help cross-building with clang") mentions, this does not always work, so giving distributions more control to specify their flags & sysroot is beneficial. Suggested-by: Manoj Gupta <manojgupta@chromium.com> Suggested-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Nathan Chancellor <nathan@kernel.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Link: https://lore.kernel.org/lkml/87czjk4osi.fsf@ryzen9.i-did-not-set--mail-host-address--so-tickle-me Link: https://lore.kernel.org/bpf/20220308121428.81735-1-adrian.ratiu@collabora.com
1 parent d23a872 commit 7fd9fd4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/scripts/Makefile.include

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,17 @@ ifeq ($(CC_NO_CLANG), 1)
8989
EXTRA_WARNINGS += -Wstrict-aliasing=3
9090

9191
else ifneq ($(CROSS_COMPILE),)
92+
# Allow userspace to override CLANG_CROSS_FLAGS to specify their own
93+
# sysroots and flags or to avoid the GCC call in pure Clang builds.
94+
ifeq ($(CLANG_CROSS_FLAGS),)
9295
CLANG_CROSS_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%))
9396
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)gcc 2>/dev/null))
9497
ifneq ($(GCC_TOOLCHAIN_DIR),)
9598
CLANG_CROSS_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
9699
CLANG_CROSS_FLAGS += --sysroot=$(shell $(CROSS_COMPILE)gcc -print-sysroot)
97100
CLANG_CROSS_FLAGS += --gcc-toolchain=$(realpath $(GCC_TOOLCHAIN_DIR)/..)
98101
endif # GCC_TOOLCHAIN_DIR
102+
endif # CLANG_CROSS_FLAGS
99103
CFLAGS += $(CLANG_CROSS_FLAGS)
100104
AFLAGS += $(CLANG_CROSS_FLAGS)
101105
endif # CROSS_COMPILE

0 commit comments

Comments
 (0)