Differences from libbpf
gobpfgo follows libbpf 1.9 development at the pinned
4f05fb0
commit, with the same names, load steps, CO-RE relocations and errnos. This
page summarizes where it differs. The source of truth is Differences from
libbpf in
the repository, which gives libbpf’s behavior, gobpfgo’s, the status and the
impact of each difference, and is updated as differences close. Each row
below links to its entry there.
Intentional API differences
Section titled “Intentional API differences”These differences are in the Go API on purpose. Each one replaces a C behavior that Go code could not use safely, or that does not fit Go’s ownership of resources.
| Area | What gobpfgo does | What it means for your code | Source |
|---|---|---|---|
| Detach and destroy | BpfLinkDetach, and Link.Detach in the layer, detach and release in one call: they disable the link, close its descriptors and remove the tracefs event it owns. BpfLinkDestroy then frees the Go value. In libbpf, bpf_link__detach keeps the descriptor, and bpf_link__destroy does the teardown. |
A link cannot be reused or updated after a detach. gobpfgo’s detach is libbpf’s destroy. | differences.md |
| Clone options | BpfProgramClone takes BpfProgLoadOpts, which has no BPF token, program BTF or function and line records. It returns EINVAL after a failed prepare or load, and for an fd array shorter than its count or than the slots the program’s kernel function calls name. |
A clone cannot use a token or BTF records of its own. Clone the programs of an object whose prepare succeeded. | differences.md |
| Nil and zero-value handles | A nil handle returns EINVAL where libbpf would dereference it and crash. Freeing a zero-value ring, user ring or perf buffer leaves descriptor 0 alone. |
Go code gets an error instead of a crash. | differences.md |
| struct_ops link update | BpfLinkUpdateMap returns EINVAL, before any system call, for a link that is not a struct_ops map’s BPF link. libbpf reads a map descriptor from whatever link it is given. |
A misuse that is undefined behavior in C gets an error. | differences.md |
| Custom section handler copies | A program keeps a copy of the section handler it matched at open, so it still loads and attaches through it after that handler is unregistered. A program that matched the fallback handler follows the fallback slot, as in libbpf. The registry is safe for concurrent use. | Unregistering a section handler does not change programs already opened. | differences.md |
| Tracing multi input checks | BpfProgramAttachTracingMulti takes an empty Go string as no pattern, and checks that len(Cookies) equals len(IDs). libbpf refuses a non-NULL empty pattern and trusts the cookie count. |
A wrong cookie count is refused, and an empty pattern with IDs attaches by ID where libbpf refuses it. |
differences.md |
| The initial-value slice after the load | The load maps the kernel’s .data, .bss, .rodata and .kconfig maps at a new address, so BpfMapInitialValue, and Map.InitialValue, return a new slice after the load: the live map, writable for .data and .bss and read-only for .rodata and .kconfig. libbpf maps them over the buffer it returned at open. |
Fetch the slice again after the load. Writing to one taken before the load changes nothing. | differences.md |
| Link-create option validation | The tcx, netkit and cgroup placement fields are kept apart, and nonzero fields that belong to another attach type’s member return EINVAL. In C, bpf_link_create_opts is a union, read as whichever member the attach type selects. |
A call that is valid C but sets fields of another member is refused. Nil or zero options behave the same in both. | differences.md |
Unsupported features
Section titled “Unsupported features”| Feature | What libbpf does | What gobpfgo does | Source |
|---|---|---|---|
| Skeleton generation and the generated loader | Opens and loads an object through the skeleton bpftool gen skeleton writes, and the light skeleton through a generated loader program. |
Provides neither. Open objects by path or from bytes with bpf.OpenFile or bpf.OpenMem, and find programs and maps by name. |
differences.md |
| Big-endian linker input | Links big-endian objects and writes the output in their byte order. | Refuses big-endian input with EOPNOTSUPP. gobpfgo runs on little-endian amd64 and arm64 only. |
differences.md |
| Split-BTF dedup | btf__dedup deduplicates BTF that has a base, such as module BTF. |
BtfDedup refuses BTF with a base with EOPNOTSUPP. Nothing in gobpfgo needs it yet: the linker’s BTF never has a base. |
differences.md |
| Fixed-address arenas | Creates the arena with its map_extra and maps it at that address. |
Creates the arena without it and maps it where the kernel places it, because a slice at a chosen address needs unsafe. Arena data, globals included, works as in libbpf, and a pinned arena is reused only when its map_extra is 0. |
differences.md |
perf_buffer__new_raw |
Hands its callback a raw perf_event_header pointer. |
Not provided, because raw pointers stay out of the API. The sample and lost callbacks of PerfBufferNew, and of bpf.NewPerfBuffer, cover the buffer. |
differences.md |
Scope: no cgo and no unsafe
Section titled “Scope: no cgo and no unsafe”gobpfgo is a Go library for Go callers. It has no C ABI and no C callers,
uses neither cgo nor the unsafe package, and runs on Linux only. BPF
programs stay in C, compiled by clang: gobpfgo is the loader, not a compiler,
and ships no BPF-side headers. The scope
row
of the canonical page and the README’s Not
supported
section state this scope.
Several rows above follow from it. Without unsafe, memory the kernel
shares reaches Go only as byte slices from mmap(2) at an address the kernel
chooses, which rules out fixed-address arenas and keeps the initial-value
slice from staying at one address across the load; and raw pointers, such as
the one perf_buffer__new_raw hands its callback, stay out of the API.
Without C unions, link-create options are separate Go fields, which is why
fields of the wrong attach type are refused.
Where to go next
Section titled “Where to go next”- API reference: the calls of both packages, by task.
- Kernel support: the oldest kernel for each feature, and the kernel configuration.
- The two layers: when to use the
bpflayer and when thelibbpfcore.
