diff mbox series

[v5,3/3] Documentation/llvm: update CROSS_COMPILE inferencing

Message ID 20210730215708.276437-4-ndesaulniers@google.com (mailing list archive)
State New, archived
Headers show
Series infer --target from SRCARCH for CC=clang | expand

Commit Message

Nick Desaulniers July 30, 2021, 9:57 p.m. UTC
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(+)

Comments

Fangrui Song July 30, 2021, 11:12 p.m. UTC | #1
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
>
Masahiro Yamada July 31, 2021, 12:04 a.m. UTC | #2
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
Nick Desaulniers Aug. 2, 2021, 5:57 p.m. UTC | #3
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.
Nick Desaulniers Aug. 2, 2021, 6:30 p.m. UTC | #4
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.
diff mbox series

Patch

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
 -----------------------