cilium/cilium · error
adding key type: %w
Error message
adding key type: %w
What it means
addMapKV registers a map's BTF key and value types with a btf.Builder used by dpgen's -maps/-types commands. This error wraps a failure while adding the key type (spec.Key) to the builder — e.g. the BTF type could not be resolved or encoded. Callers runMaps and runTypes further wrap it with the map name.
Source
Thrown at tools/dpgen/util.go:211
}
if a.ValueSize != b.ValueSize {
return fmt.Errorf("value size mismatch: %d != %d", a.ValueSize, b.ValueSize)
}
if a.MaxEntries != b.MaxEntries {
return fmt.Errorf("max entries mismatch: %d != %d", a.MaxEntries, b.MaxEntries)
}
return nil
}
// addMapKV adds the BTF types of the map's key and value to the given BTF
// builder.
func addMapKV(bb *btf.Builder, added *set.Set[string], spec *ebpf.MapSpec) error {
if spec.Key != nil {
if err := addType(bb, added, spec.Key); err != nil {
return fmt.Errorf("adding key type: %w", err)
}
}
if spec.Value != nil {
if err := addType(bb, added, spec.Value); err != nil {
return fmt.Errorf("adding value type: %w", err)
}
}
return nil
}
// addVariableType adds the BTF type of the variable to the given BTF builder.
func addVariableType(bb *btf.Builder, added *set.Set[string], v *ebpf.VariableSpec) error {
if v.Type == nil || v.Type.Type == nil {
return fmt.Errorf("no BTF type information")
}
return addType(bb, added, v.Type.Type)
}View on GitHub (pinned to ac7b90affa)
Solutions
- Recompile the BPF objects with BTF enabled (clang -g / -target bpf with BTF, not stripped) and rerun dpgen.
- Inspect the wrapped inner error (strip this frame via errors.Unwrap) to see which BTF construct failed; adjust the C type or upgrade cilium/ebpf.
- Check for clang/LLVM version incompatibilities and build with the toolchain version cilium requires.
- Verify the object with `bpftool btf dump file <obj>` to confirm key BTF is present and valid.
Example fix
// before: compiling without BTF clang -target bpf -c prog.c -o prog.o // after clang -target bpf -g -c prog.c -o prog.o
Defensive patterns
Strategy: validation
Validate before calling
f, err := os.Open(objPath)
if err != nil { return err }
rd, err := elf.NewFile(f)
if err != nil { return err }
if rd.Section(".BTF") == nil {
return fmt.Errorf("%s has no .BTF section; rebuild with clang -g", objPath)
} Try / catch
if err := runTypes(cmd, args); err != nil {
if strings.Contains(err.Error(), "adding key type:") {
// verify object BTF with bpftool btf dump and rebuild with -g
}
} Prevention
- Always compile BPF objects with -g so BTF is emitted
- Use the clang/LLVM version mandated by cilium to avoid unparsable BTF
- Sanity-check objects with `bpftool btf dump file <o>` before running dpgen
When it happens
Trigger: Running `dpgen -types` or `dpgen -maps` over ELF objects whose map has a Key BTF type that the builder cannot add (missing/corrupt BTF in the object, unsupported type constructs, deduplication conflicts).
Common situations: Objects compiled without BTF or with stripped BTF sections; clang versions producing BTF constructs the cilium/ebpf library can't parse; duplicate type names across objects clashing under the deduplicating builder.
Related errors
- program %s has no function metadata
- program %s has no tail call slot
- getting tail call slot: %w
- removing unused tail calls: %w
- generating config struct: %w
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/d4ce8884833d2901.
Report an issue: GitHub.