Skip to content

Commit fd5db40

Browse files
Luigi Rizzokernel-patches-bot
authored andcommitted
bpf, libbpf: use valid btf in bpf_program__set_attach_target
bpf_program__set_attach_target(prog, fd, ...) will always fail when fd = 0 (attach to a kernel symbol) because obj->btf_vmlinux is NULL and there is no way to set it (at the moment btf_vmlinux is meant to be temporary storage for use in bpf_object__load_xattr()). Fix this by using libbpf_find_vmlinux_btf_id(). At some point we may want to opportunistically cache btf_vmlinux so it can be reused with multiple programs. Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Luigi Rizzo <[email protected]>
1 parent 6f80a28 commit fd5db40

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9129,9 +9129,8 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
91299129
btf_id = libbpf_find_prog_btf_id(attach_func_name,
91309130
attach_prog_fd);
91319131
else
9132-
btf_id = __find_vmlinux_btf_id(prog->obj->btf_vmlinux,
9133-
attach_func_name,
9134-
prog->expected_attach_type);
9132+
btf_id = libbpf_find_vmlinux_btf_id(attach_func_name,
9133+
prog->expected_attach_type);
91359134

91369135
if (btf_id < 0)
91379136
return btf_id;

0 commit comments

Comments
 (0)