Skip to contentSkip to conversation

use valid btf in bpf_program__set_attach_target(prog, 0, ...);

PATCH New Luigi Rizzo 1 participant 1 message Oct 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 use valid btf in bpf_program__set_attach_target(prog, 0, ...);

bpf_program__set_attach_target() will always fail with fd=0 (attach to a kernel symbol) because obj->btf_vmlinux is NULL and there is no way to set it.

Fix this by using libbpf_find_vmlinux_btf_id()

(on a side note: it is unclear whether btf_vmlinux is meant to be just temporary storage for use in bpf_object__load_xattr(), or a property of bpf_object, in which case it could be initialuzed opportunistically, and properly released in bpf_object__close() ).

---
 tools/lib/bpf/libbpf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/lib/bpf/libbpf.c +2 -3
index a4f55f8a460d..33bf102259dd 100644
@@ -10353,9 +10353,8 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
 		btf_id = libbpf_find_prog_btf_id(attach_func_name,
 						 attach_prog_fd);
 	else
-		btf_id = __find_vmlinux_btf_id(prog->obj->btf_vmlinux,
-					       attach_func_name,
-					       prog->expected_attach_type);
+		btf_id = libbpf_find_vmlinux_btf_id(attach_func_name,
+						    prog->expected_attach_type);
 
 	if (btf_id < 0)
 		return btf_id;
Signature · 1 line
2.28.0.806.g8561365e88-goog