bpftool: Implement btfgen_get_btf()
authorMauricio Vásquez <mauricio@kinvolk.io>
Tue, 15 Feb 2022 22:58:54 +0000 (17:58 -0500)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 16 Feb 2022 18:10:42 +0000 (10:10 -0800)
commitdc695516b6f5cb322b95de7ef3a6ec1db707ff8b
treed06d94211dc7939318ea370d5ca7eefeb988d8e0
parenta9caaba399f9cff34c6bffa1b1fd673d3d6043a0
bpftool: Implement btfgen_get_btf()

The last part of the BTFGen algorithm is to create a new BTF object with
all the types that were recorded in the previous steps.

This function performs two different steps:
1. Add the types to the new BTF object by using btf__add_type(). Some
special logic around struct and unions is implemented to only add the
members that are really used in the field-based relocations. The type
ID on the new and old BTF objects is stored on a map.
2. Fix all the type IDs on the new BTF object by using the IDs saved in
the previous step.

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>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220215225856.671072-6-mauricio@kinvolk.io
tools/bpf/bpftool/gen.c