Message ID | 20210802183910.1802120-4-ndesaulniers@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | infer --target from SRCARCH for CC=clang | expand |
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 > ----------------------- > >
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.
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."
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
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.
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 -----------------------