libbpf,bpf: Share BTF relocate-related code with kernel
authorAlan Maguire <alan.maguire@oracle.com>
Thu, 20 Jun 2024 09:17:31 +0000 (10:17 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 21 Jun 2024 21:45:07 +0000 (14:45 -0700)
commit8646db238997df36c6ad71a9d7e0b52ceee221b2
tree3968d9444fab7f563fc71f78ac0fb2fd5df188e0
parente7ac331b30555cf1a0826784a346f36dbf800451
libbpf,bpf: Share BTF relocate-related code with kernel

Share relocation implementation with the kernel.  As part of this,
we also need the type/string iteration functions so also share
btf_iter.c file. Relocation code in kernel and userspace is identical
save for the impementation of the reparenting of split BTF to the
relocated base BTF and retrieval of the BTF header from "struct btf";
these small functions need separate user-space and kernel implementations
for the separate "struct btf"s they operate upon.

One other wrinkle on the kernel side is we have to map .BTF.ids in
modules as they were generated with the type ids used at BTF encoding
time. btf_relocate() optionally returns an array mapping from old BTF
ids to relocated ids, so we use that to fix up these references where
needed for kfuncs.

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/20240620091733.1967885-5-alan.maguire@oracle.com
include/linux/btf.h
kernel/bpf/Makefile
kernel/bpf/btf.c
tools/lib/bpf/btf_iter.c
tools/lib/bpf/btf_relocate.c