mbox series

[bpf-next,0/6] tools/bpf: Enable cross-building with clang

Message ID 20211122192019.1277299-1-jean-philippe@linaro.org (mailing list archive)
Headers show
Series tools/bpf: Enable cross-building with clang | expand

Message

Jean-Philippe Brucker Nov. 22, 2021, 7:20 p.m. UTC
Add support for cross-building BPF tools and selftests with clang, by
passing LLVM=1 or CC=clang to make, as well as CROSS_COMPILE. A single
clang toolchain can generate binaries for multiple architectures, so
instead of having prefixes such as aarch64-linux-gnu-gcc, clang uses the
-target parameter: `clang -target aarch64-linux-gnu'.

Patch 1 adds the parameter in Makefile.include so tools can easily
support this. Patch 2 prepares for the libbpf change from patch 3 (keep
building resolve_btfids's libbpf in the host arch, when cross-building
the kernel with clang). Patches 3-6 enable cross-building BPF tools with
clang.

Jean-Philippe Brucker (6):
  tools: Help cross-building with clang
  tools/resolve_btfids: Support cross-building the kernel with clang
  tools/libbpf: Enable cross-building with clang
  bpftool: Enable cross-building with clang
  tools/runqslower: Enable cross-building with clang
  selftests/bpf: Enable cross-building with clang

 tools/bpf/bpftool/Makefile           | 13 +++++++------
 tools/bpf/resolve_btfids/Makefile    |  1 +
 tools/bpf/runqslower/Makefile        |  4 ++--
 tools/lib/bpf/Makefile               |  3 ++-
 tools/scripts/Makefile.include       | 13 ++++++++++++-
 tools/testing/selftests/bpf/Makefile |  8 ++++----
 6 files changed, 28 insertions(+), 14 deletions(-)

Comments

Quentin Monnet Nov. 26, 2021, 8:36 p.m. UTC | #1
On Mon, 22 Nov 2021 at 19:23, Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> Add support for cross-building BPF tools and selftests with clang, by
> passing LLVM=1 or CC=clang to make, as well as CROSS_COMPILE. A single
> clang toolchain can generate binaries for multiple architectures, so
> instead of having prefixes such as aarch64-linux-gnu-gcc, clang uses the
> -target parameter: `clang -target aarch64-linux-gnu'.
>
> Patch 1 adds the parameter in Makefile.include so tools can easily
> support this. Patch 2 prepares for the libbpf change from patch 3 (keep
> building resolve_btfids's libbpf in the host arch, when cross-building
> the kernel with clang). Patches 3-6 enable cross-building BPF tools with
> clang.

The set looks good to me. I checked that the tools are still building
(without cross-compiling). I currently have issues building the
selftests on my setup, but they don't appear to be related to this
patchset.

Acked-by: Quentin Monnet <quentin@isovalent.com>

Note that on bpf-next, patch 5 (runqslower) has a conflict with
be79505caf3f ("tools/runqslower: Install libbpf headers when
building").

Did you consider enabling cross-compiling for the BPF samples too? I'm
asking because the build system is pretty similar to the BPF tools.

Thanks,
Quentin
Daniel Borkmann Nov. 26, 2021, 9:15 p.m. UTC | #2
On 11/26/21 9:36 PM, Quentin Monnet wrote:
> On Mon, 22 Nov 2021 at 19:23, Jean-Philippe Brucker
> <jean-philippe@linaro.org> wrote:
>>
>> Add support for cross-building BPF tools and selftests with clang, by
>> passing LLVM=1 or CC=clang to make, as well as CROSS_COMPILE. A single
>> clang toolchain can generate binaries for multiple architectures, so
>> instead of having prefixes such as aarch64-linux-gnu-gcc, clang uses the
>> -target parameter: `clang -target aarch64-linux-gnu'.
>>
>> Patch 1 adds the parameter in Makefile.include so tools can easily
>> support this. Patch 2 prepares for the libbpf change from patch 3 (keep
>> building resolve_btfids's libbpf in the host arch, when cross-building
>> the kernel with clang). Patches 3-6 enable cross-building BPF tools with
>> clang.
> 
> The set looks good to me. I checked that the tools are still building
> (without cross-compiling). I currently have issues building the
> selftests on my setup, but they don't appear to be related to this
> patchset.
> 
> Acked-by: Quentin Monnet <quentin@isovalent.com>
> 
> Note that on bpf-next, patch 5 (runqslower) has a conflict with
> be79505caf3f ("tools/runqslower: Install libbpf headers when
> building").

Jean-Philippe, please do one rebase spin for addressing the above.

Thanks,
Daniel
Jean-Philippe Brucker Nov. 29, 2021, 9:42 a.m. UTC | #3
On Fri, Nov 26, 2021 at 08:36:24PM +0000, Quentin Monnet wrote:
> On Mon, 22 Nov 2021 at 19:23, Jean-Philippe Brucker
> <jean-philippe@linaro.org> wrote:
> >
> > Add support for cross-building BPF tools and selftests with clang, by
> > passing LLVM=1 or CC=clang to make, as well as CROSS_COMPILE. A single
> > clang toolchain can generate binaries for multiple architectures, so
> > instead of having prefixes such as aarch64-linux-gnu-gcc, clang uses the
> > -target parameter: `clang -target aarch64-linux-gnu'.
> >
> > Patch 1 adds the parameter in Makefile.include so tools can easily
> > support this. Patch 2 prepares for the libbpf change from patch 3 (keep
> > building resolve_btfids's libbpf in the host arch, when cross-building
> > the kernel with clang). Patches 3-6 enable cross-building BPF tools with
> > clang.
> 
> The set looks good to me. I checked that the tools are still building
> (without cross-compiling). I currently have issues building the
> selftests on my setup, but they don't appear to be related to this
> patchset.
> 
> Acked-by: Quentin Monnet <quentin@isovalent.com>
> 
> Note that on bpf-next, patch 5 (runqslower) has a conflict with
> be79505caf3f ("tools/runqslower: Install libbpf headers when
> building").

Ah right, I have the series on top of "tools/runqslower: Fix cross-build",
which is in bpf/master but not yet in bpf-next. I'll wait for the branches
to synchronize before resending, since the patches conflict either way.

> Did you consider enabling cross-compiling for the BPF samples too? I'm
> asking because the build system is pretty similar to the BPF tools.

Right, the problems seem similar to the selftests (need to build two
libbpfs, pass $(HOSTCC) etc). Samples aren't as crucial as tools but I can
look into it when I find a bit of time.

Thanks,
Jean