* LLVM=1 patches for 5.4
@ 2020-08-20 20:14 Nick Desaulniers
2020-08-20 20:27 ` Nick Desaulniers
2020-08-24 8:10 ` Greg KH
0 siblings, 2 replies; 4+ messages in thread
From: Nick Desaulniers @ 2020-08-20 20:14 UTC (permalink / raw)
To: Greg KH, Sasha Levin, Masahiro Yamada
Cc: # 3.4.x, clang-built-linux, Nathan Chancellor, Dmitry Golovin,
Geert Uytterhoeven, Fangrui Song, Sedat Dilek, Kees Cook
[-- Attachment #1: Type: text/plain, Size: 1982 bytes --]
Dear stable kernel maintainers,
Please consider the attached mbox file, which contains 9 patches which
cherry pick cleanly onto 5.4:
1. commit fcf1b6a35c16 ("Documentation/llvm: add documentation on
building w/ Clang/LLVM")
2. commit 0f44fbc162b7 ("Documentation/llvm: fix the name of llvm-size")
3. commit 63b903dfebde ("net: wan: wanxl: use allow to pass
CROSS_COMPILE_M68k for rebuilding firmware")
4. commit 734f3719d343 ("net: wan: wanxl: use $(M68KCC) instead of
$(M68KAS) for rebuilding firmware")
5. commit eefb8c124fd9 ("x86/boot: kbuild: allow readelf executable to
be specified")
6. commit 94f7345b7124 ("kbuild: remove PYTHON2 variable")
7. commit aa824e0c962b ("kbuild: remove AS variable")
8. commit 7e20e47c70f8 ("kbuild: replace AS=clang with LLVM_IAS=1")
9. commit a0d1c951ef08 ("kbuild: support LLVM=1 to switch the default
tools to Clang/LLVM")
This series improves/simplifies building kernels with Clang and LLVM
utilities; it will help the various CI systems testing kernels built
with Clang+LLVM utilities (in fact I will be pointing to this, if
accepted, next week at plumbers with those CI system maintainers), and
we will make immediate use of it in Android (see also:
https://android-review.googlesource.com/c/platform/prebuilts/clang/host/linux-x86/+/1405387).
We can always carry it out of tree in Android, but I think the series
is fairly tame, and would prefer not to.
I only particularly care about 5+8+9 (eefb8c124fd9, 7e20e47c70f8, and
a0d1c951ef08), but the rest are required for them to cherry-pick
cleanly. I don't mind separating those three out, though they won't
be clean cherry-picks at that point. It might be good to have
Masahiro review the series. If accepted, I plan to wire up test
coverage of these immediately in
https://github.com/ClangBuiltLinux/continuous-integration/issues/300.
Most of the above landed in v5.7-rc1, with 94f7345b7124 landing in
v5.6-rc1 and eefb8c124fd9 landing in v5.5-rc3.
--
Thanks,
~Nick Desaulniers
[-- Attachment #2: llvm_1.mbox --]
[-- Type: application/octet-stream, Size: 24912 bytes --]
From 52dd5c2a6ce76063f3db72796940de5660be3ca4 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers@google.com>
Date: Wed, 26 Feb 2020 15:23:36 -0800
Subject: [PATCH 1/9] Documentation/llvm: add documentation on building w/
Clang/LLVM
commit fcf1b6a35c16ac500fa908a4022238e5d666eabf upstream.
added to kbuild documentation. Provides more official info on building
kernels with Clang and LLVM than our wiki.
Suggested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Reviewed-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
Documentation/kbuild/index.rst | 1 +
Documentation/kbuild/llvm.rst | 80 ++++++++++++++++++++++++++++++++++
MAINTAINERS | 1 +
3 files changed, 82 insertions(+)
create mode 100644 Documentation/kbuild/llvm.rst
diff --git a/Documentation/kbuild/index.rst b/Documentation/kbuild/index.rst
index 0f144fad99a6..3882bd5f7728 100644
--- a/Documentation/kbuild/index.rst
+++ b/Documentation/kbuild/index.rst
@@ -19,6 +19,7 @@ Kernel Build System
issues
reproducible-builds
+ llvm
.. only:: subproject and html
diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
new file mode 100644
index 000000000000..d6c79eb4e23e
--- /dev/null
+++ b/Documentation/kbuild/llvm.rst
@@ -0,0 +1,80 @@
+==============================
+Building Linux with Clang/LLVM
+==============================
+
+This document covers how to build the Linux kernel with Clang and LLVM
+utilities.
+
+About
+-----
+
+The Linux kernel has always traditionally been compiled with GNU toolchains
+such as GCC and binutils. Ongoing work has allowed for `Clang
+<https://clang.llvm.org/>`_ and `LLVM <https://llvm.org/>`_ utilities to be
+used as viable substitutes. Distributions such as `Android
+<https://www.android.com/>`_, `ChromeOS
+<https://www.chromium.org/chromium-os>`_, and `OpenMandriva
+<https://www.openmandriva.org/>`_ use Clang built kernels. `LLVM is a
+collection of toolchain components implemented in terms of C++ objects
+<https://www.aosabook.org/en/llvm.html>`_. Clang is a front-end to LLVM that
+supports C and the GNU C extensions required by the kernel, and is pronounced
+"klang," not "see-lang."
+
+Clang
+-----
+
+The compiler used can be swapped out via `CC=` command line argument to `make`.
+`CC=` should be set when selecting a config and during a build.
+
+ make CC=clang defconfig
+
+ make CC=clang
+
+Cross Compiling
+---------------
+
+A single Clang compiler binary will typically contain all supported backends,
+which can help simplify cross compiling.
+
+ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make CC=clang
+
+`CROSS_COMPILE` is not used to prefix the Clang compiler binary, instead
+`CROSS_COMPILE` is used to set a command line flag: `--target <triple>`. For
+example:
+
+ clang --target aarch64-linux-gnu foo.c
+
+LLVM Utilities
+--------------
+
+LLVM has substitutes for GNU binutils utilities. These can be invoked as
+additional parameters to `make`.
+
+ make CC=clang AS=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \\
+ OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-objsize \\
+ READELF=llvm-readelf HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar \\
+ HOSTLD=ld.lld
+
+Getting Help
+------------
+
+- `Website <https://clangbuiltlinux.github.io/>`_
+- `Mailing List <https://groups.google.com/forum/#!forum/clang-built-linux>`_: <clang-built-linux@googlegroups.com>
+- `Issue Tracker <https://github.com/ClangBuiltLinux/linux/issues>`_
+- IRC: #clangbuiltlinux on chat.freenode.net
+- `Telegram <https://t.me/ClangBuiltLinux>`_: @ClangBuiltLinux
+- `Wiki <https://github.com/ClangBuiltLinux/linux/wiki>`_
+- `Beginner Bugs <https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22>`_
+
+Getting LLVM
+-------------
+
+- http://releases.llvm.org/download.html
+- https://github.com/llvm/llvm-project
+- https://llvm.org/docs/GettingStarted.html
+- https://llvm.org/docs/CMake.html
+- https://apt.llvm.org/
+- https://www.archlinux.org/packages/extra/x86_64/llvm/
+- https://github.com/ClangBuiltLinux/tc-build
+- https://github.com/ClangBuiltLinux/linux/wiki/Building-Clang-from-source
+- https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/
diff --git a/MAINTAINERS b/MAINTAINERS
index fe6fa5d3a63e..1407008df749 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4028,6 +4028,7 @@ B: https://github.com/ClangBuiltLinux/linux/issues
C: irc://chat.freenode.net/clangbuiltlinux
S: Supported
K: \b(?i:clang|llvm)\b
+F: Documentation/kbuild/llvm.rst
CLEANCACHE API
M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
--
2.28.0.297.g1956fa8f8d-goog
From 32f506fb476d511da81dc550d64e430da237da49 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Thu, 2 Apr 2020 10:38:42 -0700
Subject: [PATCH 2/9] Documentation/llvm: fix the name of llvm-size
commit 0f44fbc162b737ff6251ae248184390ae2279fee upstream.
The tool is called llvm-size, not llvm-objsize.
Fixes: fcf1b6a35c16 ("Documentation/llvm: add documentation on building w/ Clang/LLVM")
Signed-off-by: Fangrui Song <maskray@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Documentation/kbuild/llvm.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
index d6c79eb4e23e..eefbdfa3e4d9 100644
--- a/Documentation/kbuild/llvm.rst
+++ b/Documentation/kbuild/llvm.rst
@@ -51,7 +51,7 @@ LLVM has substitutes for GNU binutils utilities. These can be invoked as
additional parameters to `make`.
make CC=clang AS=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \\
- OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-objsize \\
+ OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-size \\
READELF=llvm-readelf HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar \\
HOSTLD=ld.lld
--
2.28.0.297.g1956fa8f8d-goog
From ca258a40a1675124f0b423833b1c9821d7f6055e Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Thu, 26 Mar 2020 14:57:15 +0900
Subject: [PATCH 3/9] net: wan: wanxl: use allow to pass CROSS_COMPILE_M68k for
rebuilding firmware
commit 63b903dfebdea92aa92ad337d8451a6fbfeabf9d upstream.
As far as I understood from the Kconfig help text, this build rule is
used to rebuild the driver firmware, which runs on an old m68k-based
chip. So, you need m68k tools for the firmware rebuild.
wanxl.c is a PCI driver, but CONFIG_M68K does not select CONFIG_HAVE_PCI.
So, you cannot enable CONFIG_WANXL_BUILD_FIRMWARE for ARCH=m68k. In other
words, ifeq ($(ARCH),m68k) is false here.
I am keeping the dead code for now, but rebuilding the firmware requires
'as68k' and 'ld68k', which I do not have in hand.
Instead, the kernel.org m68k GCC [1] successfully built it.
Allowing a user to pass in CROSS_COMPILE_M68K= is handier.
[1] https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-m68k-linux.tar.xz
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
drivers/net/wan/Kconfig | 2 +-
drivers/net/wan/Makefile | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index dd1a147f2971..058d77d2e693 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -200,7 +200,7 @@ config WANXL_BUILD_FIRMWARE
depends on WANXL && !PREVENT_FIRMWARE_BUILD
help
Allows you to rebuild firmware run by the QUICC processor.
- It requires as68k, ld68k and hexdump programs.
+ It requires m68k toolchains and hexdump programs.
You should never need this option, say N.
diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile
index 701f5d2fe3b6..995277c657a1 100644
--- a/drivers/net/wan/Makefile
+++ b/drivers/net/wan/Makefile
@@ -40,17 +40,17 @@ $(obj)/wanxl.o: $(obj)/wanxlfw.inc
ifeq ($(CONFIG_WANXL_BUILD_FIRMWARE),y)
ifeq ($(ARCH),m68k)
- AS68K = $(AS)
- LD68K = $(LD)
+ M68KAS = $(AS)
+ M68KLD = $(LD)
else
- AS68K = as68k
- LD68K = ld68k
+ M68KAS = $(CROSS_COMPILE_M68K)as
+ M68KLD = $(CROSS_COMPILE_M68K)ld
endif
quiet_cmd_build_wanxlfw = BLD FW $@
cmd_build_wanxlfw = \
- $(CPP) -D__ASSEMBLY__ -Wp,-MD,$(depfile) -I$(srctree)/include/uapi $< | $(AS68K) -m68360 -o $(obj)/wanxlfw.o; \
- $(LD68K) --oformat binary -Ttext 0x1000 $(obj)/wanxlfw.o -o $(obj)/wanxlfw.bin; \
+ $(CPP) -D__ASSEMBLY__ -Wp,-MD,$(depfile) -I$(srctree)/include/uapi $< | $(M68KAS) -m68360 -o $(obj)/wanxlfw.o; \
+ $(M68KLD) --oformat binary -Ttext 0x1000 $(obj)/wanxlfw.o -o $(obj)/wanxlfw.bin; \
hexdump -ve '"\n" 16/1 "0x%02X,"' $(obj)/wanxlfw.bin | sed 's/0x ,//g;1s/^/static const u8 firmware[]={/;$$s/,$$/\n};\n/' >$(obj)/wanxlfw.inc; \
rm -f $(obj)/wanxlfw.bin $(obj)/wanxlfw.o
--
2.28.0.297.g1956fa8f8d-goog
From 791d921e52348413f842c7e33148617e696c02fe Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Thu, 26 Mar 2020 14:57:16 +0900
Subject: [PATCH 4/9] net: wan: wanxl: use $(M68KCC) instead of $(M68KAS) for
rebuilding firmware
commit 734f3719d3438f9cc181d674c33ca9762e9148a1 upstream.
The firmware source, wanxlfw.S, is currently compiled by the combo of
$(CPP) and $(M68KAS). This is not what we usually do for compiling *.S
files. In fact, this Makefile is the only user of $(AS) in the kernel
build.
Instead of combining $(CPP) and (AS) from different tool sets, using
$(M68KCC) as an assembler driver is simpler, and saner.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
drivers/net/wan/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile
index 995277c657a1..cf7a0a65aae8 100644
--- a/drivers/net/wan/Makefile
+++ b/drivers/net/wan/Makefile
@@ -40,16 +40,16 @@ $(obj)/wanxl.o: $(obj)/wanxlfw.inc
ifeq ($(CONFIG_WANXL_BUILD_FIRMWARE),y)
ifeq ($(ARCH),m68k)
- M68KAS = $(AS)
+ M68KCC = $(CC)
M68KLD = $(LD)
else
- M68KAS = $(CROSS_COMPILE_M68K)as
+ M68KCC = $(CROSS_COMPILE_M68K)gcc
M68KLD = $(CROSS_COMPILE_M68K)ld
endif
quiet_cmd_build_wanxlfw = BLD FW $@
cmd_build_wanxlfw = \
- $(CPP) -D__ASSEMBLY__ -Wp,-MD,$(depfile) -I$(srctree)/include/uapi $< | $(M68KAS) -m68360 -o $(obj)/wanxlfw.o; \
+ $(M68KCC) -D__ASSEMBLY__ -Wp,-MD,$(depfile) -I$(srctree)/include/uapi -c -o $(obj)/wanxlfw.o $<; \
$(M68KLD) --oformat binary -Ttext 0x1000 $(obj)/wanxlfw.o -o $(obj)/wanxlfw.bin; \
hexdump -ve '"\n" 16/1 "0x%02X,"' $(obj)/wanxlfw.bin | sed 's/0x ,//g;1s/^/static const u8 firmware[]={/;$$s/,$$/\n};\n/' >$(obj)/wanxlfw.inc; \
rm -f $(obj)/wanxlfw.bin $(obj)/wanxlfw.o
--
2.28.0.297.g1956fa8f8d-goog
From 963cdc94b730d2a5ba8b5cebd65337a124401c3d Mon Sep 17 00:00:00 2001
From: Dmitry Golovin <dima@golovin.in>
Date: Thu, 5 Dec 2019 00:54:41 +0200
Subject: [PATCH 5/9] x86/boot: kbuild: allow readelf executable to be
specified
commit eefb8c124fd969e9a174ff2bedff86aa305a7438 upstream.
Introduce a new READELF variable to top-level Makefile, so the name of
readelf binary can be specified.
Before this change the name of the binary was hardcoded to
"$(CROSS_COMPILE)readelf" which might not be present for every
toolchain.
This allows to build with LLVM Object Reader by using make parameter
READELF=llvm-readelf.
Link: https://github.com/ClangBuiltLinux/linux/issues/771
Signed-off-by: Dmitry Golovin <dima@golovin.in>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Makefile | 3 ++-
arch/x86/boot/compressed/Makefile | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index cc72b8472f24..971ed7b03c56 100644
--- a/Makefile
+++ b/Makefile
@@ -414,6 +414,7 @@ STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OBJSIZE = $(CROSS_COMPILE)size
+READELF = $(CROSS_COMPILE)readelf
PAHOLE = pahole
LEX = flex
YACC = bison
@@ -472,7 +473,7 @@ GCC_PLUGINS_CFLAGS :=
CLANG_FLAGS :=
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
-export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK INSTALLKERNEL
+export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL
export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 6b84afdd7538..98aac5b4bdb7 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -102,7 +102,7 @@ vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
quiet_cmd_check_data_rel = DATAREL $@
define cmd_check_data_rel
for obj in $(filter %.o,$^); do \
- ${CROSS_COMPILE}readelf -S $$obj | grep -qF .rel.local && { \
+ $(READELF) -S $$obj | grep -qF .rel.local && { \
echo "error: $$obj has data relocations!" >&2; \
exit 1; \
} || true; \
--
2.28.0.297.g1956fa8f8d-goog
From ac39d2f3b13f640ccf3321d73a8482ff4bc3adbd Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Mon, 6 Jan 2020 17:36:28 +0900
Subject: [PATCH 6/9] kbuild: remove PYTHON2 variable
commit 94f7345b712405b79647a6a4bf8ccbd0d78fa69d upstream.
Python 2 has retired. There is no user of this variable.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 971ed7b03c56..9db9385c335d 100644
--- a/Makefile
+++ b/Makefile
@@ -423,7 +423,6 @@ INSTALLKERNEL := installkernel
DEPMOD = /sbin/depmod
PERL = perl
PYTHON = python
-PYTHON2 = python2
PYTHON3 = python3
CHECK = sparse
BASH = bash
@@ -474,7 +473,7 @@ CLANG_FLAGS :=
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL
-export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
+export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
--
2.28.0.297.g1956fa8f8d-goog
From c45a815ff14a684eb7d71875a694ea3e9b3bbaf8 Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Thu, 26 Mar 2020 14:57:18 +0900
Subject: [PATCH 7/9] kbuild: remove AS variable
commit aa824e0c962b532d5073cbb41b2efcd6f5e72bae upstream.
As commit 5ef872636ca7 ("kbuild: get rid of misleading $(AS) from
documents") noted, we rarely use $(AS) directly in the kernel build.
Now that the only/last user of $(AS) in drivers/net/wan/Makefile was
converted to $(CC), $(AS) is no longer used in the build process.
You can still pass in AS=clang, which is just a switch to turn on
the LLVM integrated assembler.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Makefile | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 9db9385c335d..7c5f09904bb5 100644
--- a/Makefile
+++ b/Makefile
@@ -404,7 +404,6 @@ KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
# Make variables (CC, etc...)
-AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
@@ -471,7 +470,7 @@ KBUILD_LDFLAGS :=
GCC_PLUGINS_CFLAGS :=
CLANG_FLAGS :=
-export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
+export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL
export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
@@ -534,7 +533,7 @@ endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
-ifeq ($(shell $(AS) --version 2>&1 | head -n 1 | grep clang),)
+ifeq ($(if $(AS),$(shell $(AS) --version 2>&1 | head -n 1 | grep clang)),)
CLANG_FLAGS += -no-integrated-as
endif
CLANG_FLAGS += -Werror=unknown-warning-option
--
2.28.0.297.g1956fa8f8d-goog
From 5a7fd3e996f640114bb6ca27d7303f92af5e4894 Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Wed, 8 Apr 2020 10:36:22 +0900
Subject: [PATCH 8/9] kbuild: replace AS=clang with LLVM_IAS=1
commit 7e20e47c70f810d678d02941fa3c671209c4ca97 upstream.
The 'AS' variable is unused for building the kernel. Only the remaining
usage is to turn on the integrated assembler. A boolean flag is a better
fit for this purpose.
AS=clang was added for experts. So, I replaced it with LLVM_IAS=1,
breaking the backward compatibility.
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Documentation/kbuild/llvm.rst | 5 ++++-
Makefile | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
index eefbdfa3e4d9..450708534860 100644
--- a/Documentation/kbuild/llvm.rst
+++ b/Documentation/kbuild/llvm.rst
@@ -50,11 +50,14 @@ LLVM Utilities
LLVM has substitutes for GNU binutils utilities. These can be invoked as
additional parameters to `make`.
- make CC=clang AS=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \\
+ make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \\
OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-size \\
READELF=llvm-readelf HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar \\
HOSTLD=ld.lld
+Currently, the integrated assembler is disabled by default. You can pass
+`LLVM_IAS=1` to enable it.
+
Getting Help
------------
diff --git a/Makefile b/Makefile
index 7c5f09904bb5..552640a22a0c 100644
--- a/Makefile
+++ b/Makefile
@@ -533,7 +533,7 @@ endif
ifneq ($(GCC_TOOLCHAIN),)
CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
endif
-ifeq ($(if $(AS),$(shell $(AS) --version 2>&1 | head -n 1 | grep clang)),)
+ifneq ($(LLVM_IAS),1)
CLANG_FLAGS += -no-integrated-as
endif
CLANG_FLAGS += -Werror=unknown-warning-option
--
2.28.0.297.g1956fa8f8d-goog
From 32509f91e5156984411c4f90502aa32442342e50 Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Wed, 8 Apr 2020 10:36:23 +0900
Subject: [PATCH 9/9] kbuild: support LLVM=1 to switch the default tools to
Clang/LLVM
commit a0d1c951ef08ed24f35129267e3595d86f57f5d3 upstream.
As Documentation/kbuild/llvm.rst implies, building the kernel with a
full set of LLVM tools gets very verbose and unwieldy.
Provide a single switch LLVM=1 to use Clang and LLVM tools instead
of GCC and Binutils. You can pass it from the command line or as an
environment variable.
Please note LLVM=1 does not turn on the integrated assembler. You need
to pass LLVM_IAS=1 to use it. When the upstream kernel is ready for the
integrated assembler, I think we can make it default.
We discussed what we need, and we agreed to go with a simple boolean
flag that switches both target and host tools:
https://lkml.org/lkml/2020/3/28/494
https://lkml.org/lkml/2020/4/3/43
Some items discussed, but not adopted:
- LLVM_DIR
When multiple versions of LLVM are installed, I just thought supporting
LLVM_DIR=/path/to/my/llvm/bin/ might be useful.
CC = $(LLVM_DIR)clang
LD = $(LLVM_DIR)ld.lld
...
However, we can handle this by modifying PATH. So, we decided to not do
this.
- LLVM_SUFFIX
Some distributions (e.g. Debian) package specific versions of LLVM with
naming conventions that use the version as a suffix.
CC = clang$(LLVM_SUFFIX)
LD = ld.lld(LLVM_SUFFIX)
...
will allow a user to pass LLVM_SUFFIX=-11 to use clang-11 etc.,
but the suffixed versions in /usr/bin/ are symlinks to binaries in
/usr/lib/llvm-#/bin/, so this can also be handled by PATH.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com> # build
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Documentation/kbuild/kbuild.rst | 5 +++++
Documentation/kbuild/llvm.rst | 8 ++++++--
Makefile | 29 +++++++++++++++++++++++------
tools/objtool/Makefile | 6 ++++++
4 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
index f1e5dce86af7..852ccc551bb3 100644
--- a/Documentation/kbuild/kbuild.rst
+++ b/Documentation/kbuild/kbuild.rst
@@ -262,3 +262,8 @@ KBUILD_BUILD_USER, KBUILD_BUILD_HOST
These two variables allow to override the user@host string displayed during
boot and in /proc/version. The default value is the output of the commands
whoami and host, respectively.
+
+LLVM
+----
+If this variable is set to 1, Kbuild will use Clang and LLVM utilities instead
+of GCC and GNU binutils to build the kernel.
diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
index 450708534860..c776b6eee969 100644
--- a/Documentation/kbuild/llvm.rst
+++ b/Documentation/kbuild/llvm.rst
@@ -47,8 +47,12 @@ example:
LLVM Utilities
--------------
-LLVM has substitutes for GNU binutils utilities. These can be invoked as
-additional parameters to `make`.
+LLVM has substitutes for GNU binutils utilities. Kbuild supports `LLVM=1`
+to enable them.
+
+ make LLVM=1
+
+They can be enabled individually. The full list of the parameters:
make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \\
OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-size \\
diff --git a/Makefile b/Makefile
index 552640a22a0c..a5237dd861cc 100644
--- a/Makefile
+++ b/Makefile
@@ -394,8 +394,13 @@ HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
-HOSTCC = gcc
-HOSTCXX = g++
+ifneq ($(LLVM),)
+HOSTCC = clang
+HOSTCXX = clang++
+else
+HOSTCC = gcc
+HOSTCXX = g++
+endif
KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
-fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
$(HOSTCFLAGS)
@@ -404,16 +409,28 @@ KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
# Make variables (CC, etc...)
-LD = $(CROSS_COMPILE)ld
-CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
+ifneq ($(LLVM),)
+CC = clang
+LD = ld.lld
+AR = llvm-ar
+NM = llvm-nm
+OBJCOPY = llvm-objcopy
+OBJDUMP = llvm-objdump
+READELF = llvm-readelf
+OBJSIZE = llvm-size
+STRIP = llvm-strip
+else
+CC = $(CROSS_COMPILE)gcc
+LD = $(CROSS_COMPILE)ld
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
-STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
-OBJSIZE = $(CROSS_COMPILE)size
READELF = $(CROSS_COMPILE)readelf
+OBJSIZE = $(CROSS_COMPILE)size
+STRIP = $(CROSS_COMPILE)strip
+endif
PAHOLE = pahole
LEX = flex
YACC = bison
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index ee08aeff30a1..f591c4d1b6fe 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -3,9 +3,15 @@ include ../scripts/Makefile.include
include ../scripts/Makefile.arch
# always use the host compiler
+ifneq ($(LLVM),)
+HOSTAR ?= llvm-ar
+HOSTCC ?= clang
+HOSTLD ?= ld.lld
+else
HOSTAR ?= ar
HOSTCC ?= gcc
HOSTLD ?= ld
+endif
AR = $(HOSTAR)
CC = $(HOSTCC)
LD = $(HOSTLD)
--
2.28.0.297.g1956fa8f8d-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: LLVM=1 patches for 5.4
2020-08-20 20:14 LLVM=1 patches for 5.4 Nick Desaulniers
@ 2020-08-20 20:27 ` Nick Desaulniers
2020-08-20 20:44 ` Kees Cook
2020-08-24 8:10 ` Greg KH
1 sibling, 1 reply; 4+ messages in thread
From: Nick Desaulniers @ 2020-08-20 20:27 UTC (permalink / raw)
To: Greg KH, Sasha Levin, Masahiro Yamada
Cc: # 3.4.x, clang-built-linux, Nathan Chancellor, Dmitry Golovin,
Geert Uytterhoeven, Fangrui Song, Sedat Dilek, Kees Cook
On Thu, Aug 20, 2020 at 1:14 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
Oh, I almost forgot, here's a picture of my cat who helped me by
trying to lay on my keyboard mid-interactive rebase of this series.
https://photos.app.goo.gl/J7CtBJtHmiuzhSfq7
I asked him nicely to move; he proceeded to bite me, and not comply.
>
> Dear stable kernel maintainers,
> Please consider the attached mbox file, which contains 9 patches which
> cherry pick cleanly onto 5.4:
>
> 1. commit fcf1b6a35c16 ("Documentation/llvm: add documentation on
> building w/ Clang/LLVM")
> 2. commit 0f44fbc162b7 ("Documentation/llvm: fix the name of llvm-size")
> 3. commit 63b903dfebde ("net: wan: wanxl: use allow to pass
> CROSS_COMPILE_M68k for rebuilding firmware")
> 4. commit 734f3719d343 ("net: wan: wanxl: use $(M68KCC) instead of
> $(M68KAS) for rebuilding firmware")
> 5. commit eefb8c124fd9 ("x86/boot: kbuild: allow readelf executable to
> be specified")
> 6. commit 94f7345b7124 ("kbuild: remove PYTHON2 variable")
> 7. commit aa824e0c962b ("kbuild: remove AS variable")
> 8. commit 7e20e47c70f8 ("kbuild: replace AS=clang with LLVM_IAS=1")
> 9. commit a0d1c951ef08 ("kbuild: support LLVM=1 to switch the default
> tools to Clang/LLVM")
>
> This series improves/simplifies building kernels with Clang and LLVM
> utilities; it will help the various CI systems testing kernels built
> with Clang+LLVM utilities (in fact I will be pointing to this, if
> accepted, next week at plumbers with those CI system maintainers), and
> we will make immediate use of it in Android (see also:
> https://android-review.googlesource.com/c/platform/prebuilts/clang/host/linux-x86/+/1405387).
> We can always carry it out of tree in Android, but I think the series
> is fairly tame, and would prefer not to.
>
> I only particularly care about 5+8+9 (eefb8c124fd9, 7e20e47c70f8, and
> a0d1c951ef08), but the rest are required for them to cherry-pick
> cleanly. I don't mind separating those three out, though they won't
> be clean cherry-picks at that point. It might be good to have
> Masahiro review the series. If accepted, I plan to wire up test
> coverage of these immediately in
> https://github.com/ClangBuiltLinux/continuous-integration/issues/300.
>
> Most of the above landed in v5.7-rc1, with 94f7345b7124 landing in
> v5.6-rc1 and eefb8c124fd9 landing in v5.5-rc3.
> --
> Thanks,
> ~Nick Desaulniers
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: LLVM=1 patches for 5.4
2020-08-20 20:27 ` Nick Desaulniers
@ 2020-08-20 20:44 ` Kees Cook
0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2020-08-20 20:44 UTC (permalink / raw)
To: Nick Desaulniers
Cc: Greg KH, Sasha Levin, Masahiro Yamada, # 3.4.x, clang-built-linux,
Nathan Chancellor, Dmitry Golovin, Geert Uytterhoeven,
Fangrui Song, Sedat Dilek
On Thu, Aug 20, 2020 at 01:27:32PM -0700, Nick Desaulniers wrote:
> On Thu, Aug 20, 2020 at 1:14 PM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
>
> Oh, I almost forgot, here's a picture of my cat who helped me by
> trying to lay on my keyboard mid-interactive rebase of this series.
> https://photos.app.goo.gl/J7CtBJtHmiuzhSfq7
> I asked him nicely to move; he proceeded to bite me, and not comply.
I think this needs to be an ongoing change to the stable kernel process.
Since such things require documentation, I propose:
diff --git a/Documentation/process/stable-kernel-rules.rst b/Documentation/process/stable-kernel-rules.rst
index 06f743b612c4..928f6f3ce6e2 100644
--- a/Documentation/process/stable-kernel-rules.rst
+++ b/Documentation/process/stable-kernel-rules.rst
@@ -35,6 +35,7 @@ Rules on what kind of patches are accepted, and which ones are not, into the
Procedure for submitting patches to the -stable tree
----------------------------------------------------
+ - Preference may be given to submissions featuring pictures of cats. Also dogs.
- If the patch covers files in net/ or drivers/net please follow netdev stable
submission guidelines as described in
:ref:`Documentation/networking/netdev-FAQ.rst <netdev-FAQ>`
> > Dear stable kernel maintainers,
> > Please consider the attached mbox file, which contains 9 patches which
> > cherry pick cleanly onto 5.4:
> >
> > 1. commit fcf1b6a35c16 ("Documentation/llvm: add documentation on
> > building w/ Clang/LLVM")
> > 2. commit 0f44fbc162b7 ("Documentation/llvm: fix the name of llvm-size")
> > 3. commit 63b903dfebde ("net: wan: wanxl: use allow to pass
> > CROSS_COMPILE_M68k for rebuilding firmware")
> > 4. commit 734f3719d343 ("net: wan: wanxl: use $(M68KCC) instead of
> > $(M68KAS) for rebuilding firmware")
> > 5. commit eefb8c124fd9 ("x86/boot: kbuild: allow readelf executable to
> > be specified")
> > 6. commit 94f7345b7124 ("kbuild: remove PYTHON2 variable")
> > 7. commit aa824e0c962b ("kbuild: remove AS variable")
> > 8. commit 7e20e47c70f8 ("kbuild: replace AS=clang with LLVM_IAS=1")
> > 9. commit a0d1c951ef08 ("kbuild: support LLVM=1 to switch the default
> > tools to Clang/LLVM")
And FWIW, "yes please" from me as well. This makes things muuuch easier
to test LTS with Clang.
--
Kees Cook
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: LLVM=1 patches for 5.4
2020-08-20 20:14 LLVM=1 patches for 5.4 Nick Desaulniers
2020-08-20 20:27 ` Nick Desaulniers
@ 2020-08-24 8:10 ` Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2020-08-24 8:10 UTC (permalink / raw)
To: Nick Desaulniers
Cc: Sasha Levin, Masahiro Yamada, # 3.4.x, clang-built-linux,
Nathan Chancellor, Dmitry Golovin, Geert Uytterhoeven,
Fangrui Song, Sedat Dilek, Kees Cook
On Thu, Aug 20, 2020 at 01:14:36PM -0700, Nick Desaulniers wrote:
> Dear stable kernel maintainers,
> Please consider the attached mbox file, which contains 9 patches which
> cherry pick cleanly onto 5.4:
>
> 1. commit fcf1b6a35c16 ("Documentation/llvm: add documentation on
> building w/ Clang/LLVM")
> 2. commit 0f44fbc162b7 ("Documentation/llvm: fix the name of llvm-size")
> 3. commit 63b903dfebde ("net: wan: wanxl: use allow to pass
> CROSS_COMPILE_M68k for rebuilding firmware")
> 4. commit 734f3719d343 ("net: wan: wanxl: use $(M68KCC) instead of
> $(M68KAS) for rebuilding firmware")
> 5. commit eefb8c124fd9 ("x86/boot: kbuild: allow readelf executable to
> be specified")
> 6. commit 94f7345b7124 ("kbuild: remove PYTHON2 variable")
> 7. commit aa824e0c962b ("kbuild: remove AS variable")
> 8. commit 7e20e47c70f8 ("kbuild: replace AS=clang with LLVM_IAS=1")
> 9. commit a0d1c951ef08 ("kbuild: support LLVM=1 to switch the default
> tools to Clang/LLVM")
>
> This series improves/simplifies building kernels with Clang and LLVM
> utilities; it will help the various CI systems testing kernels built
> with Clang+LLVM utilities (in fact I will be pointing to this, if
> accepted, next week at plumbers with those CI system maintainers), and
> we will make immediate use of it in Android (see also:
> https://android-review.googlesource.com/c/platform/prebuilts/clang/host/linux-x86/+/1405387).
> We can always carry it out of tree in Android, but I think the series
> is fairly tame, and would prefer not to.
>
> I only particularly care about 5+8+9 (eefb8c124fd9, 7e20e47c70f8, and
> a0d1c951ef08), but the rest are required for them to cherry-pick
> cleanly. I don't mind separating those three out, though they won't
> be clean cherry-picks at that point. It might be good to have
> Masahiro review the series. If accepted, I plan to wire up test
> coverage of these immediately in
> https://github.com/ClangBuiltLinux/continuous-integration/issues/300.
>
> Most of the above landed in v5.7-rc1, with 94f7345b7124 landing in
> v5.6-rc1 and eefb8c124fd9 landing in v5.5-rc3.
All now queued up, thanks.
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-24 8:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-20 20:14 LLVM=1 patches for 5.4 Nick Desaulniers
2020-08-20 20:27 ` Nick Desaulniers
2020-08-20 20:44 ` Kees Cook
2020-08-24 8:10 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.