Topics

clang 10 for BPF CO-RE

Tristan Mayfield
 

Hi all,
 
Finally found the BPF blog and it's been nice to get more information on using libbpf directly since I don't have a lot of systems or kernel experience.
 
Scanning through the "BCC to libbpf" post, I noticed Andrii calls for using clang 10. I went to look at llvm releases and only saw clang/llvm 9 (as of September 2019).
Is clang 10 just built from source?
 
Looking forward to building with CO-RE and move some of my BCC tooling to libbpf.
 
-Tristan

Andrii Nakryiko
 

On Wed, Mar 11, 2020 at 10:33 AM <tmayfield@...> wrote:

Hi all,

Finally found the BPF blog and it's been nice to get more information on using libbpf directly since I don't have a lot of systems or kernel experience.
Thanks! Glad it was useful.


Scanning through the "BCC to libbpf" post, I noticed Andrii calls for using clang 10. I went to look at llvm releases and only saw clang/llvm 9 (as of September 2019).
Is clang 10 just built from source?
For kernel/libbpf development we do build Clang from sources, but you
can install it from packages as well. See https://apt.llvm.org/, there
are packages for Clang 10 and even Clang 11 and they are updated
frequently.


Looking forward to building with CO-RE and move some of my BCC tooling to libbpf.
Great, please do!


-Tristan

Jesper Dangaard Brouer
 

On Wed, 11 Mar 2020 10:36:47 -0700
"Andrii Nakryiko" <andrii.nakryiko@...> wrote:

On Wed, Mar 11, 2020 at 10:33 AM <tmayfield@...> wrote:

Hi all,

Finally found the BPF blog and it's been nice to get more
information on using libbpf directly since I don't have a lot of
systems or kernel experience.
Thanks! Glad it was useful.
I assume this is the blog post[1]:
[1] https://facebookmicrosites.github.io/bpf/blog/2020/02/20/bcc-to-libbpf-howto-guide.html
Thanks for writing that Andrii!

For using libbpf directly from C, we also have the XDP-tutorial[2], but
doesn't contain BPF CO-RE examples. And it uses the old style map
defines. We are planning to update/fix that, once LLVM 10 gets more
widely available in distros.

[2] https://github.com/xdp-project/xdp-tutorial


Scanning through the "BCC to libbpf" post, I noticed Andrii calls
for using clang 10. I went to look at llvm releases and only saw
clang/llvm 9 (as of September 2019). Is clang 10 just built from
source?
For kernel/libbpf development we do build Clang from sources, but you
can install it from packages as well. See https://apt.llvm.org/, there
are packages for Clang 10 and even Clang 11 and they are updated
frequently.
Let me give you the manual compile recipe (that I got from Eelco):

git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir -p llvm/build/install
cd llvm/build
cmake -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
-DLLVM_ENABLE_PROJECTS="clang" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install ..
ninja && ninja install
export PATH=$PWD/install/bin:$PATH

--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer