Right now -no-integrated-as is passed to clang unconditionally during kernel compilation. I would like to make it optional and add a Kconfig switch to toggle it. I will try to work on it in my spare time.
Initial version of what it should look like
diff --git a/Makefile b/Makefile
index 7a7c17eb0..a487f1f5b 100644
--- a/Makefile
+++ b/Makefile
@@ -527,7 +527,11 @@ endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
+ifdef CONFIG_CLANG_USE_INTEGRATED_AS
+CLANG_FLAGS += -integrated-as
+else
CLANG_FLAGS += -no-integrated-as
+endif
KBUILD_CFLAGS += $(CLANG_FLAGS)
KBUILD_AFLAGS += $(CLANG_FLAGS)
export CLANG_FLAGS
diff --git a/init/Kconfig b/init/Kconfig
index 0e2344389..fcab57c66 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -24,6 +24,11 @@ config CLANG_VERSION
int
default $(shell,$(srctree)/scripts/clang-version.sh $(CC))
+config CLANG_USE_INTEGRATED_AS
+ bool "Use Clang integrated assembler"
+ depends on CC_IS_CLANG
+ default CC_IS_CLANG && CLANG_VERSION > 90000
+
config CC_HAS_ASM_GOTO
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
[1] says:
Assembler
Clang can either use LLVM鈥檚 integrated assembler or an external system-specific tool (for instance, > the GNU Assembler on GNU OSes) to produce machine code from assembly. By default, Clang uses > LLVM鈥檚 integrated assembler on all targets where it is supported. If you wish to use the system
assembler instead, use the -fno-integrated-as option."
[2] says:
-fintegrated-as, -fno-integrated-as, -integrated-as
Enable the integrated assembler
bool "Use LLVM鈥檚 integrated assembler with Clang" ?
[1] https://clang.llvm.org/docs/Toolchain.html#assembler
[2] https://clang.llvm.org/docs/ClangCommandLineReference.html#target-dependent-compilation-options
A config option would make allyesconfig builds start failing. Maybe a custom command like variable to Make like AS and CC and friends currently are?
Maybe -no-integrated-as should not be added IF AS was set at the command line? I think that should be the way to go.
diff --git a/Makefile b/Makefile
index aa233492e04a..929b2cca671f 100644
--- a/Makefile
+++ b/Makefile
@@ -527,7 +527,9 @@ endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
+ifeq ($(findstring clang,$(AS)),)
CLANG_FLAGS += -no-integrated-as
+endif
CLANG_FLAGS += -Werror=unknown-warning-option
KBUILD_CFLAGS += $(CLANG_FLAGS)
KBUILD_AFLAGS += $(CLANG_FLAGS)
or
diff --git a/Makefile b/Makefile
index aa233492e04a..4954f1e911be 100644
--- a/Makefile
+++ b/Makefile
@@ -527,7 +527,9 @@ endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
+ifeq ($(shell $(AS) --version 2>&1 | head -n 1 | grep clang),)
CLANG_FLAGS += -no-integrated-as
+endif
CLANG_FLAGS += -Werror=unknown-warning-option
KBUILD_CFLAGS += $(CLANG_FLAGS)
KBUILD_AFLAGS += $(CLANG_FLAGS)
works for all four of these combos:
$ make AS=as CC=clang
$ make AS=clang CC=clang
$ make AS=/usr/bin/clang CC=clang
$ make AS=/usr/bin/as CC=clang
I would think the latter is preferred but I have no strong opinion. This type of change is easily upstreamable I think, I can send it along.
I would think the latter is preferred but I have no strong opinion.
The first doesn't invoke a subshell. ;)
What about if I use AS=clang-8 or AS=clang-9?
The first doesn't invoke a subshell. ;)
Fair point :)
What about if I use
AS=clang-8orAS=clang-9?
Also works because findstring just checks if clang is somewhere in $(AS) not that $(AS) is clang.
Second option looks better to me because it will also work with a clang-based comiler with a different executable name (e.g. ELLCC).
Hmmm, interesting for me the possibility to set AS=clang.
When do people use llvm-as?
Can we use it for CBL?
2nd options looks more familiar to me (similiar setting like for LD etc.)
llvm-as is used for building LLVM assembly. Platform specific assembly can be built with clang (it would either use LLVM's integrated assembler or call external as depending on whether or not -no-integrated-as was set).
@tpimh I agree, I realized that last night and never commented lol.
Tentative patch, let me know if you all want the patch improved in any way.
From 50e90e9d6b9f2ae26656e7eb532ae545567c386a Mon Sep 17 00:00:00 2001
From: Nathan Chancellor <[email protected]>
Date: Thu, 27 Jun 2019 08:58:50 -0700
Subject: [PATCH] kbuild: Add ability to test Clang's integrated assembler
There are some people interested in experimenting with Clang's
integrated assembler. To make it easy to do so without source
modification, allow the user to specify AS=clang as part of the
make command to avoid adding '-no-integrated-as' to the {A,C}FLAGS.
Link: https://github.com/ClangBuiltLinux/linux/issues/577
Suggested-by: Dmitry Golovin <[email protected]>
Signed-off-by: Nathan Chancellor <[email protected]>
---
Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Makefile b/Makefile
index aa233492e04a..4954f1e911be 100644
--- a/Makefile
+++ b/Makefile
@@ -527,7 +527,9 @@ endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
+ifeq ($(shell $(AS) --version 2>&1 | head -n 1 | grep clang),)
CLANG_FLAGS += -no-integrated-as
+endif
CLANG_FLAGS += -Werror=unknown-warning-option
KBUILD_CFLAGS += $(CLANG_FLAGS)
KBUILD_AFLAGS += $(CLANG_FLAGS)
--
2.22.0
It's all fine with me 馃憤
Patch sent: https://lore.kernel.org/lkml/[email protected]/
Merged into mainline: https://git.kernel.org/torvalds/c/876a0600896c1857c79cb58625ff012b27fea9fd
Most helpful comment
or
works for all four of these combos:
I would think the latter is preferred but I have no strong opinion. This type of change is easily upstreamable I think, I can send it along.