From: Nick Desaulniers <ndesaulniers@google.com>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>,
Miguel Ojeda <ojeda@kernel.org>,
Fangrui Song <maskray@google.com>,
Michal Marek <michal.lkml@markovi.net>,
Arnd Bergmann <arnd@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
clang-built-linux <clang-built-linux@googlegroups.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Christoph Hellwig <hch@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v2 2/2] Makefile: infer CROSS_COMPILE from SRCARCH for LLVM=1 LLVM_IAS=1
Date: Wed, 28 Jul 2021 11:59:59 -0700 [thread overview]
Message-ID: <CAKwvOdkENUWd7OgJO=dNiYjH6D1aJ0puBgs4W7uuYO9xQiAiNg@mail.gmail.com> (raw)
In-Reply-To: <CAK7LNAQtw-ZR0D4quHAqT_6rkMjgkjJhWG8EY7H4T1=PwUMgVw@mail.gmail.com>
On Tue, Jul 20, 2021 at 8:50 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Wed, Jul 21, 2021 at 2:30 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > On 7/20/2021 1:04 AM, Masahiro Yamada wrote:
> > > On Fri, Jul 9, 2021 at 8:25 AM 'Nick Desaulniers' via Clang Built
> > > Linux <clang-built-linux@googlegroups.com> wrote:
> > >>
> > >> diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
> > >> index 297932e973d4..956603f56724 100644
> > >> --- a/scripts/Makefile.clang
> > >> +++ b/scripts/Makefile.clang
> > >> @@ -1,6 +1,36 @@
> > >> -ifneq ($(CROSS_COMPILE),)
> > >> +# Individual arch/{arch}/Makfiles 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),)
> > >> +ifneq ($(LLVM),)
> > >
> > >
> > > Do you need to check $(LLVM) ?
> > >
> > >
> > > LLVM=1 is a convenient switch to change all the
> > > defaults, but yet you can flip each tool individually.
> > >
> > > Instead of LLVM=1, you still should be able to
> > > get the equivalent setups by:
> > >
> > >
> > > make CC=clang LD=ld.lld AR=llvm-ar OBJCOPY=llvm-objcopy ...
> > >
> > >
> > > The --target option is passed to only
> > > KBUILD_CFLAGS and KBUILD_AFLAGS.
> > >
> > > So, when we talk about --target=,
> > > we only care about whether $(CC) is Clang.
> > > Not caring about $(AR), $(LD), or $(OBJCOPY).
> > >
> > >
> > > scripts/Makefile.clang is already guarded by:
> > >
> > > ifneq ($(findstring clang,$(CC_VERSION_TEXT)),
> >
> > $ make ARCH=arm64 CC=clang LLVM_IAS=1
> >
> > will use the right compiler and assembler but none of the other binary
> > tools because '--prefix=' will not be set so CROSS_COMPILE needs to be
> > specified still, which defeats the purpose of this whole change. This
> > patch is designed to work for the "normal" case of saying "I want to use
> > all of the LLVM tools", not "I want to use clang by itself".
>
>
> I disagree.
>
> LLVM=1 is a shorthand.
>
>
>
> make LLVM=1 LLVM_IAS=1
>
> should be equivalent to:
>
> make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \
> OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf \
> HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld \
> LLVM_IAS=1
>
>
>
> We do not care about the origin of CC=clang,
> whether it came from LLVM=1 or every tool was explicitly,
> individually specified.
>
>
>
> ifneq ($(LLVM),) is a garbage code
> that checks a pointless thing.
Masahiro,
Nathan is correct. Test for yourself; if you apply these two patches,
then apply:
diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
index 956603f56724..a1b46811bdc6 100644
--- a/scripts/Makefile.clang
+++ b/scripts/Makefile.clang
@@ -2,7 +2,6 @@
# and -m32/-m64 to set word size based on Kconfigs instead of relying on the
# target triple.
ifeq ($(CROSS_COMPILE),)
-ifneq ($(LLVM),)
ifeq ($(LLVM_IAS),1)
ifeq ($(SRCARCH),arm)
CLANG_FLAGS += --target=arm-linux-gnueabi
@@ -26,7 +25,6 @@ else
$(error Specify CROSS_COMPILE or add '--target=' option to
scripts/Makefile.clang)
endif # SRCARCH
endif # LLVM_IAS
-endif # LLVM
else
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
endif # CROSS_COMPILE
Then build as Nathan specified:
$ ARCH=arm64 make CC=clang LLVM_IAS=1 -j72 defconfig all
...
arch/arm64/Makefile:25: ld does not support --fix-cortex-a53-843419;
kernel may be susceptible to erratum
...
LD arch/arm64/kernel/vdso/vdso.so.dbg
ld: unrecognised emulation mode: aarch64linux
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu
elf_l1om elf_k1om i386pep i386pe
make[1]: *** [arch/arm64/kernel/vdso/Makefile:56:
arch/arm64/kernel/vdso/vdso.so.dbg] Error 1
make: *** [arch/arm64/Makefile:193: vdso_prepare] Error 2
Nathan referred to --prefix, but in this failure, because
CROSS_COMPILE was never set, the top level Makefile set LD to:
452 LD = $(CROSS_COMPILE)ld
in this case `ld` in my path was my host x86 linker, which is not
correct for a cross compilation of arm64 target.
Perhaps we can somehow support "implicit CROSS_COMPILE" with just
CC=clang, and not LLVM=1, but I think it would be inflexible to
hardcode such target triple prefixes. What if someone has
arm-linux-gnueabi-as but not arm-linux-gnueabihf-as installed? That's
the point of CROSS_COMPILE in my opinion to provide such flexibility
at the cost of additional command line verbosity.
For the common case of LLVM=1 though, this series is a simplification.
If users want to specify CC=clang, then they MUST use CROSS_COMPILE
when cross compiling.
Please review the current approach and see if there's more I can
improve in a v3; otherwise I still think this series is good to go.
--
Thanks,
~Nick Desaulniers
next prev parent reply other threads:[~2021-07-28 19:00 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-08 23:25 [PATCH v2 0/2] infer CROSS_COMPILE from SRCARCH for LLVM=1 LLVM_IAS=1 Nick Desaulniers
2021-07-08 23:25 ` [PATCH v2 1/2] Makefile: move initial clang flag handling into scripts/Makefile.clang Nick Desaulniers
2021-07-09 20:12 ` Nathan Chancellor
2021-07-08 23:25 ` [PATCH v2 2/2] Makefile: infer CROSS_COMPILE from SRCARCH for LLVM=1 LLVM_IAS=1 Nick Desaulniers
2021-07-09 20:44 ` Nathan Chancellor
2021-07-20 8:04 ` Masahiro Yamada
2021-07-20 17:30 ` Nathan Chancellor
2021-07-21 3:49 ` Masahiro Yamada
2021-07-28 18:59 ` Nick Desaulniers [this message]
2021-07-28 22:35 ` Masahiro Yamada
2021-07-20 17:42 ` Linus Torvalds
2021-07-20 19:58 ` Arnd Bergmann
2021-07-20 20:18 ` Nick Desaulniers
2021-07-21 4:04 ` Masahiro Yamada
2021-07-23 19:54 ` Geert Uytterhoeven
2021-07-24 13:46 ` Masahiro Yamada
2021-07-26 20:27 ` Eric W. Biederman
2021-07-27 7:07 ` Geert Uytterhoeven
2021-07-27 7:49 ` Arnd Bergmann
2021-07-27 7:55 ` Geert Uytterhoeven
2021-07-27 8:21 ` Arnd Bergmann
2021-07-27 10:10 ` Masahiro Yamada
2021-07-27 14:16 ` Eric W. Biederman
2021-07-27 15:45 ` Masahiro Yamada
2021-07-27 18:46 ` Eric W. Biederman
2021-07-28 22:31 ` Masahiro Yamada
2021-07-20 20:52 ` Nick Desaulniers
2021-07-20 21:11 ` Linus Torvalds
2021-07-20 21:27 ` Nick Desaulniers
2021-07-21 4:53 ` Masahiro Yamada
2021-07-20 21:29 ` Nick Desaulniers
2021-07-20 21:54 ` Linus Torvalds
2021-07-20 23:19 ` Linus Torvalds
2021-07-20 23:22 ` Linus Torvalds
2021-07-21 5:12 ` Masahiro Yamada
2021-07-21 4:52 ` Christoph Hellwig
2021-07-21 5:33 ` Masahiro Yamada
2021-07-21 4:31 ` Masahiro Yamada
2021-07-21 4:44 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKwvOdkENUWd7OgJO=dNiYjH6D1aJ0puBgs4W7uuYO9xQiAiNg@mail.gmail.com' \
--to=ndesaulniers@google.com \
--cc=arnd@kernel.org \
--cc=clang-built-linux@googlegroups.com \
--cc=geert@linux-m68k.org \
--cc=hch@infradead.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=maskray@google.com \
--cc=michal.lkml@markovi.net \
--cc=nathan@kernel.org \
--cc=ojeda@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).