Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: add bpf_core_type_matches() helper macro

This patch finalizes support for the proposed type match relation in libbpf by
adding bpf_core_type_matches() macro which emits TYPE_MATCH relocation.

Clang support for this relocation was added in [0].

[0] https://reviews.llvm.org/D126838

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-7-deso@posteo.net¬

+10
+10
tools/lib/bpf/bpf_core_read.h
··· 185 185 __builtin_preserve_type_info(*(typeof(type) *)0, BPF_TYPE_EXISTS) 186 186 187 187 /* 188 + * Convenience macro to check that provided named type 189 + * (struct/union/enum/typedef) "matches" that in a target kernel. 190 + * Returns: 191 + * 1, if the type matches in the target kernel's BTF; 192 + * 0, if the type does not match any in the target kernel 193 + */ 194 + #define bpf_core_type_matches(type) \ 195 + __builtin_preserve_type_info(*(typeof(type) *)0, BPF_TYPE_MATCHES) 196 + 197 + /* 188 198 * Convenience macro to get the byte size of a provided named type 189 199 * (struct/union/enum/typedef) in a target kernel. 190 200 * Returns: