cilium/cilium · error
loading marshaled BTF: %w
Error message
loading marshaled BTF: %w
What it means
marshalSorted re-loads the bytes it just marshaled via btf.LoadSpecFromReader to obtain a spec whose types it can sort. If the freshly marshaled BTF cannot be parsed back, the error is wrapped with this message. Since the input bytes come straight from bb.Marshal, a failure here indicates the produced blob is malformed (or a library bug).
Source
Thrown at tools/dpgen/util.go:266
// declaration, so it needs to be queryable by name in the resulting BTF blob.
if added != nil {
added.Insert(name)
}
return nil
}
// marshalSorted marshals the BTF types in the builder into a byte slice,
// ensuring the types are sorted by name in the resulting BTF blob for
// more deterministic output.
func marshalSorted(bb *btf.Builder) ([]byte, error) {
b, err := bb.Marshal(nil, nil)
if err != nil {
return nil, fmt.Errorf("marshaling BTF before sort: %w", err)
}
spec, err := btf.LoadSpecFromReader(bytes.NewReader(b))
if err != nil {
return nil, fmt.Errorf("loading marshaled BTF: %w", err)
}
var types []btf.Type
for t, err := range spec.All() {
if err != nil {
return nil, fmt.Errorf("iterating BTF types: %w", err)
}
// Can't sort anonymous types. These are typically referred to by named
// types, so they will be included by dependency when adding named types to
// the builder.
if t.TypeName() == "" {
continue
}
types = append(types, t)
}
View on GitHub (pinned to ac7b90affa)
Solutions
- Verify the cilium/ebpf version is consistent (no mixed versions of vendor packages).
- Check the wrapped LoadSpecFromReader error for which BTF feature/offset failed.
- Try upgrading cilium/ebpf so marshal and parse support the same BTF features.
- As a workaround, dump the marshaled bytes with bpftool btf to inspect the blob.
Defensive patterns
Strategy: try-catch
Try / catch
b, err := marshalSorted(bb)
if err != nil {
if strings.Contains(err.Error(), "loading marshaled BTF") {
log.Printf("BTF round-trip parse failed (library bug or feature mismatch): %v", err)
}
return err
} Prevention
- Pin a single cilium/ebpf version across the module (go mod tidy / vendor check)
- Avoid mixed vendored copies of cilium/ebpf packages
- Verify round-trip (marshal then LoadSpecFromReader) in unit tests
- Report marshal/parse round-trip failures upstream as library bugs
When it happens
Trigger: Marshal or runMaps calls marshalSorted; bb.Marshal succeeded but btf.LoadSpecFromReader on the in-memory blob returns an error (corrupt split-BTF blob, incompatible BTF features the parser can't round-trip).
Common situations: BTF features (e.g. enum64, kind-specific encodings) written by the builder cannot be re-parsed by the same library version — usually signals a cilium/ebpf version mismatch or bug; memory blob truncated by an intermediate writer.
Related errors
- adding type %s: %w
- marshaling BTF before sort: %w
- iterating BTF types: %w
- creating BTF builder: %w
- cannot parse BTF debug info %s: %w
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/3e9df54c241e3357.
Report an issue: GitHub.