github.com/cilium/ebpf@v0.10.0/cmd/bpf2go/README.md (about) 1 bpf2go 2 === 3 4 `bpf2go` compiles a C source file into eBPF bytecode and then emits a 5 Go file containing the eBPF. The goal is to avoid loading the 6 eBPF from disk at runtime and to minimise the amount of manual 7 work required to interact with eBPF programs. It takes inspiration 8 from `bpftool gen skeleton`. 9 10 Invoke the program using go generate: 11 12 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go foo path/to/src.c -- -I/path/to/include 13 14 This will emit `foo_bpfel.go` and `foo_bpfeb.go`, with types using `foo` 15 as a stem. The two files contain compiled BPF for little and big 16 endian systems, respectively. 17 18 You can use environment variables to affect all bpf2go invocations 19 across a project, e.g. to set specific C flags: 20 21 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go -cflags "$BPF_CFLAGS" foo path/to/src.c 22 23 By exporting `$BPF_CFLAGS` from your build system you can then control 24 all builds from a single location. 25 26 ## Generated types 27 28 `bpf2go` generates Go types for all map keys and values by default. You can 29 disable this behaviour using `-no-global-types`. You can add to the set of 30 types by specifying `-type foo` for each type you'd like to generate. 31 32 ## Examples 33 34 See [examples/kprobe](../../examples/kprobe/main.go) for a fully worked out example.