Skip to content

Commit a2a5172

Browse files
eddyz87anakryiko
authored andcommitted
libbpf: Allow version suffixes (___smth) for struct_ops types
E.g. allow the following struct_ops definitions: struct bpf_testmod_ops___v1 { int (*test)(void); }; struct bpf_testmod_ops___v2 { int (*test)(void); }; SEC(".struct_ops.link") struct bpf_testmod_ops___v1 a = { .test = ... } SEC(".struct_ops.link") struct bpf_testmod_ops___v2 b = { .test = ... } Where both bpf_testmod_ops__v1 and bpf_testmod_ops__v2 would be resolved as 'struct bpf_testmod_ops' from kernel BTF. Signed-off-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: David Vernet <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0f79bb8 commit a2a5172

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ static int find_btf_by_prefix_kind(const struct btf *btf, const char *prefix,
948948
const char *name, __u32 kind);
949949

950950
static int
951-
find_struct_ops_kern_types(struct bpf_object *obj, const char *tname,
951+
find_struct_ops_kern_types(struct bpf_object *obj, const char *tname_raw,
952952
struct module_btf **mod_btf,
953953
const struct btf_type **type, __u32 *type_id,
954954
const struct btf_type **vtype, __u32 *vtype_id,
@@ -958,8 +958,12 @@ find_struct_ops_kern_types(struct bpf_object *obj, const char *tname,
958958
const struct btf_member *kern_data_member;
959959
struct btf *btf;
960960
__s32 kern_vtype_id, kern_type_id;
961+
char tname[256];
961962
__u32 i;
962963

964+
snprintf(tname, sizeof(tname), "%.*s",
965+
(int)bpf_core_essential_name_len(tname_raw), tname_raw);
966+
963967
kern_type_id = find_ksym_btf_id(obj, tname, BTF_KIND_STRUCT,
964968
&btf, mod_btf);
965969
if (kern_type_id < 0) {

0 commit comments

Comments
 (0)