Skip to content

Commit

Permalink
bpftool: Implement btfgen
Browse files Browse the repository at this point in the history
The BTFGen's goal is to produce a BTF file that contains **only** the
information that is needed by an eBPF program. This algorithm does a
first step collecting the types involved for each relocation present on
the object and "marking" them as needed. Types are collected in
different ways according to the type relocation, for field based
relocations only the union and structures members involved are
considered, for type based relocations the whole types are added, enum
field relocations are not supported in this iteration yet.

A second step generates a BTF file from the "marked" types. This step
accesses the original BTF file extracting the types and their members
that were "marked" as needed in the first step.

This command is implemented under the "gen" command in bpftool and the
syntax is the following:

$ bpftool gen btf INPUT OUTPUT OBJECT(S)

INPUT can be either a single BTF file or a folder containing BTF files,
when it's a folder, a BTF file is generated for each BTF file contained
in this folder. OUTPUT is the file (or folder) where generated files are
stored and OBJECT(S) is the list of bpf objects we want to generate the
BTF file(s) for (each generated BTF file contains all the types needed
by all the objects).

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
Signed-off-by: Rafael David Tinoco <rafael.tinoco@aquasec.com>
Signed-off-by: Lorenzo Fontana <lorenzo.fontana@elastic.co>
Signed-off-by: Leonardo Di Donato <leonardo.didonato@elastic.co>
  • Loading branch information
mauriciovasquezbernal committed Dec 20, 2021
1 parent a8df891 commit 02c93d4
Showing 1 changed file with 892 additions and 0 deletions.
Loading

0 comments on commit 02c93d4

Please sign in to comment.