diff options
author | Daniel Müller <deso@posteo.net> | 2022-06-28 16:01:21 +0000 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2022-07-05 21:14:25 -0700 |
commit | ec6209c8d42f815bc3bef10934637ca92114cd1b (patch) | |
tree | 9366cf9645bdc5273cb8e93e0a109fe3f63d65a7 /tools/lib/bpf/relo_core.h | |
parent | bpftool: Honor BPF_CORE_TYPE_MATCHES relocation (diff) | |
download | linux-dev-ec6209c8d42f815bc3bef10934637ca92114cd1b.tar.xz linux-dev-ec6209c8d42f815bc3bef10934637ca92114cd1b.zip |
bpf, libbpf: Add type match support
This patch adds support for the proposed type match relation to
relo_core where it is shared between userspace and kernel. It plumbs
through both kernel-side and libbpf-side support.
The matching relation is defined as follows (copy from source):
- modifiers and typedefs are stripped (and, hence, effectively ignored)
- generally speaking types need to be of same kind (struct vs. struct, union
vs. union, etc.)
- exceptions are struct/union behind a pointer which could also match a
forward declaration of a struct or union, respectively, and enum vs.
enum64 (see below)
Then, depending on type:
- integers:
- match if size and signedness match
- arrays & pointers:
- target types are recursively matched
- structs & unions:
- local members need to exist in target with the same name
- for each member we recursively check match unless it is already behind a
pointer, in which case we only check matching names and compatible kind
- enums:
- local variants have to have a match in target by symbolic name (but not
numeric value)
- size has to match (but enum may match enum64 and vice versa)
- function pointers:
- number and position of arguments in local type has to match target
- for each argument and the return value we recursively check match
Signed-off-by: Daniel Müller <deso@posteo.net>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220628160127.607834-5-deso@posteo.net
Diffstat (limited to 'tools/lib/bpf/relo_core.h')
-rw-r--r-- | tools/lib/bpf/relo_core.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/lib/bpf/relo_core.h b/tools/lib/bpf/relo_core.h index 3fd3842d4230..1c0566daf8e8 100644 --- a/tools/lib/bpf/relo_core.h +++ b/tools/lib/bpf/relo_core.h @@ -72,6 +72,10 @@ int __bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id, const struct btf *targ_btf, __u32 targ_id, int level); int bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id, const struct btf *targ_btf, __u32 targ_id); +int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const struct btf *targ_btf, + __u32 targ_id, bool behind_ptr, int level); +int bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const struct btf *targ_btf, + __u32 targ_id); size_t bpf_core_essential_name_len(const char *name); |