[RFC] Makefile: drop CROSS_COMPILE for LLVM=1 LLVM_IAS=1

91 views
Skip to first unread message

Nick Desaulniers

unread,
Jul 7, 2021, 3:03:09 PM7/7/21
to clang-bu...@googlegroups.com, Nick Desaulniers
We get constant feedback that the command line invocation of make is too
long. CROSS_COMPILE is helpful when a toolchain has a prefix of the
target triple, or is an absolute path outside of $PATH, but it's mostly
redundant for a given ARCH.

If CROSS_COMPILE is not set, simply set --target=aarch64-linux for
CLANG_FLAGS, KBUILD_CFLAGS, and KBUILD_AFLAGS.

Previously, we'd cross compile via:
$ ARCH=arm64 CROSS_COMPILE=aarch64-linxu-gnu make LLVM=1 LLVM_IAS=1
Now:
$ ARCH=arm64 make LLVM=1 LLVM_IAS=1

We can drop gnu from the triple, but dropping linux from the triple
produces different .config files for the above invocations for the
defconfig target.

Link: https://github.com/ClangBuiltLinux/linux/issues/1399
Suggested-by: Arnd Bergmann <ar...@kernel.org>
Suggested-by: Fangrui Song <mas...@google.com>
Suggested-by: Nathan Chancellor <nat...@kernel.org>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
Note: not a serious patch, just need something to link to from lore.
Sorry for the noise.


MAINTAINERS | 1 +
Makefile | 24 +++------------------
scripts/Makefile.LLVMTargetTriple | 35 +++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 21 deletions(-)
create mode 100644 scripts/Makefile.LLVMTargetTriple

diff --git a/MAINTAINERS b/MAINTAINERS
index 548783bf6505..0da239be76d8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4500,6 +4500,7 @@ B: https://github.com/ClangBuiltLinux/linux/issues
C: irc://chat.freenode.net/clangbuiltlinux
F: Documentation/kbuild/llvm.rst
F: include/linux/compiler-clang.h
+F: scripts/Makefile.LLVMTargetTriple
F: scripts/clang-tools/
K: \b(?i:clang|llvm)\b

diff --git a/Makefile b/Makefile
index 6fbb35661354..fffe75a9d76b 100644
--- a/Makefile
+++ b/Makefile
@@ -627,27 +627,9 @@ endif
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -n 1))

-TENTATIVE_CLANG_FLAGS := -Werror=unknown-warning-option
-
-ifneq ($(CROSS_COMPILE),)
-TENTATIVE_CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
-endif
-ifeq ($(LLVM_IAS),1)
-TENTATIVE_CLANG_FLAGS += -integrated-as
-else
-TENTATIVE_CLANG_FLAGS += -no-integrated-as
-GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
-TENTATIVE_CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-endif
-
-export TENTATIVE_CLANG_FLAGS
-
-ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
-CLANG_FLAGS += $(TENTATIVE_CLANG_FLAGS)
-KBUILD_CFLAGS += $(CLANG_FLAGS)
-KBUILD_AFLAGS += $(CLANG_FLAGS)
-export CLANG_FLAGS
-endif
+# Figure out the target triple needed for cross compiling with LLVM. Defines
+# TENTATIVE_CLANG_FLAGS and . Depends on CC_VERSION_TEXT.
+include $(srctree)/scripts/Makefile.LLVMTargetTriple

# Include this also for config targets because some architectures need
# cc-cross-prefix to determine CROSS_COMPILE.
diff --git a/scripts/Makefile.LLVMTargetTriple b/scripts/Makefile.LLVMTargetTriple
new file mode 100644
index 000000000000..e21df3482c67
--- /dev/null
+++ b/scripts/Makefile.LLVMTargetTriple
@@ -0,0 +1,35 @@
+TENTATIVE_CLANG_FLAGS := -Werror=unknown-warning-option
+
+ifeq ($(CROSS_COMPILE),)
+ifneq ($(LLVM),)
+ifneq ($(LLVM_IAS),)
+ifeq ($(ARCH),arm64)
+TENTATIVE_CLANG_FLAGS += --target=aarch64-linux
+# TODO: add `else ifeq` for other architectures.
+# TODO: arm64 compat vdso (CROSS_COMPILE_COMPAT)
+else
+$(error Specify CROSS_COMPILE or add '--target=' option to Makefile)
+endif # ARCH
+endif # LLVM_IAS
+endif # LLVM
+else
+# Even when not using clang as CC, we still need to build up "tentative" flags
+# for bindgen when using Rust.
+TENTATIVE_CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
+endif # CROSS_COMPILE
+
+ifeq ($(LLVM_IAS),1)
+TENTATIVE_CLANG_FLAGS += -integrated-as
+else
+TENTATIVE_CLANG_FLAGS += -no-integrated-as
+GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
+TENTATIVE_CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
+endif
+
+ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
+CLANG_FLAGS += $(TENTATIVE_CLANG_FLAGS)
+KBUILD_CFLAGS += $(CLANG_FLAGS)
+KBUILD_AFLAGS += $(CLANG_FLAGS)
+endif
+
+export TENTATIVE_CLANG_FLAGS CLANG_FLAGS
--
2.32.0.93.g670b81a890-goog

Reply all
Reply to author
Forward
0 new messages