linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/3] infer --target from SRCARCH for CC=clang
@ 2021-08-02 18:39 Nick Desaulniers
  2021-08-02 18:39 ` [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Nick Desaulniers @ 2021-08-02 18:39 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 --target from SRCARCH, and move some flag handling into a
new file included from the top level Makefile.

Changes v5 -> v6:
* Use indirection as per Linus.
* Change hexagon triple to use -musl rather than -gnu. glibc doesn't
  have support for hexagon, and hexagon-linux-musl is the triple we use
  in CI.
  https://github.com/ClangBuiltLinux/continuous-integration2/blob/d659897d1700894d67feb64fe28e298da399a287/generator.yml#L53
* Pick up Fangrui's RB.
* Reorder use of Env vars in documentation to use command line
  parameters instead, for consistency.

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 | 19 ++++++++++++++++++-
 MAINTAINERS                   |  1 +
 Makefile                      | 15 +--------------
 scripts/Makefile.clang        | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 15 deletions(-)
 create mode 100644 scripts/Makefile.clang


base-commit: d7a86429dbc691bf540688fcc8542cc20246a85b
-- 
2.32.0.554.ge1b32706d8-goog


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

* [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang
  2021-08-02 18:39 [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
@ 2021-08-02 18:39 ` Nick Desaulniers
  2021-08-02 21:06   ` Fāng-ruì Sòng
  2021-08-02 18:39 ` [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: Nick Desaulniers @ 2021-08-02 18:39 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 19135a9d778e..3af8d39f43ef 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4501,6 +4501,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 6b555f64df06..444558e62cbc 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] 15+ messages in thread

* [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang
  2021-08-02 18:39 [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
  2021-08-02 18:39 ` [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
@ 2021-08-02 18:39 ` Nick Desaulniers
  2021-08-05 13:58   ` Masahiro Yamada
  2021-08-05 18:17   ` Miguel Ojeda
  2021-08-02 18:39 ` [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
  2021-08-10  0:05 ` [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Masahiro Yamada
  3 siblings, 2 replies; 15+ messages in thread
From: Nick Desaulniers @ 2021-08-02 18:39 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: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Suggested-by: Nathan Chancellor <nathan@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 v5 -> v6:
* Use indirection as per Linus. We now have CLANG_TARGET_FLAGS and a
  few variables suffixed with $SRCARCH.
* Add Linus' SB tag.
* Change hexagon target triple from -gnu to -musl.

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 | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
index 297932e973d4..1f4e3eb70f88 100644
--- a/scripts/Makefile.clang
+++ b/scripts/Makefile.clang
@@ -1,6 +1,27 @@
-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.
+CLANG_TARGET_FLAGS_arm		:= arm-linux-gnueabi
+CLANG_TARGET_FLAGS_arm64	:= aarch64-linux-gnu
+CLANG_TARGET_FLAGS_hexagon	:= hexagon-linux-musl
+CLANG_TARGET_FLAGS_m68k		:= m68k-linux-gnu
+CLANG_TARGET_FLAGS_mips		:= mipsel-linux-gnu
+CLANG_TARGET_FLAGS_powerpc	:= powerpc64le-linux-gnu
+CLANG_TARGET_FLAGS_riscv	:= riscv64-linux-gnu
+CLANG_TARGET_FLAGS_s390		:= s390x-linux-gnu
+CLANG_TARGET_FLAGS_x86		:= x86_64-linux-gnu
+CLANG_TARGET_FLAGS		:= $(CLANG_TARGET_FLAGS_$(SRCARCH))
+
+ifeq ($(CROSS_COMPILE),)
+ifeq ($(CLANG_TARGET_FLAGS),)
+$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang)
+else
+CLANG_FLAGS	+= --target=$(CLANG_TARGET_FLAGS)
+endif # CLANG_TARGET_FLAGS
+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] 15+ messages in thread

* [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-08-02 18:39 [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
  2021-08-02 18:39 ` [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
  2021-08-02 18:39 ` [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
@ 2021-08-02 18:39 ` Nick Desaulniers
  2021-08-02 19:16   ` Nathan Chancellor
  2021-08-05 13:57   ` Masahiro Yamada
  2021-08-10  0:05 ` [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Masahiro Yamada
  3 siblings, 2 replies; 15+ messages in thread
From: Nick Desaulniers @ 2021-08-02 18:39 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.

Change use of env vars to command line parameters.

Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Fangrui Song <maskray@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
Changes v5 -> v6:
* Pick up Fangrui's RB tag.
* Change use of env vars to command line parameters for consistency.

 Documentation/kbuild/llvm.rst | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
index b18401d2ba82..f8a360958f4c 100644
--- a/Documentation/kbuild/llvm.rst
+++ b/Documentation/kbuild/llvm.rst
@@ -38,7 +38,7 @@ 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
+	make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu-
 
 ``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
@@ -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 linker.
+
+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::
+
+	make ARCH=arm64 LLVM=1 LLVM_IAS=1
+
 Supported Architectures
 -----------------------
 
-- 
2.32.0.554.ge1b32706d8-goog


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

* Re: [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-08-02 18:39 ` [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
@ 2021-08-02 19:16   ` Nathan Chancellor
  2021-08-05 13:57   ` Masahiro Yamada
  1 sibling, 0 replies; 15+ messages in thread
From: Nathan Chancellor @ 2021-08-02 19:16 UTC (permalink / raw)
  To: Nick Desaulniers, Masahiro Yamada
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds

On 8/2/2021 11:39 AM, 'Nick Desaulniers' via Clang Built Linux 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.
> 
> Change use of env vars to command line parameters.
> 
> Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
> Reviewed-by: Fangrui Song <maskray@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Thanks for the update, I think this is much easier for non-CBL folks to 
understand.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
> Changes v5 -> v6:
> * Pick up Fangrui's RB tag.
> * Change use of env vars to command line parameters for consistency.
> 
>   Documentation/kbuild/llvm.rst | 19 ++++++++++++++++++-
>   1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
> index b18401d2ba82..f8a360958f4c 100644
> --- a/Documentation/kbuild/llvm.rst
> +++ b/Documentation/kbuild/llvm.rst
> @@ -38,7 +38,7 @@ 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
> +	make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu-
>   
>   ``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
> @@ -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 linker.
> +
> +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::
> +
> +	make ARCH=arm64 LLVM=1 LLVM_IAS=1
> +
>   Supported Architectures
>   -----------------------
>   
> 

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

* Re: [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang
  2021-08-02 18:39 ` [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
@ 2021-08-02 21:06   ` Fāng-ruì Sòng
  2021-08-02 21:14     ` Nick Desaulniers
  2021-08-05 12:55     ` Masahiro Yamada
  0 siblings, 2 replies; 15+ messages in thread
From: Fāng-ruì Sòng @ 2021-08-02 21:06 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,
	Nathan Chancellor

On Mon, Aug 2, 2021 at 11:39 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> 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 19135a9d778e..3af8d39f43ef 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -4501,6 +4501,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 6b555f64df06..444558e62cbc 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

-i* options are for includes. -fintegrated-as is the canonical spelling.
Since -fintegrated-as is the default (for most llvm/lib/Target/
targets and the ones clang builds actually support),
it can even be deleted.

> +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	[flat|nested] 15+ messages in thread

* Re: [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang
  2021-08-02 21:06   ` Fāng-ruì Sòng
@ 2021-08-02 21:14     ` Nick Desaulniers
  2021-08-05 12:55     ` Masahiro Yamada
  1 sibling, 0 replies; 15+ messages in thread
From: Nick Desaulniers @ 2021-08-02 21:14 UTC (permalink / raw)
  To: Fāng-ruì Sòng
  Cc: Masahiro Yamada, Miguel Ojeda, Michal Marek, Arnd Bergmann,
	linux-kernel, linux-kbuild, clang-built-linux,
	Geert Uytterhoeven, Christoph Hellwig, Linus Torvalds,
	Nathan Chancellor

On Mon, Aug 2, 2021 at 2:06 PM Fāng-ruì Sòng <maskray@google.com> wrote:
>
> On Mon, Aug 2, 2021 at 11:39 AM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> > 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
>
> -i* options are for includes. -fintegrated-as is the canonical spelling.
> Since -fintegrated-as is the default (for most llvm/lib/Target/
> targets and the ones clang builds actually support),
> it can even be deleted.

It was made explicit by Masahiro in
git.kernel.org/linus/ba64beb17493a4bfec563100c86a462a15926f24
So I don't think we need to go back to the implicit default.

It's definitely nicer to use groupings rather than these raw prefixed
flags IMO.  If you sent a patch for that I would approve of it.
Otherwise we don't really need to change this as this is how it's
worked in LLVM for as long as we've been able to build the kernel with
LLVM.
-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang
  2021-08-02 21:06   ` Fāng-ruì Sòng
  2021-08-02 21:14     ` Nick Desaulniers
@ 2021-08-05 12:55     ` Masahiro Yamada
  1 sibling, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2021-08-05 12:55 UTC (permalink / raw)
  To: Fāng-ruì Sòng
  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, Nathan Chancellor

On Tue, Aug 3, 2021 at 6:06 AM 'Fāng-ruì Sòng' via Clang Built Linux
<clang-built-linux@googlegroups.com> wrote:
>
> On Mon, Aug 2, 2021 at 11:39 AM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > 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 19135a9d778e..3af8d39f43ef 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -4501,6 +4501,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 6b555f64df06..444558e62cbc 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
>
> -i* options are for includes. -fintegrated-as is the canonical spelling.


If -fintegrated-as is preferred to -integrated-as,
please send a patch.
(on top of this series)


Thanks.






> Since -fintegrated-as is the default (for most llvm/lib/Target/
> targets and the ones clang builds actually support),
> it can even be deleted.
>
> > +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
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAFP8O3Jc%3DiwzAQojgBZZzdT8iVBY9TO6GLTq%2B0vkXoo6L5JJ-A%40mail.gmail.com.



-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-08-02 18:39 ` [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
  2021-08-02 19:16   ` Nathan Chancellor
@ 2021-08-05 13:57   ` Masahiro Yamada
  2021-08-05 18:27     ` Nick Desaulniers
  1 sibling, 1 reply; 15+ messages in thread
From: Masahiro Yamada @ 2021-08-05 13:57 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	Linux Kernel Mailing List, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds

On Tue, Aug 3, 2021 at 3:39 AM 'Nick Desaulniers' via Clang Built
Linux <clang-built-linux@googlegroups.com> 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.
>
> Change use of env vars to command line parameters.
>
> Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
> Reviewed-by: Fangrui Song <maskray@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> Changes v5 -> v6:
> * Pick up Fangrui's RB tag.
> * Change use of env vars to command line parameters for consistency.
>
>  Documentation/kbuild/llvm.rst | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
> index b18401d2ba82..f8a360958f4c 100644
> --- a/Documentation/kbuild/llvm.rst
> +++ b/Documentation/kbuild/llvm.rst
> @@ -38,7 +38,7 @@ 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
> +       make ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu-
>
>  ``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
> @@ -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 linker.


Is there any place where we rely on --prefix
to search for the linker?

In general, the compiler stops after generating an object
since it is passed with the -c option.
The linking stage is separated.

In the old days, VDSO was an exceptional case
where $(CC) was used as the linker driver, but
commit fe00e50b2db8c60e4ec90befad1f5bab8ca2c800 fixed it.







> +
> +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::
> +
> +       make ARCH=arm64 LLVM=1 LLVM_IAS=1
> +
>  Supported Architectures
>  -----------------------
>
> --
> 2.32.0.554.ge1b32706d8-goog
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210802183910.1802120-4-ndesaulniers%40google.com.



-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang
  2021-08-02 18:39 ` [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
@ 2021-08-05 13:58   ` Masahiro Yamada
  2021-08-05 18:17   ` Miguel Ojeda
  1 sibling, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2021-08-05 13:58 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	Linux Kernel Mailing List, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds, Nathan Chancellor

On Tue, Aug 3, 2021 at 3:39 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> 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: Linus Torvalds <torvalds@linux-foundation.org>
> Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
> Suggested-by: Nathan Chancellor <nathan@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 v5 -> v6:
> * Use indirection as per Linus. We now have CLANG_TARGET_FLAGS and a
>   few variables suffixed with $SRCARCH.
> * Add Linus' SB tag.
> * Change hexagon target triple from -gnu to -musl.
>
> 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 | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> index 297932e973d4..1f4e3eb70f88 100644
> --- a/scripts/Makefile.clang
> +++ b/scripts/Makefile.clang
> @@ -1,6 +1,27 @@
> -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.
> +CLANG_TARGET_FLAGS_arm         := arm-linux-gnueabi
> +CLANG_TARGET_FLAGS_arm64       := aarch64-linux-gnu
> +CLANG_TARGET_FLAGS_hexagon     := hexagon-linux-musl
> +CLANG_TARGET_FLAGS_m68k                := m68k-linux-gnu
> +CLANG_TARGET_FLAGS_mips                := mipsel-linux-gnu
> +CLANG_TARGET_FLAGS_powerpc     := powerpc64le-linux-gnu
> +CLANG_TARGET_FLAGS_riscv       := riscv64-linux-gnu
> +CLANG_TARGET_FLAGS_s390                := s390x-linux-gnu
> +CLANG_TARGET_FLAGS_x86         := x86_64-linux-gnu
> +CLANG_TARGET_FLAGS             := $(CLANG_TARGET_FLAGS_$(SRCARCH))
> +
> +ifeq ($(CROSS_COMPILE),)
> +ifeq ($(CLANG_TARGET_FLAGS),)
> +$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang)


When I was browsing the code, I noticed a nit.

I believe non-build targets such as
'make help', 'make clean' etc. should succeed
without any correct CROSS_COMPILE set
since they do not use the compiler at all.


The remaining architectures may fail to clean.

$ export LLVM=1
$ make ARCH=csky  clean
scripts/Makefile.clang:17: *** Specify CROSS_COMPILE or add
'--target=' option to scripts/Makefile.clang.  Stop.



I decided to not be worried about it because it
is fixable later.
I will pick it up unless a significant issue is found.





> +else
> +CLANG_FLAGS    += --target=$(CLANG_TARGET_FLAGS)
> +endif # CLANG_TARGET_FLAGS
> +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
>


--
Best Regards


Masahiro Yamada

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

* Re: [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang
  2021-08-02 18:39 ` [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
  2021-08-05 13:58   ` Masahiro Yamada
@ 2021-08-05 18:17   ` Miguel Ojeda
  1 sibling, 0 replies; 15+ messages in thread
From: Miguel Ojeda @ 2021-08-05 18:17 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Masahiro Yamada, Miguel Ojeda, Fangrui Song, Michal Marek,
	Arnd Bergmann, linux-kernel, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds, Nathan Chancellor

On Mon, Aug 2, 2021 at 8:39 PM 'Nick Desaulniers' via Clang Built
Linux <clang-built-linux@googlegroups.com> wrote:
>
> 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: Linus Torvalds <torvalds@linux-foundation.org>
> Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Acked-by: Arnd Bergmann <arnd@kernel.org>
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Acked-by: Miguel Ojeda <ojeda@kernel.org>

Cheers,
Miguel

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

* Re: [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-08-05 13:57   ` Masahiro Yamada
@ 2021-08-05 18:27     ` Nick Desaulniers
  2021-08-05 18:29       ` Nick Desaulniers
  0 siblings, 1 reply; 15+ messages in thread
From: Nick Desaulniers @ 2021-08-05 18:27 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	Linux Kernel Mailing List, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds

On Thu, Aug 5, 2021 at 6:58 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Tue, Aug 3, 2021 at 3:39 AM 'Nick Desaulniers' via Clang Built
> Linux <clang-built-linux@googlegroups.com> wrote:
> > diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
> > index b18401d2ba82..f8a360958f4c 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 linker.
>
>
> Is there any place where we rely on --prefix
> to search for the linker?
>
> In general, the compiler stops after generating an object
> since it is passed with the -c option.
> The linking stage is separated.
>
> In the old days, VDSO was an exceptional case
> where $(CC) was used as the linker driver, but
> commit fe00e50b2db8c60e4ec90befad1f5bab8ca2c800 fixed it.

See my previous reply to Fangrui.
https://lore.kernel.org/lkml/CAKwvOdnK=SUm1_--tcLRO3LVeXd_2Srfv2tsZCUW0uXXa1W_pg@mail.gmail.com/

To be more specific, I believe this is still a problem for ppc vdso.
https://github.com/ClangBuiltLinux/linux/issues/774

I had sent patches for that, but binutils 2.26 would crash (IIUC,
newer GNU binutils are ok).  See this thread:
https://lore.kernel.org/lkml/b2066ccd-2b81-6032-08e3-41105b400f75@csgroup.eu/

So "we'd prefer the linker was used as the driver, but there's at
least one place I know of in the tree where that's not currently the
case."
-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing
  2021-08-05 18:27     ` Nick Desaulniers
@ 2021-08-05 18:29       ` Nick Desaulniers
  2021-08-05 23:26         ` Masahiro Yamada
  0 siblings, 1 reply; 15+ messages in thread
From: Nick Desaulniers @ 2021-08-05 18:29 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	Linux Kernel Mailing List, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds

On Thu, Aug 5, 2021 at 11:27 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Thu, Aug 5, 2021 at 6:58 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Tue, Aug 3, 2021 at 3:39 AM 'Nick Desaulniers' via Clang Built
> > Linux <clang-built-linux@googlegroups.com> wrote:
> > > diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
> > > index b18401d2ba82..f8a360958f4c 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 linker.
> >
> >
> > Is there any place where we rely on --prefix
> > to search for the linker?
> >
> > In general, the compiler stops after generating an object
> > since it is passed with the -c option.
> > The linking stage is separated.
> >
> > In the old days, VDSO was an exceptional case
> > where $(CC) was used as the linker driver, but
> > commit fe00e50b2db8c60e4ec90befad1f5bab8ca2c800 fixed it.
>
> See my previous reply to Fangrui.
> https://lore.kernel.org/lkml/CAKwvOdnK=SUm1_--tcLRO3LVeXd_2Srfv2tsZCUW0uXXa1W_pg@mail.gmail.com/
>
> To be more specific, I believe this is still a problem for ppc vdso.
> https://github.com/ClangBuiltLinux/linux/issues/774
>
> I had sent patches for that, but binutils 2.26 would crash (IIUC,
> newer GNU binutils are ok).  See this thread:
> https://lore.kernel.org/lkml/b2066ccd-2b81-6032-08e3-41105b400f75@csgroup.eu/
>
> So "we'd prefer the linker was used as the driver, but there's at
> least one place I know of in the tree where that's not currently the
> case."

Also, I think the CC_CAN_LINK functionality also fits the bill.
https://github.com/ClangBuiltLinux/linux/issues/1290
-- 
Thanks,
~Nick Desaulniers

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

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

On Fri, Aug 6, 2021 at 3:29 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Thu, Aug 5, 2021 at 11:27 AM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > On Thu, Aug 5, 2021 at 6:58 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > On Tue, Aug 3, 2021 at 3:39 AM 'Nick Desaulniers' via Clang Built
> > > Linux <clang-built-linux@googlegroups.com> wrote:
> > > > diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst
> > > > index b18401d2ba82..f8a360958f4c 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 linker.
> > >
> > >
> > > Is there any place where we rely on --prefix
> > > to search for the linker?
> > >
> > > In general, the compiler stops after generating an object
> > > since it is passed with the -c option.
> > > The linking stage is separated.
> > >
> > > In the old days, VDSO was an exceptional case
> > > where $(CC) was used as the linker driver, but
> > > commit fe00e50b2db8c60e4ec90befad1f5bab8ca2c800 fixed it.
> >
> > See my previous reply to Fangrui.
> > https://lore.kernel.org/lkml/CAKwvOdnK=SUm1_--tcLRO3LVeXd_2Srfv2tsZCUW0uXXa1W_pg@mail.gmail.com/
> >
> > To be more specific, I believe this is still a problem for ppc vdso.
> > https://github.com/ClangBuiltLinux/linux/issues/774
> >
> > I had sent patches for that, but binutils 2.26 would crash (IIUC,
> > newer GNU binutils are ok).  See this thread:
> > https://lore.kernel.org/lkml/b2066ccd-2b81-6032-08e3-41105b400f75@csgroup.eu/
> >
> > So "we'd prefer the linker was used as the driver, but there's at
> > least one place I know of in the tree where that's not currently the
> > case."
>
> Also, I think the CC_CAN_LINK functionality also fits the bill.
> https://github.com/ClangBuiltLinux/linux/issues/1290
> --
> Thanks,
> ~Nick Desaulniers


Ah, this is it.

Thanks.


-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v6 0/3] infer --target from SRCARCH for CC=clang
  2021-08-02 18:39 [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
                   ` (2 preceding siblings ...)
  2021-08-02 18:39 ` [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
@ 2021-08-10  0:05 ` Masahiro Yamada
  3 siblings, 0 replies; 15+ messages in thread
From: Masahiro Yamada @ 2021-08-10  0:05 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Miguel Ojeda, Fangrui Song, Michal Marek, Arnd Bergmann,
	Linux Kernel Mailing List, Linux Kbuild mailing list,
	clang-built-linux, Geert Uytterhoeven, Christoph Hellwig,
	Linus Torvalds

On Tue, Aug 3, 2021 at 3:39 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> 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 --target from SRCARCH, and move some flag handling into a
> new file included from the top level Makefile.


Series, applied to linux-kbuild.
Thanks.



> Changes v5 -> v6:
> * Use indirection as per Linus.
> * Change hexagon triple to use -musl rather than -gnu. glibc doesn't
>   have support for hexagon, and hexagon-linux-musl is the triple we use
>   in CI.
>   https://github.com/ClangBuiltLinux/continuous-integration2/blob/d659897d1700894d67feb64fe28e298da399a287/generator.yml#L53
> * Pick up Fangrui's RB.
> * Reorder use of Env vars in documentation to use command line
>   parameters instead, for consistency.
>
> 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 | 19 ++++++++++++++++++-
>  MAINTAINERS                   |  1 +
>  Makefile                      | 15 +--------------
>  scripts/Makefile.clang        | 35 +++++++++++++++++++++++++++++++++++
>  4 files changed, 55 insertions(+), 15 deletions(-)
>  create mode 100644 scripts/Makefile.clang
>
>
> base-commit: d7a86429dbc691bf540688fcc8542cc20246a85b
> --
> 2.32.0.554.ge1b32706d8-goog
>


-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2021-08-10  0:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 18:39 [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Nick Desaulniers
2021-08-02 18:39 ` [PATCH v6 1/3] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
2021-08-02 21:06   ` Fāng-ruì Sòng
2021-08-02 21:14     ` Nick Desaulniers
2021-08-05 12:55     ` Masahiro Yamada
2021-08-02 18:39 ` [PATCH v6 2/3] Makefile: infer --target from ARCH for CC=clang Nick Desaulniers
2021-08-05 13:58   ` Masahiro Yamada
2021-08-05 18:17   ` Miguel Ojeda
2021-08-02 18:39 ` [PATCH v6 3/3] Documentation/llvm: update CROSS_COMPILE inferencing Nick Desaulniers
2021-08-02 19:16   ` Nathan Chancellor
2021-08-05 13:57   ` Masahiro Yamada
2021-08-05 18:27     ` Nick Desaulniers
2021-08-05 18:29       ` Nick Desaulniers
2021-08-05 23:26         ` Masahiro Yamada
2021-08-10  0:05 ` [PATCH v6 0/3] infer --target from SRCARCH for CC=clang Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).