{"record":{"id":"3e9df54c241e3357","repo":"cilium/cilium","slug":"loading-marshaled-btf-w","errorCode":null,"errorMessage":"loading marshaled BTF: %w","messagePattern":"loading marshaled BTF: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/dpgen/util.go","lineNumber":266,"sourceCode":"\t// declaration, so it needs to be queryable by name in the resulting BTF blob.\n\tif added != nil {\n\t\tadded.Insert(name)\n\t}\n\treturn nil\n}\n\n// marshalSorted marshals the BTF types in the builder into a byte slice,\n// ensuring the types are sorted by name in the resulting BTF blob for\n// more deterministic output.\nfunc marshalSorted(bb *btf.Builder) ([]byte, error) {\n\tb, err := bb.Marshal(nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"marshaling BTF before sort: %w\", err)\n\t}\n\n\tspec, err := btf.LoadSpecFromReader(bytes.NewReader(b))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"loading marshaled BTF: %w\", err)\n\t}\n\n\tvar types []btf.Type\n\tfor t, err := range spec.All() {\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"iterating BTF types: %w\", err)\n\t\t}\n\n\t\t// Can't sort anonymous types. These are typically referred to by named\n\t\t// types, so they will be included by dependency when adding named types to\n\t\t// the builder.\n\t\tif t.TypeName() == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\ttypes = append(types, t)\n\t}\n","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/tools/dpgen/util.go#L248-L284","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"b, err := marshalSorted(bb)\nif err != nil {\n    if strings.Contains(err.Error(), \"loading marshaled BTF\") {\n        log.Printf(\"BTF round-trip parse failed (library bug or feature mismatch): %v\", err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["bpf","btf","serialization"],"backgroundTag":"btf-parse-failed","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}