All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/3] infer --target from SRCARCH for CC=clang
@ 2021-07-30 21:57 Nick Desaulniers
  2021-07-30 21:57 ` [PATCH v5 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Nick Desaulniers @ 2021-07-30 21:57 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds,
	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.

Instead, let's infer it from SRCARCH, and move some flag handling into a
new file included from the top level Makefile.

Changes v4 -> v5:
* Include previously missing first patch!

Changes v3 -> v4:
* Remove the requirement that LLVM_IAS=1 be set, as per Masahiro.
* Remove the Documentation/ change from patch 2, as per Masahiro and
  Nathan.
* Add Documentation/ change as patch 3, from Masahiro.
* Reword commit message of patch 2, as per Nathan.
* Change patch 2 oneline to refer to --target and CC=clang (not
  CROSS_COMPILE).
* Carry Arnd's and Nathan's AB/RB/TB tags, confirmed ok on IRC+discord.

Changes v2 -> v3:
* Remove requirement that LLVM=1 be set. Instead, if building with just
  CC=clang LLVM_IAS=1 instead of LLVM=1 LLVM_IAS=1, you should use
  LD=ld.lld explicitly, or LD=aarch64-linux-gnu-ld. (As per Masahiro)
  Example:

  $ ARCH=arm64 make CC=clang LLVM_IAS=1 LD=ld.lld OBJCOPY=llvm-objcopy \
    STRIP=llvm-strip -j72 defconfig all

  (It's still preferable to use LLVM=1 IMO, but this is maximally
  flexible.)
* Change oneliner from LLVM=1 to CC=clang.
* Update Docs slightly.

Changes v1 -> v2:
* patch 1/2 untouched.
* Fix typos in commit message as per Geert and Masahiro.
* Use SRCARCH instead of ARCH, simplifying x86 handling, as per
  Masahiro. Add his sugguested by tag.
* change commit oneline from 'drop' to 'infer.'
* Add detail about explicit host --target and relationship of ARCH to
  SRCARCH, as per Masahiro.

Nick Desaulniers (3):
  Makefile: move initial clang flag handling into scripts/Makefile.clang
  Makefile: infer --target from ARCH for CC=clang
  Documentation/llvm: update CROSS_COMPILE inferencing

 Documentation/kbuild/llvm.rst | 17 +++++++++++++++
 MAINTAINERS                   |  1 +
 Makefile                      | 15 +------------
 scripts/Makefile.clang        | 40 +++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 14 deletions(-)
 create mode 100644 scripts/Makefile.clang


base-commit: 27932b6a2088eac7a5afa5471963b926cfbb4de7
-- 
2.32.0.554.ge1b32706d8-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v5 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang
  2021-07-30 21:57 [PATCH v5 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
@ 2021-07-30 21:57 ` Nick Desaulniers
  2021-07-30 21:57 ` [PATCH v5 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
  2021-07-30 21:57 ` [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
  2 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2021-07-30 21:57 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds,
	Nick Desaulniers, Nathan Chancellor

With some of the changes we'd like to make to CROSS_COMPILE, the initial
block of clang flag handling which controls things like the target triple,
whether or not to use the integrated assembler and how to find GAS,
and erroring on unknown warnings is becoming unwieldy. Move it into its
own file under scripts/.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 MAINTAINERS            |  1 +
 Makefile               | 15 +--------------
 scripts/Makefile.clang | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 14 deletions(-)
 create mode 100644 scripts/Makefile.clang

diff --git a/MAINTAINERS b/MAINTAINERS
index 81e1edeceae4..9c1205c258c7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4433,6 +4433,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.clang
 F:	scripts/clang-tools/
 K:	\b(?i:clang|llvm)\b
 
diff --git a/Makefile b/Makefile
index cbab0dc53065..010e3a4e770b 100644
--- a/Makefile
+++ b/Makefile
@@ -586,20 +586,7 @@ endif
 CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -n 1))
 
 ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
-ifneq ($(CROSS_COMPILE),)
-CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
-endif
-ifeq ($(LLVM_IAS),1)
-CLANG_FLAGS	+= -integrated-as
-else
-CLANG_FLAGS	+= -no-integrated-as
-GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
-CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-endif
-CLANG_FLAGS	+= -Werror=unknown-warning-option
-KBUILD_CFLAGS	+= $(CLANG_FLAGS)
-KBUILD_AFLAGS	+= $(CLANG_FLAGS)
-export CLANG_FLAGS
+include $(srctree)/scripts/Makefile.clang
 endif
 
 # Include this also for config targets because some architectures need
diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
new file mode 100644
index 000000000000..297932e973d4
--- /dev/null
+++ b/scripts/Makefile.clang
@@ -0,0 +1,14 @@
+ifneq ($(CROSS_COMPILE),)
+CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
+endif
+ifeq ($(LLVM_IAS),1)
+CLANG_FLAGS	+= -integrated-as
+else
+CLANG_FLAGS	+= -no-integrated-as
+GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
+CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
+endif
+CLANG_FLAGS	+= -Werror=unknown-warning-option
+KBUILD_CFLAGS	+= $(CLANG_FLAGS)
+KBUILD_AFLAGS	+= $(CLANG_FLAGS)
+export CLANG_FLAGS
-- 
2.32.0.554.ge1b32706d8-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v5 2/3] Makefile: infer --target from ARCH for CC=clang
  2021-07-30 21:57 [PATCH v5 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
  2021-07-30 21:57 ` [PATCH v5 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
@ 2021-07-30 21:57 ` Nick Desaulniers
  2021-07-30 21:57 ` [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
  2 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2021-07-30 21:57 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds,
	Nick Desaulniers, Nathan Chancellor

We get constant feedback that the command line invocation of make is too
long when compiling with LLVM. CROSS_COMPILE is helpful when a toolchain
has a prefix of the target triple, or is an absolute path outside of
$PATH.

Since a Clang binary is generally multi-targeted, we can infer a given
target from SRCARCH/ARCH.  If CROSS_COMPILE is not set, simply set
--target= for CLANG_FLAGS, KBUILD_CFLAGS, and KBUILD_AFLAGS based on
$SRCARCH.

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

For native builds (not involving cross compilation) we now explicitly
specify a target triple rather than rely on the implicit host triple.

Link: https://github.com/ClangBuiltLinux/linux/issues/1399
Suggested-by: Arnd Bergmann <arnd@kernel.org>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Arnd Bergmann <arnd@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Changes v3 -> v4:
* Reword commit message and oneline, as per Nathan.
* Drop documentation change (it's the next patch, could be squashed in,
  I guess).
* Drop LLVM_IAS=1 requirement, as per Masahiro.
* Carry Arnd's and Nathan's AB/RB/TB tags, confirmed OK on IRC+Discord.

Changes v2 -> v3:
* Drop check/requirement for LLVM=1, as per Masahiro.
* Change oneliner from LLVM=1 LLVM_IAS=1 to CC=clang LLVM_IAS=1.
* Don't carry forward Nathan's RB/TB tags. :( Sorry Nathan, but thank
  you for testing+reviewing v2.
* Update wording of docs slightly.

Changes v1 -> v2:
* Fix typos in commit message as per Geert and Masahiro.
* Use SRCARCH instead of ARCH, simplifying x86 handling, as per
  Masahiro. Add his sugguested by tag.
* change commit oneline from 'drop' to 'infer.'
* Add detail about explicit host --target and relationship of ARCH to
  SRCARCH, as per Masahiro.

Changes RFC -> v1:
* Rebase onto linux-kbuild/for-next
* Keep full target triples since missing the gnueabi suffix messes up
  32b ARM. Drop Fangrui's sugguested by tag. Update commit message to
  drop references to arm64.
* Flush out TODOS.
* Add note about -EL/-EB, -m32/-m64.
* Add note to Documentation/.

 scripts/Makefile.clang | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
index 297932e973d4..f983f65dd9f5 100644
--- a/scripts/Makefile.clang
+++ b/scripts/Makefile.clang
@@ -1,6 +1,32 @@
-ifneq ($(CROSS_COMPILE),)
+# Individual arch/{arch}/Makefiles should use -EL/-EB to set intended
+# endianness and -m32/-m64 to set word size based on Kconfigs instead of
+# relying on the target triple.
+ifeq ($(CROSS_COMPILE),)
+ifeq ($(SRCARCH),arm)
+CLANG_FLAGS	+= --target=arm-linux-gnueabi
+else ifeq ($(SRCARCH),arm64)
+CLANG_FLAGS	+= --target=aarch64-linux-gnu
+else ifeq ($(SRCARCH),hexagon)
+CLANG_FLAGS	+= --target=hexagon-linux-gnu
+else ifeq ($(SRCARCH),m68k)
+CLANG_FLAGS	+= --target=m68k-linux-gnu
+else ifeq ($(SRCARCH),mips)
+CLANG_FLAGS	+= --target=mipsel-linux-gnu
+else ifeq ($(SRCARCH),powerpc)
+CLANG_FLAGS	+= --target=powerpc64le-linux-gnu
+else ifeq ($(SRCARCH),riscv)
+CLANG_FLAGS	+= --target=riscv64-linux-gnu
+else ifeq ($(SRCARCH),s390)
+CLANG_FLAGS	+= --target=s390x-linux-gnu
+else ifeq ($(SRCARCH),x86)
+CLANG_FLAGS	+= --target=x86_64-linux-gnu
+else
+$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang)
+endif # SRCARCH
+else
 CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
-endif
+endif # CROSS_COMPILE
+
 ifeq ($(LLVM_IAS),1)
 CLANG_FLAGS	+= -integrated-as
 else
-- 
2.32.0.554.ge1b32706d8-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-07-30 21:57 [PATCH v5 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
  2021-07-30 21:57 ` [PATCH v5 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
  2021-07-30 21:57 ` [PATCH v5 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
@ 2021-07-30 21:57 ` Nick Desaulniers
  2021-07-30 23:12   ` Fangrui Song
  2 siblings, 1 reply; 8+ messages in thread
From: Nick Desaulniers @ 2021-07-30 21:57 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds,
	Nick Desaulniers

As noted by Masahiro, document how we can generally infer CROSS_COMPILE
(and the more specific details about --target and --prefix) based on
ARCH.

Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 Documentation/kbuild/llvm.rst | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
index b18401d2ba82..4292f0686316 100644
--- a/Documentation/kbuild/llvm.rst
+++ b/Documentation/kbuild/llvm.rst
@@ -63,6 +63,23 @@ They can be enabled individually. The full list of the parameters: ::
 Currently, the integrated assembler is disabled by default. You can pass
 ``LLVM_IAS=1`` to enable it.
 
+Omitting CROSS_COMPILE
+----------------------
+
+As explained above, ``CROSS_COMPILE`` is used to set ``--target=<triple>``.
+
+Unless ``LLVM_IAS=1`` is specified, ``CROSS_COMPILE`` is also used to derive
+``--prefix=<path>`` to search for the GNU assembler.
+
+If ``CROSS_COMPILE`` is not specified, the ``--target=<triple>`` is inferred
+from ``ARCH``.
+
+That means if you use only LLVM tools, ``CROSS_COMPILE`` becomes unnecessary.
+
+For example, to cross-compile the arm64 kernel::
+
+	ARCH=arm64 make LLVM=1 LLVM_IAS=1
+
 Supported Architectures
 -----------------------
 
-- 
2.32.0.554.ge1b32706d8-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-07-30 21:57 ` [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
@ 2021-07-30 23:12   ` Fangrui Song
  2021-07-31  0:04     ` Masahiro Yamada
  2021-08-02 17:57     ` Nick Desaulniers
  0 siblings, 2 replies; 8+ messages in thread
From: Fangrui Song @ 2021-07-30 23:12 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Masahiro Yamada, Miguel Ojeda, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds

On 2021-07-30, Nick Desaulniers wrote:
>As noted by Masahiro, document how we can generally infer CROSS_COMPILE
>(and the more specific details about --target and --prefix) based on
>ARCH.
>
>Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
>Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
>---
> Documentation/kbuild/llvm.rst | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
>diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
>index b18401d2ba82..4292f0686316 100644
>--- a/Documentation/kbuild/llvm.rst
>+++ b/Documentation/kbuild/llvm.rst
>@@ -63,6 +63,23 @@ They can be enabled individually. The full list of the parameters: ::
> Currently, the integrated assembler is disabled by default. You can pass
> ``LLVM_IAS=1`` to enable it.
>
>+Omitting CROSS_COMPILE
>+----------------------
>+
>+As explained above, ``CROSS_COMPILE`` is used to set ``--target=<triple>``.
>+
>+Unless ``LLVM_IAS=1`` is specified, ``CROSS_COMPILE`` is also used to derive
>+``--prefix=<path>`` to search for the GNU assembler.

and the GNU linker.

Reviewed-by: Fangrui Song <maskray@google.com>

>+If ``CROSS_COMPILE`` is not specified, the ``--target=<triple>`` is inferred
>+from ``ARCH``.
>+
>+That means if you use only LLVM tools, ``CROSS_COMPILE`` becomes unnecessary.
>+
>+For example, to cross-compile the arm64 kernel::
>+
>+	ARCH=arm64 make LLVM=1 LLVM_IAS=1

Is  ARCH=arm64 make LLVM=1 LLVM_IAS=1

preferred over

   make ARCH=arm64 LLVM=1 LLVM_IAS=1

?

> Supported Architectures
> -----------------------
>
>-- 
>2.32.0.554.ge1b32706d8-goog
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-07-30 23:12   ` Fangrui Song
@ 2021-07-31  0:04     ` Masahiro Yamada
  2021-08-02 18:30       ` Nick Desaulniers
  2021-08-02 17:57     ` Nick Desaulniers
  1 sibling, 1 reply; 8+ messages in thread
From: Masahiro Yamada @ 2021-07-31  0:04 UTC (permalink / raw)
  To: Fangrui Song
  Cc: Nick Desaulniers, Miguel Ojeda, Michal Marek, Arnd Bergmann,
	Linux Kernel Mailing List, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds

On Sat, Jul 31, 2021 at 8:12 AM Fangrui Song <maskray@google.com> wrote:
>
> On 2021-07-30, Nick Desaulniers wrote:
> >As noted by Masahiro, document how we can generally infer CROSS_COMPILE
> >(and the more specific details about --target and --prefix) based on
> >ARCH.
> >
> >Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
> >Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> >---
> > Documentation/kbuild/llvm.rst | 17 +++++++++++++++++
> > 1 file changed, 17 insertions(+)
> >
> >diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
> >index b18401d2ba82..4292f0686316 100644
> >--- a/Documentation/kbuild/llvm.rst
> >+++ b/Documentation/kbuild/llvm.rst
> >@@ -63,6 +63,23 @@ They can be enabled individually. The full list of the parameters: ::
> > Currently, the integrated assembler is disabled by default. You can pass
> > ``LLVM_IAS=1`` to enable it.
> >
> >+Omitting CROSS_COMPILE
> >+----------------------
> >+
> >+As explained above, ``CROSS_COMPILE`` is used to set ``--target=<triple>``.
> >+
> >+Unless ``LLVM_IAS=1`` is specified, ``CROSS_COMPILE`` is also used to derive
> >+``--prefix=<path>`` to search for the GNU assembler.
>
> and the GNU linker.
>
> Reviewed-by: Fangrui Song <maskray@google.com>
>
> >+If ``CROSS_COMPILE`` is not specified, the ``--target=<triple>`` is inferred
> >+from ``ARCH``.
> >+
> >+That means if you use only LLVM tools, ``CROSS_COMPILE`` becomes unnecessary.
> >+
> >+For example, to cross-compile the arm64 kernel::
> >+
> >+      ARCH=arm64 make LLVM=1 LLVM_IAS=1
>
> Is  ARCH=arm64 make LLVM=1 LLVM_IAS=1
>
> preferred over
>
>    make ARCH=arm64 LLVM=1 LLVM_IAS=1
>
> ?


I do not think so.

For consistency,

   make ARCH=arm64 LLVM=1 LLVM_IAS=1

or

   ARCH=arm64 LLVM=1 LLVM_IAS=1 make

might be preferred.



But, in the same doc, I see an example, which
mixes up the env variables and a make variable.

     ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make CC=clang




-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-07-30 23:12   ` Fangrui Song
  2021-07-31  0:04     ` Masahiro Yamada
@ 2021-08-02 17:57     ` Nick Desaulniers
  1 sibling, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2021-08-02 17:57 UTC (permalink / raw)
  To: Fangrui Song
  Cc: Masahiro Yamada, Miguel Ojeda, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds

On Fri, Jul 30, 2021 at 4:12 PM 'Fangrui Song' via Clang Built Linux
<clang-built-linux@googlegroups.com> wrote:
>
> On 2021-07-30, Nick Desaulniers wrote:
> >As noted by Masahiro, document how we can generally infer CROSS_COMPILE
> >(and the more specific details about --target and --prefix) based on
> >ARCH.
> >
> >Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
> >Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> >---
> > Documentation/kbuild/llvm.rst | 17 +++++++++++++++++
> > 1 file changed, 17 insertions(+)
> >
> >diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
> >index b18401d2ba82..4292f0686316 100644
> >--- a/Documentation/kbuild/llvm.rst
> >+++ b/Documentation/kbuild/llvm.rst
> >@@ -63,6 +63,23 @@ They can be enabled individually. The full list of the parameters: ::
> > Currently, the integrated assembler is disabled by default. You can pass
> > ``LLVM_IAS=1`` to enable it.
> >
> >+Omitting CROSS_COMPILE
> >+----------------------
> >+
> >+As explained above, ``CROSS_COMPILE`` is used to set ``--target=<triple>``.
> >+
> >+Unless ``LLVM_IAS=1`` is specified, ``CROSS_COMPILE`` is also used to derive
> >+``--prefix=<path>`` to search for the GNU assembler.
>
> and the GNU linker.

Sure, I'll add this, but wanted to note that generally the compiler is
not used as the driver for kernel builds; the linker is invoked
directly. IIRC, there were a few spots where the compiler is used as
the driver; I think some of the various VDSO's are still built that
way, but it's not common.

>
> Reviewed-by: Fangrui Song <maskray@google.com>
>
> >+If ``CROSS_COMPILE`` is not specified, the ``--target=<triple>`` is inferred
> >+from ``ARCH``.
> >+
> >+That means if you use only LLVM tools, ``CROSS_COMPILE`` becomes unnecessary.
> >+
> >+For example, to cross-compile the arm64 kernel::
> >+
> >+      ARCH=arm64 make LLVM=1 LLVM_IAS=1
>
> Is  ARCH=arm64 make LLVM=1 LLVM_IAS=1
>
> preferred over
>
>    make ARCH=arm64 LLVM=1 LLVM_IAS=1
>
> ?

Will respond to this against Masahiro's reply.

-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-07-31  0:04     ` Masahiro Yamada
@ 2021-08-02 18:30       ` Nick Desaulniers
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2021-08-02 18:30 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Fangrui Song, Miguel Ojeda, Michal Marek, Arnd Bergmann,
	Linux Kernel Mailing List, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds

On Fri, Jul 30, 2021 at 5:05 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Sat, Jul 31, 2021 at 8:12 AM Fangrui Song <maskray@google.com> wrote:
> >
> > On 2021-07-30, Nick Desaulniers wrote:
> > >+For example, to cross-compile the arm64 kernel::
> > >+
> > >+      ARCH=arm64 make LLVM=1 LLVM_IAS=1
> >
> > Is  ARCH=arm64 make LLVM=1 LLVM_IAS=1
> >
> > preferred over
> >
> >    make ARCH=arm64 LLVM=1 LLVM_IAS=1
> >
> > ?
>
>
> I do not think so.
>
> For consistency,
>
>    make ARCH=arm64 LLVM=1 LLVM_IAS=1
>
> or
>
>    ARCH=arm64 LLVM=1 LLVM_IAS=1 make
>
> might be preferred.
>
>
>
> But, in the same doc, I see an example, which
> mixes up the env variables and a make variable.
>
>      ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make CC=clang

Perhaps it's just muscle memory from when I started working on Nexus
phone kernels ~5 years ago; that's how our build scripts invoked make
(with ARCH and CROSS_COMPILE as env vars).

IIRC, GNU make has the notion of `origin` for variables.
https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
So "before `make`" would be "environment" and "after `make`" would be
"command line."

I'm rereading the section on assignment to see if one of the
assignment operators was affected by origin.
https://www.gnu.org/software/make/manual/html_node/Setting.html
https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors

I could have sworn that due to one of the assignment operators
(perhaps `?=`) that the orderings weren't commutative.
$ make ARCH=arm64 LLVM=1 LLVM_IAS=1 -j72
works
$ ARCH=arm64 LLVM=1 LLVM_IAS=1 make -j72
also works.  Hmm...maybe I misremembered the issue then.

Ok, I will reorder all instances to use the command line rather than
env vars in v6.
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-02 18:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 21:57 [PATCH v5 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
2021-07-30 21:57 ` [PATCH v5 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
2021-07-30 21:57 ` [PATCH v5 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
2021-07-30 21:57 ` [PATCH v5 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
2021-07-30 23:12   ` Fangrui Song
2021-07-31  0:04     ` Masahiro Yamada
2021-08-02 18:30       ` Nick Desaulniers
2021-08-02 17:57     ` Nick Desaulniers

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.