ebpf
ebpf copied to clipboard
Marshal BTF from `btf.Type`
Over the past few months, while working on per-instruction metadata, we've identified the need for marshaling valid BTF blobs based on btf.Types.
A few use cases:
- caller-provided
btf.Types for map keys/values, for pretty-printing dumps and creating valid StructOps maps - caller-provided FuncInfo (e.g.
Instruction.WithFunc(f *btf.Func)) for manually assembling (and modifying) programs with bpf-to-bpf calls - caller-provided source information (e.g.
Instruction.WithSource(s fmt.Stringer)), for adding comments or other info on instructions - .. probably a few things I haven't thought of
Optimizations/cleanups:
- BTF blobs accompanying maps can consist of just 2 (best case) types, removing the need for the BTF handle cache.
- Loading the complete BTF blob from larger ELFs is no longer required. For programs, this only needs to contain types+strings of FuncInfos and strings from LineInfos.
This should also make fixing https://github.com/cilium/ebpf/issues/344 possible.