Failed to build bpftool from source
clang \
-I. \
-I/home/ubuntu/bpf/bpftool/include/uapi/ \
-I/home/ubuntu/bpf/bpftool/src/bootstrap/libbpf/include \
-g -O2 -Wall -target bpf -c skeleton/pid_iter.bpf.c -o pid_iter.bpf.o
skeleton/pid_iter.bpf.c:47:14: error: incomplete definition of type 'struct bpf_perf_link'
perf_link = container_of(link, struct bpf_perf_link, link);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi, thanks for the report! What's your kernel version, please? I guess it is lower than 5.15? It seems that commit cbdaf71f7e65 introduced requirements for recent structures to be present in kernel's BTF when compiling :/.
Yes, I tried it on 5.4 and 5.11.
+1 5.11.0-49-generic
Thanks for the reports!
Since https://github.com/libbpf/bpftool/commit/d97300d3565e99d9fea06d1875935234796f4096, kernel 5.15 is a requirement for building bpftool with all its features. The definition may also be missing if the kernel of the host has not been compiled with CONFIG_PERF_EVENTS.
Workarounds:
- Work with an older version (the latest release should not include this commit and should compile fine).
- Disable the “skeletons” feature (
feature-clang-bpf-co-re), but there's currently no clean way to do this (I'm planning to add Makefile options for that when I have some cycles) so you'll have to edit the Makefile manually.
I'll try to submit a fix upstream.
diff --git a/src/Makefile b/src/Makefile
index bffd4e7..5fc927e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -125,7 +125,7 @@ all: $(OUTPUT)bpftool
BFD_SRCS = jit_disasm.c
-SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
+SRCS = $(filter-out $(BFD_SRCS) pids.c,$(wildcard *.c))
ifeq ($(feature-libbfd),1)
LIBS += -lbfd -ldl -lopcodes
I haven't managed to find a fix myself (I was missing the ...___local change), but I believe that the patch currently discussed on the mailing list should address the issue.
https://lore.kernel.org/bpf/[email protected]/T/#u
diff --git a/src/Makefile b/src/Makefile index bffd4e7..5fc927e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -125,7 +125,7 @@ all: $(OUTPUT)bpftool BFD_SRCS = jit_disasm.c -SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) +SRCS = $(filter-out $(BFD_SRCS) pids.c,$(wildcard *.c)) ifeq ($(feature-libbfd),1) LIBS += -lbfd -ldl -lopcodes
This can compile successfully but everytime I execute sudo bpftool prog show, segmentation fault pops up.
same issue. +1
I re-submitted the patches today (at https://lore.kernel.org/bpf/[email protected]/t/#u).
[EDIT: v2 at https://lore.kernel.org/bpf/[email protected]/t/#u]
Apologies, this had taken more time than I expected - or than it should have. At last, we have the fix merged in bpf-next. I'll pull it in this repo at the next sync.