[v2,1/3] build: add aarch64 clang to meson cross-compile

Message ID 1601548239-2990-2-git-send-email-juraj.linkes@pantheon.tech (mailing list archive)
State Superseded, archived
Headers
Series aarch64 clang cross compilation |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Juraj Linkeš Oct. 1, 2020, 10:30 a.m. UTC
  Create meson cross file arm64_armv8_linux_clang_ubuntu1804.
Use clang/LLVM toolchain with sysroot pointing to gcc cross stdlib.

Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
 config/arm/arm64_armv8_linux_clang_ubuntu1804 | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 config/arm/arm64_armv8_linux_clang_ubuntu1804
  

Comments

Jerin Jacob Oct. 4, 2020, 8:29 a.m. UTC | #1
On Thu, Oct 1, 2020 at 4:07 PM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:
>
> Create meson cross file arm64_armv8_linux_clang_ubuntu1804.
> Use clang/LLVM toolchain with sysroot pointing to gcc cross stdlib.
>
> Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
> ---
>  config/arm/arm64_armv8_linux_clang_ubuntu1804 | 20 +++++++++++++++++++

IMO, if we are adding a specific OS distribution-specific
configuration then it won't scale.
Why not have just arm64_armv8_linux_clang ?
  
Juraj Linkeš Oct. 5, 2020, 10:57 a.m. UTC | #2
> -----Original Message-----
> From: Jerin Jacob <jerinjacobk@gmail.com>
> Sent: Sunday, October 4, 2020 10:30 AM
> To: Juraj Linkeš <juraj.linkes@pantheon.tech>
> Cc: Thomas Monjalon <thomas@monjalon.net>; David Marchand
> <david.marchand@redhat.com>; Aaron Conole <aconole@redhat.com>;
> Michael Santana <maicolgabriel@hotmail.com>; dpdk-dev <dev@dpdk.org>
> Subject: Re: [dpdk-dev] [PATCH v2 1/3] build: add aarch64 clang to meson cross-
> compile
> 
> On Thu, Oct 1, 2020 at 4:07 PM Juraj Linkeš <juraj.linkes@pantheon.tech>
> wrote:
> >
> > Create meson cross file arm64_armv8_linux_clang_ubuntu1804.
> > Use clang/LLVM toolchain with sysroot pointing to gcc cross stdlib.
> >
> > Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
> > ---
> >  config/arm/arm64_armv8_linux_clang_ubuntu1804 | 20
> > +++++++++++++++++++
> 
> IMO, if we are adding a specific OS distribution-specific configuration then it
> won't scale.
> Why not have just arm64_armv8_linux_clang ?

CFLAGS, LDFLAGS, c_args and c_link_args don't work when cross-compiling (at least they didn't work when I tested it) and that means we have to put the paths to stdlib (which llvm/clang doesn't implement) into a cross file. The arm64_armv8_linux_clang_ubuntu1804 contains paths that work with ubuntu clang/gcc packages (and would thus be used in CI). We can't have a generic cross file for clang because of this path limitation.
  
Jerin Jacob Oct. 5, 2020, 2:26 p.m. UTC | #3
On Mon, Oct 5, 2020 at 4:27 PM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:
>
>
>
> > -----Original Message-----
> > From: Jerin Jacob <jerinjacobk@gmail.com>
> > Sent: Sunday, October 4, 2020 10:30 AM
> > To: Juraj Linkeš <juraj.linkes@pantheon.tech>
> > Cc: Thomas Monjalon <thomas@monjalon.net>; David Marchand
> > <david.marchand@redhat.com>; Aaron Conole <aconole@redhat.com>;
> > Michael Santana <maicolgabriel@hotmail.com>; dpdk-dev <dev@dpdk.org>
> > Subject: Re: [dpdk-dev] [PATCH v2 1/3] build: add aarch64 clang to meson cross-
> > compile
> >
> > On Thu, Oct 1, 2020 at 4:07 PM Juraj Linkeš <juraj.linkes@pantheon.tech>
> > wrote:
> > >
> > > Create meson cross file arm64_armv8_linux_clang_ubuntu1804.
> > > Use clang/LLVM toolchain with sysroot pointing to gcc cross stdlib.
> > >
> > > Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
> > > ---
> > >  config/arm/arm64_armv8_linux_clang_ubuntu1804 | 20
> > > +++++++++++++++++++
> >
> > IMO, if we are adding a specific OS distribution-specific configuration then it
> > won't scale.
> > Why not have just arm64_armv8_linux_clang ?
>
> CFLAGS, LDFLAGS, c_args and c_link_args don't work when cross-compiling (at least they didn't work when I tested it) and that means we have to put the paths to stdlib (which llvm/clang doesn't implement) into a cross file

I am using cross-build, following syntax is working
CFLAGS='-g -ggdb3' meson build

> The arm64_armv8_linux_clang_ubuntu1804 contains paths that work with ubuntu clang/gcc packages (and would thus be used in CI). We can't have a generic cross file for clang because of this path limitation.

If ubuntu 18.04 needs some fix up like adding the stuff to PATH etc,
we could do a different stage in Travis ci. right?
  
Juraj Linkeš Oct. 22, 2020, 1:40 p.m. UTC | #4
> -----Original Message-----
> From: Jerin Jacob <jerinjacobk@gmail.com>
> Sent: Monday, October 5, 2020 4:26 PM
> To: Juraj Linkeš <juraj.linkes@pantheon.tech>
> Cc: Thomas Monjalon <thomas@monjalon.net>; David Marchand
> <david.marchand@redhat.com>; Aaron Conole <aconole@redhat.com>;
> Michael Santana <maicolgabriel@hotmail.com>; dpdk-dev <dev@dpdk.org>
> Subject: Re: [dpdk-dev] [PATCH v2 1/3] build: add aarch64 clang to meson cross-
> compile
> 
> On Mon, Oct 5, 2020 at 4:27 PM Juraj Linkeš <juraj.linkes@pantheon.tech>
> wrote:
> >
> >
> >
> > > -----Original Message-----
> > > From: Jerin Jacob <jerinjacobk@gmail.com>
> > > Sent: Sunday, October 4, 2020 10:30 AM
> > > To: Juraj Linkeš <juraj.linkes@pantheon.tech>
> > > Cc: Thomas Monjalon <thomas@monjalon.net>; David Marchand
> > > <david.marchand@redhat.com>; Aaron Conole <aconole@redhat.com>;
> > > Michael Santana <maicolgabriel@hotmail.com>; dpdk-dev <dev@dpdk.org>
> > > Subject: Re: [dpdk-dev] [PATCH v2 1/3] build: add aarch64 clang to
> > > meson cross- compile
> > >
> > > On Thu, Oct 1, 2020 at 4:07 PM Juraj Linkeš
> > > <juraj.linkes@pantheon.tech>
> > > wrote:
> > > >
> > > > Create meson cross file arm64_armv8_linux_clang_ubuntu1804.
> > > > Use clang/LLVM toolchain with sysroot pointing to gcc cross stdlib.
> > > >
> > > > Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
> > > > ---
> > > >  config/arm/arm64_armv8_linux_clang_ubuntu1804 | 20
> > > > +++++++++++++++++++
> > >
> > > IMO, if we are adding a specific OS distribution-specific
> > > configuration then it won't scale.
> > > Why not have just arm64_armv8_linux_clang ?
> >
> > CFLAGS, LDFLAGS, c_args and c_link_args don't work when
> > cross-compiling (at least they didn't work when I tested it) and that
> > means we have to put the paths to stdlib (which llvm/clang doesn't
> > implement) into a cross file
> 
> I am using cross-build, following syntax is working CFLAGS='-g -ggdb3' meson
> build
> 
> > The arm64_armv8_linux_clang_ubuntu1804 contains paths that work with
> ubuntu clang/gcc packages (and would thus be used in CI). We can't have a
> generic cross file for clang because of this path limitation.
> 
> If ubuntu 18.04 needs some fix up like adding the stuff to PATH etc, we could do
> a different stage in Travis ci. right?

Sorry for the long delay, I was swamped with other stuff.

What do you mean by "following syntax is working CFLAGS='-g -ggdb3' meson build" in cross-builds? I tried the same thing with the flags I've put into the arm64_armv8_linux_clang_ubuntu1804 file and it doesn't work at all for cross builds - CFLAGS get only used for native compiler and not the cross compiler.

Here's what I mean:
CFLAGS='--sysroot /usr/aarch64-linux-gnu --gcc-toolchain=/usr' meson clang-build-aarch64 --werror -Dexamples=all --default-library static --cross-file config/arm/arm64_armv8_linux_clang  # the cross file doesn't contain the paths
Results in meson not being able to properly figure out size of "void *":
-----------------------
Running compile:
Working directory:  /tmp/tmpf_n3b9c7
Command line:  clang /tmp/tmpf_n3b9c7/testfile.c -pipe -D_FILE_OFFSET_BITS=64 -c -o /tmp/tmpf_n3b9c7/output.obj -target aarch64-linux-gnu -O0

Code:
 #include <stdio.h>

        int main(int argc, char **argv) {
            void * something;
        }
Compiler stdout:

Compiler stderr:
 In file included from /tmp/tmpf_n3b9c7/testfile.c:1:
/usr/include/stdio.h:27:10: fatal error: 'bits/libc-header-start.h' file not found
#include <bits/libc-header-start.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Checking for size of "void *": -1
-----------------------

However, when I put the paths into the cross file and run without CFLAGS, it works fine:
meson clang-build-aarch64 --werror -Dexamples=all --default-library static --cross-file config/arm/arm64_armv8_linux_clang_ubuntu1804  # the cross file contains the paths
Results in:
-----------------------
Running compile:
Working directory:  /tmp/tmpikoi3353
Command line:  clang /tmp/tmpikoi3353/testfile.c -pipe -D_FILE_OFFSET_BITS=64 -c -o /tmp/tmpikoi3353/output.obj -target aarch64-linux-gnu --sysroot /usr/aarch64-linux-gnu --gcc-toolchain=/usr -O0

Code:
 #include <stdio.h>

        int main(int argc, char **argv) {
            void * something;
        }
Compiler stdout:

Compiler stderr:
-----------------------

From what I was able to google, meson devs only want to allow specifying cross-specific option in cross files and are purposefully ignoring env variables for cross builds.

What we could do is just modify the cross file in Travis before running the build. But then we would have a useless clang cross file in the repo since we have to have the paths in it for clang cross compilition.

I hope I'm wrong, but I don't see a way around this.

What do you think?
  

Patch

diff --git a/config/arm/arm64_armv8_linux_clang_ubuntu1804 b/config/arm/arm64_armv8_linux_clang_ubuntu1804
new file mode 100644
index 000000000..67f475eb0
--- /dev/null
+++ b/config/arm/arm64_armv8_linux_clang_ubuntu1804
@@ -0,0 +1,20 @@ 
+[binaries]
+c = 'clang'
+cpp = 'clang++'
+ar = 'llvm-ar'
+strip = 'llvm-strip'
+llvm-config = 'llvm-config'
+pcap-config = 'llvm-config'
+pkgconfig = 'aarch64-linux-gnu-pkg-config'
+
+[host_machine]
+system = 'linux'
+cpu_family = 'aarch64'
+cpu = 'armv8-a'
+endian = 'little'
+
+[properties]
+implementor_id = 'generic'
+implementor_pn = 'default'
+c_args = ['-target', 'aarch64-linux-gnu', '--sysroot', '/usr/aarch64-linux-gnu', '--gcc-toolchain=/usr']
+c_link_args = ['-target', 'aarch64-linux-gnu', '-fuse-ld=lld']