...

Text file src/github.com/cilium/ebpf/cmd/bpf2go/README.md

Documentation: github.com/cilium/ebpf/cmd/bpf2go

     1bpf2go
     2===
     3
     4`bpf2go` compiles a C source file into eBPF bytecode and then emits a
     5Go file containing the eBPF. The goal is to avoid loading the
     6eBPF from disk at runtime and to minimise the amount of manual
     7work required to interact with eBPF programs. It takes inspiration
     8from `bpftool gen skeleton`.
     9
    10Invoke 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
    14This will emit `foo_bpfel.go` and `foo_bpfeb.go`, with types using `foo`
    15as a stem. The two files contain compiled BPF for little and big
    16endian systems, respectively.
    17
    18You can use environment variables to affect all bpf2go invocations
    19across 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
    23By exporting `$BPF_CFLAGS` from your build system you can then control
    24all 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
    29disable this behaviour using `-no-global-types`. You can add to the set of
    30types by specifying `-type foo` for each type you'd like to generate.
    31
    32## Examples
    33
    34See [examples/kprobe](../../examples/kprobe/main.go) for a fully worked out example.

View as plain text