Here (in the src/
directory) you will find some eBPF programs to demonstrate the usage of libBPFCov.so
.
Every example is composed by:
- a
*.bpf.c
file that contains the eBPF program - a
*.c
file that contains the userspace code
The Makefile generates 2 targets for each word of the EXAMPLES variable in it.
So, assuming the EXAMPLES
variable contains a word program
, then the following targets will be generated:
-
make program
It outputs a your eBPF application binary in
.output/program
-
make cov/program
It outputs an eBPF application binary instrumented for source-based code coverage in
.output/cov/program
In case you wanna try bpfcov on another example, doing it is just a matter of putting its source code in the src/
directory and appending its name into the `EXAMPLES variable in the Makefile.
The Makefile takes care of everything... But I suggest you to take a look at it in case you are interested into getting to know the details of the steps. Or at least, read the following section.
The key aspects of building an instrumented eBPF application are the following ones.
-
Compile you eBPF program (
*.bpf.c
) to LLVM IR instrumenting it with profile and coverage mapping information (-fprofile-instr-generate -fcoverage-mapping
) -
Run the pass (
libBPFCov.so
) on the LLVM IR to fix it for the BPF VM- Use it to compile a valid BPF ELF that loads successfully in the Linux kernel
-
Run again the pass (
libBPFCov.so
) with the-strip-initializers-only
flag on the LLVM IR- Use the resulting LLVM IR to compile a (valid but not loading) BPF ELF (
*.bpf.obj
) - It will serve you as one of the inputs for
llvm-cov
- Use the resulting LLVM IR to compile a (valid but not loading) BPF ELF (
-
Userspace code compilation as usual but using the instrumted ELF from step 2
Did you already take a look at the requirements section?
Do you only wanna build a specific eBPF example application as is?
Good!
make fentry
The binary will end up in .output/fentry
.
Do you only wanna compile a specific eBPF example application instrumented for code coverage?
Even better!
make cov/fentry
At this point, you should be able to run it:
sudo .output/cov/fentry
Wanna build every eBPF application as is?
make
Wanna instrument every eBPF application here for code coverage?
make cov
Wanna start over but not recompile the dependencies too?
make clean
Wanna start from scratch?
make distclean
-
libBPFCov.so
First obtain the LLVM pass library, please.
-
bpftool
You can provide your own
bpftool
by putting it in thetools
directory.Otherwise the Makefile will try to find it in the system path and symlink it into the
tools/
directory.In any case you will need a
bpftool
that supports the skeletons feature becase this tool uses custom eBPF sections for storing the instrumentation and coverage mapping data. -
libbpf
Ensure you have the git submodule in the
libbpf/
directory.