libbpf: Split BTF relocation
authorAlan Maguire <alan.maguire@oracle.com>
Thu, 13 Jun 2024 09:50:08 +0000 (10:50 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 17 Jun 2024 21:38:31 +0000 (14:38 -0700)
commit19e00c897d5031bed969dd79af28e899e038009f
tree8860aa5eba5bd79594bd6cc5b68d25c82c72d8d6
parenteb20e727c4343ad591cff2bef243590c77f62cf1
libbpf: Split BTF relocation

Map distilled base BTF type ids referenced in split BTF and their
references to the base BTF passed in, and if the mapping succeeds,
reparent the split BTF to the base BTF.

Relocation is done by first verifying that distilled base BTF
only consists of named INT, FLOAT, ENUM, FWD, STRUCT and
UNION kinds; then we sort these to speed lookups.  Once sorted,
the base BTF is iterated, and for each relevant kind we check
for an equivalent in distilled base BTF.  When found, the
mapping from distilled -> base BTF id and string offset is recorded.
In establishing mappings, we need to ensure we check STRUCT/UNION
size when the STRUCT/UNION is embedded in a split BTF STRUCT/UNION,
and when duplicate names exist for the same STRUCT/UNION.  Otherwise
size is ignored in matching STRUCT/UNIONs.

Once all mappings are established, we can update type ids
and string offsets in split BTF and reparent it to the new base.

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20240613095014.357981-4-alan.maguire@oracle.com
tools/lib/bpf/Build
tools/lib/bpf/btf.c
tools/lib/bpf/btf.h
tools/lib/bpf/btf_relocate.c [new file with mode: 0644]
tools/lib/bpf/libbpf.map
tools/lib/bpf/libbpf_internal.h