Search code examples
bpfebpfbcc-bpf

Generate a executable from bcc python script


bcc uses python to compile ebpf programs, is there any convenient way to generate a executable file from these python scripts so that I can run these tracing programs on servers where clang and llvm environment are not installed?


Solution

  • TL;DR. No, not with BCC. You might want to check out BPF CO-RE though.


    There are two pieces to solving this for bcc. First, you need to compile an object file with the BPF program and maps that would work on your target system (same kernel version/headers and same conventions as Linux BPF loader). Second, you need BCC's userspace component to recognize and work with this program and maps.

    Neither of these is enabled by BCC currently. My fork has a (somewhat stale) branch where I implemented support for dumping an object file to disk with conventions that enable you to load it in the Linux kernel. This is probably incomplete for your purpose, as I was only trying to load the program in the kernel; I didn't care what happened afterward. There has also been some work to run BCC's tools on remote systems, but I don't know what the current state of that is.

    One effort underway that will address your issue is BPF CO-RE. BPF CO-RE allows you to develop BPF tracing programs that are portable across Linux versions. You therefore don't need to compile with the Linux headers of the target system and don't need LLVM/Clang anymore. The team behind this effort recently posted two articles on the principles and inner workings of BPF CO-RE and how it would apply to BCC's tools.