ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

Marshal BTF from `btf.Type`

Open ti-mo opened this issue 3 years ago • 0 comments

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.

ti-mo avatar Mar 31 '22 20:03 ti-mo