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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 explicitly calling libbpf_find_kernel_btf() in the function.

Signed-off-by: Luigi Rizzo <lrizzo@xxxxxxxxxx>
---
 tools/lib/bpf/libbpf.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index a4f55f8a460d..3a63db86666f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -10352,10 +10352,13 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
 	if (attach_prog_fd)
 		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,
+	else {
+		struct btf *btf = libbpf_find_kernel_btf();
+
+		btf_id = __find_vmlinux_btf_id(btf, attach_func_name,
 					       prog->expected_attach_type);
+		btf__free(btf);
+	}
 
 	if (btf_id < 0)
 		return btf_id;
-- 
2.28.0.806.g8561365e88-goog




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux