All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/Makefile.clang: set --target for host based on make -v
@ 2022-06-17 20:39 Nick Desaulniers
  2022-06-17 23:20 ` Nathan Chancellor
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Desaulniers @ 2022-06-17 20:39 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Nick Desaulniers, Michal Marek, Nathan Chancellor, Tom Rix,
	linux-kbuild, linux-kernel, llvm

We're working on providing statically linked images of clang to host on
kernel.org. We're building them in Alpine Linux based Docker containers,
which are MUSL based systems.

In order to keep bootstrapping simpler, I'd like for them to have an
implicit default --target of x86_64-alpine-linux-musl (set via LLVM's
cmake variable LLVM_DEFAULT_TARGET_TRIPLE).

Similarly, if one were to use a different build of clang meant for a
glibc or bionic based system on a MUSL based host, we'd prefer to use
the correct MUSL based triple for target hosts.

Borrowed from the Zen of Python: Explicit is better than implicit. Let's
be explicit about the target triple for HOSTCC when building with
HOSTCC=clang or LLVM=1.

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 Makefile               |  3 +--
 scripts/Makefile.clang | 10 ++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 1a6678d817bd..87712d9b043c 100644
--- a/Makefile
+++ b/Makefile
@@ -600,10 +600,9 @@ endif
 # CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
 # and from include/config/auto.conf.cmd to detect the compiler upgrade.
 CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
+HOSTCC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(HOSTCC) --version 2>/dev/null | head -n 1))
 
-ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
 include $(srctree)/scripts/Makefile.clang
-endif
 
 # Include this also for config targets because some architectures need
 # cc-cross-prefix to determine CROSS_COMPILE.
diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
index 87285b76adb2..a4505cd62d7b 100644
--- a/scripts/Makefile.clang
+++ b/scripts/Makefile.clang
@@ -1,3 +1,4 @@
+ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
 # 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.
@@ -39,3 +40,12 @@ CLANG_FLAGS	+= -Werror=ignored-optimization-argument
 KBUILD_CFLAGS	+= $(CLANG_FLAGS)
 KBUILD_AFLAGS	+= $(CLANG_FLAGS)
 export CLANG_FLAGS
+endif
+
+# If HOSTCC is clang, set the host target triple explicitly; do not rely on
+# implicit defaults.
+ifneq ($(findstring clang,$(HOSTCC_VERSION_TEXT)),)
+HOST_TRIPLE		:= --target=$(shell make --version | head -n2 | tail -n1 | cut -d ' ' -f 3)
+KBUILD_HOSTCFLAGS	+= $(HOST_TRIPLE)
+KBUILD_HOSTLDFLAGS	+= $(HOST_TRIPLE)
+endif

base-commit: 79fe0f863f920c5fcf9dea61676742f813f0b7a6
-- 
2.36.1.476.g0c4daa206d-goog


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

* Re: [PATCH] scripts/Makefile.clang: set --target for host based on make -v
  2022-06-17 20:39 [PATCH] scripts/Makefile.clang: set --target for host based on make -v Nick Desaulniers
@ 2022-06-17 23:20 ` Nathan Chancellor
  2022-06-17 23:26   ` Nick Desaulniers
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Chancellor @ 2022-06-17 23:20 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Masahiro Yamada, Michal Marek, Tom Rix, linux-kbuild, linux-kernel, llvm

On Fri, Jun 17, 2022 at 01:39:48PM -0700, Nick Desaulniers wrote:
> We're working on providing statically linked images of clang to host on
> kernel.org. We're building them in Alpine Linux based Docker containers,
> which are MUSL based systems.
> 
> In order to keep bootstrapping simpler, I'd like for them to have an
> implicit default --target of x86_64-alpine-linux-musl (set via LLVM's
> cmake variable LLVM_DEFAULT_TARGET_TRIPLE).
> 
> Similarly, if one were to use a different build of clang meant for a
> glibc or bionic based system on a MUSL based host, we'd prefer to use
> the correct MUSL based triple for target hosts.
> 
> Borrowed from the Zen of Python: Explicit is better than implicit. Let's
> be explicit about the target triple for HOSTCC when building with
> HOSTCC=clang or LLVM=1.
> 
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

I have tested this with a few different distributions on both aarch64
and x86_64:

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

One small comment below.

> ---
>  Makefile               |  3 +--
>  scripts/Makefile.clang | 10 ++++++++++
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 1a6678d817bd..87712d9b043c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -600,10 +600,9 @@ endif
>  # CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
>  # and from include/config/auto.conf.cmd to detect the compiler upgrade.
>  CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
> +HOSTCC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(HOSTCC) --version 2>/dev/null | head -n 1))
>  
> -ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
>  include $(srctree)/scripts/Makefile.clang
> -endif
>  
>  # Include this also for config targets because some architectures need
>  # cc-cross-prefix to determine CROSS_COMPILE.
> diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> index 87285b76adb2..a4505cd62d7b 100644
> --- a/scripts/Makefile.clang
> +++ b/scripts/Makefile.clang
> @@ -1,3 +1,4 @@
> +ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
>  # 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.
> @@ -39,3 +40,12 @@ CLANG_FLAGS	+= -Werror=ignored-optimization-argument
>  KBUILD_CFLAGS	+= $(CLANG_FLAGS)
>  KBUILD_AFLAGS	+= $(CLANG_FLAGS)
>  export CLANG_FLAGS
> +endif
> +
> +# If HOSTCC is clang, set the host target triple explicitly; do not rely on
> +# implicit defaults.
> +ifneq ($(findstring clang,$(HOSTCC_VERSION_TEXT)),)
> +HOST_TRIPLE		:= --target=$(shell make --version | head -n2 | tail -n1 | cut -d ' ' -f 3)

Should we use $(MAKE) instead of make here? I guess the only case where
it would matter is if someone was calling make via an explicit path and
did not have it available in their PATH so maybe it is not worth
worrying about.

> +KBUILD_HOSTCFLAGS	+= $(HOST_TRIPLE)
> +KBUILD_HOSTLDFLAGS	+= $(HOST_TRIPLE)
> +endif
> 
> base-commit: 79fe0f863f920c5fcf9dea61676742f813f0b7a6
> -- 
> 2.36.1.476.g0c4daa206d-goog
> 
> 

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

* Re: [PATCH] scripts/Makefile.clang: set --target for host based on make -v
  2022-06-17 23:20 ` Nathan Chancellor
@ 2022-06-17 23:26   ` Nick Desaulniers
  2022-06-19  9:19     ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Desaulniers @ 2022-06-17 23:26 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Masahiro Yamada, Michal Marek, Tom Rix,
	Linux Kbuild mailing list, LKML, clang-built-linux

On Fri, Jun 17, 2022 at 4:21 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Fri, Jun 17, 2022 at 01:39:48PM -0700, Nick Desaulniers wrote:
> > We're working on providing statically linked images of clang to host on
> > kernel.org. We're building them in Alpine Linux based Docker containers,
> > which are MUSL based systems.
> >
> > In order to keep bootstrapping simpler, I'd like for them to have an
> > implicit default --target of x86_64-alpine-linux-musl (set via LLVM's
> > cmake variable LLVM_DEFAULT_TARGET_TRIPLE).
> >
> > Similarly, if one were to use a different build of clang meant for a
> > glibc or bionic based system on a MUSL based host, we'd prefer to use
> > the correct MUSL based triple for target hosts.
> >
> > Borrowed from the Zen of Python: Explicit is better than implicit. Let's
> > be explicit about the target triple for HOSTCC when building with
> > HOSTCC=clang or LLVM=1.
> >
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
>
> I have tested this with a few different distributions on both aarch64
> and x86_64:
>
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> Tested-by: Nathan Chancellor <nathan@kernel.org>
>
> One small comment below.
>
> > ---
> >  Makefile               |  3 +--
> >  scripts/Makefile.clang | 10 ++++++++++
> >  2 files changed, 11 insertions(+), 2 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 1a6678d817bd..87712d9b043c 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -600,10 +600,9 @@ endif
> >  # CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
> >  # and from include/config/auto.conf.cmd to detect the compiler upgrade.
> >  CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
> > +HOSTCC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(HOSTCC) --version 2>/dev/null | head -n 1))
> >
> > -ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
> >  include $(srctree)/scripts/Makefile.clang
> > -endif
> >
> >  # Include this also for config targets because some architectures need
> >  # cc-cross-prefix to determine CROSS_COMPILE.
> > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> > index 87285b76adb2..a4505cd62d7b 100644
> > --- a/scripts/Makefile.clang
> > +++ b/scripts/Makefile.clang
> > @@ -1,3 +1,4 @@
> > +ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
> >  # 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.
> > @@ -39,3 +40,12 @@ CLANG_FLAGS        += -Werror=ignored-optimization-argument
> >  KBUILD_CFLAGS        += $(CLANG_FLAGS)
> >  KBUILD_AFLAGS        += $(CLANG_FLAGS)
> >  export CLANG_FLAGS
> > +endif
> > +
> > +# If HOSTCC is clang, set the host target triple explicitly; do not rely on
> > +# implicit defaults.
> > +ifneq ($(findstring clang,$(HOSTCC_VERSION_TEXT)),)
> > +HOST_TRIPLE          := --target=$(shell make --version | head -n2 | tail -n1 | cut -d ' ' -f 3)
>
> Should we use $(MAKE) instead of make here? I guess the only case where

oh! yeah, good call. I think so.  Will wait until next Tuesday
(Juneteenth holiday in the US on Monday) to send a v2. Thanks for
taking a look!

> it would matter is if someone was calling make via an explicit path and
> did not have it available in their PATH so maybe it is not worth
> worrying about.
>
> > +KBUILD_HOSTCFLAGS    += $(HOST_TRIPLE)
> > +KBUILD_HOSTLDFLAGS   += $(HOST_TRIPLE)
> > +endif
> >
> > base-commit: 79fe0f863f920c5fcf9dea61676742f813f0b7a6
> > --
> > 2.36.1.476.g0c4daa206d-goog
> >
> >



-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] scripts/Makefile.clang: set --target for host based on make -v
  2022-06-17 23:26   ` Nick Desaulniers
@ 2022-06-19  9:19     ` Masahiro Yamada
  0 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-06-19  9:19 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Nathan Chancellor, Michal Marek, Tom Rix,
	Linux Kbuild mailing list, LKML, clang-built-linux

On Sat, Jun 18, 2022 at 8:26 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Fri, Jun 17, 2022 at 4:21 PM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > On Fri, Jun 17, 2022 at 01:39:48PM -0700, Nick Desaulniers wrote:
> > > We're working on providing statically linked images of clang to host on
> > > kernel.org. We're building them in Alpine Linux based Docker containers,
> > > which are MUSL based systems.
> > >
> > > In order to keep bootstrapping simpler, I'd like for them to have an
> > > implicit default --target of x86_64-alpine-linux-musl (set via LLVM's
> > > cmake variable LLVM_DEFAULT_TARGET_TRIPLE).
> > >
> > > Similarly, if one were to use a different build of clang meant for a
> > > glibc or bionic based system on a MUSL based host, we'd prefer to use
> > > the correct MUSL based triple for target hosts.
> > >
> > > Borrowed from the Zen of Python: Explicit is better than implicit. Let's
> > > be explicit about the target triple for HOSTCC when building with
> > > HOSTCC=clang or LLVM=1.


If people try to use the clang packaged by you,
I think the same thing will occur on any project.

I do not understand why you are trying to patch the kernel build?


If this is a problem, it is specific to your clang package,
not to the linux kernel.

You need to find a solution in your package.





> > >
> > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> >
> > I have tested this with a few different distributions on both aarch64
> > and x86_64:
> >
> > Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> > Tested-by: Nathan Chancellor <nathan@kernel.org>
> >
> > One small comment below.
> >
> > > ---
> > >  Makefile               |  3 +--
> > >  scripts/Makefile.clang | 10 ++++++++++
> > >  2 files changed, 11 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/Makefile b/Makefile
> > > index 1a6678d817bd..87712d9b043c 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -600,10 +600,9 @@ endif
> > >  # CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
> > >  # and from include/config/auto.conf.cmd to detect the compiler upgrade.
> > >  CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
> > > +HOSTCC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(HOSTCC) --version 2>/dev/null | head -n 1))
> > >
> > > -ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
> > >  include $(srctree)/scripts/Makefile.clang
> > > -endif
> > >
> > >  # Include this also for config targets because some architectures need
> > >  # cc-cross-prefix to determine CROSS_COMPILE.
> > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> > > index 87285b76adb2..a4505cd62d7b 100644
> > > --- a/scripts/Makefile.clang
> > > +++ b/scripts/Makefile.clang
> > > @@ -1,3 +1,4 @@
> > > +ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
> > >  # 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.
> > > @@ -39,3 +40,12 @@ CLANG_FLAGS        += -Werror=ignored-optimization-argument
> > >  KBUILD_CFLAGS        += $(CLANG_FLAGS)
> > >  KBUILD_AFLAGS        += $(CLANG_FLAGS)
> > >  export CLANG_FLAGS
> > > +endif
> > > +
> > > +# If HOSTCC is clang, set the host target triple explicitly; do not rely on
> > > +# implicit defaults.
> > > +ifneq ($(findstring clang,$(HOSTCC_VERSION_TEXT)),)
> > > +HOST_TRIPLE          := --target=$(shell make --version | head -n2 | tail -n1 | cut -d ' ' -f 3)
> >
> > Should we use $(MAKE) instead of make here? I guess the only case where
>
> oh! yeah, good call. I think so.  Will wait until next Tuesday
> (Juneteenth holiday in the US on Monday) to send a v2. Thanks for
> taking a look!
>
> > it would matter is if someone was calling make via an explicit path and
> > did not have it available in their PATH so maybe it is not worth
> > worrying about.
> >
> > > +KBUILD_HOSTCFLAGS    += $(HOST_TRIPLE)
> > > +KBUILD_HOSTLDFLAGS   += $(HOST_TRIPLE)
> > > +endif
> > >
> > > base-commit: 79fe0f863f920c5fcf9dea61676742f813f0b7a6
> > > --
> > > 2.36.1.476.g0c4daa206d-goog
> > >
> > >
>
>
>
> --
> Thanks,
> ~Nick Desaulniers



--
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2022-06-19  9:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17 20:39 [PATCH] scripts/Makefile.clang: set --target for host based on make -v Nick Desaulniers
2022-06-17 23:20 ` Nathan Chancellor
2022-06-17 23:26   ` Nick Desaulniers
2022-06-19  9:19     ` Masahiro Yamada

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.