Testing an eBPF program can be quite cumbersome. One can try to rely on virtualisation and/or containerisation technologies, but that can become a burden fairly quickly too.
gBPF tries to ease the validation and testing of eBPF programs by providing control over the input and output memory as well as mimicking the different helpers leveraged when writing eBPF programs.
eBPF programs are usually written in a subset of C and compiled to eBPF instructions
with clang(1). In order to do so, it must've been compiled with support for
the BPF backend which is the case on most Linux-based distros, but not on macOS. In
order to make working with gBPF that much easier, we bundle the clang source as a
submodule you can build as-is with make clang. Be sure to read the documentation
to get a bit more info on how to compile clang and this site for a list
of available flags. To compile clang you don't really need many dependencies other than
clang, make and standard *nix tools. Check this site to get a list of
dependencies. At any rate, the official documentation always trumps these lines.
Once compiled, be sure to run clang --print-targets, your output should resemble
$ ./clang --version
clang version 21.1.8 (https://github.com/llvm/llvm-project.git 2078da43e25a4623cab2d0d60decddf709aaea28)
Target: unknown
Thread model: posix
InstalledDir: /depends/on/your/machine
$ ./clang --print-targets
Registered Targets:
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)