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.cfile that contains the eBPF program - a
*.cfile 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 programIt outputs a your eBPF application binary in
.output/program -
make cov/programIt 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-onlyflag 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 fentryThe 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/fentryAt this point, you should be able to run it:
sudo .output/cov/fentryWanna build every eBPF application as is?
makeWanna instrument every eBPF application here for code coverage?
make covWanna start over but not recompile the dependencies too?
make cleanWanna start from scratch?
make distclean-
libBPFCov.soFirst obtain the LLVM pass library, please.
-
bpftoolYou can provide your own
bpftoolby putting it in thetoolsdirectory.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
bpftoolthat supports the skeletons feature becase this tool uses custom eBPF sections for storing the instrumentation and coverage mapping data. -
libbpfEnsure you have the git submodule in the
libbpf/directory.