bpftool icon indicating copy to clipboard operation
bpftool copied to clipboard

Failed to build bpftool from source

Open chenhengqi opened this issue 3 years ago • 7 comments

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);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

chenhengqi avatar Mar 30 '22 14:03 chenhengqi

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 :/.

qmonnet avatar Mar 30 '22 14:03 qmonnet

Yes, I tried it on 5.4 and 5.11.

chenhengqi avatar Mar 31 '22 00:03 chenhengqi

+1 5.11.0-49-generic

withlin avatar Apr 06 '22 07:04 withlin

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.

qmonnet avatar Apr 06 '22 14:04 qmonnet

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

chenhengqi avatar Apr 08 '22 02:04 chenhengqi

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

qmonnet avatar Apr 21 '22 16:04 qmonnet

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.

liusy58 avatar Jul 06 '22 03:07 liusy58

same issue. +1

adamzhoul avatar Nov 04 '22 09:11 adamzhoul

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]

qmonnet avatar May 12 '23 10:05 qmonnet

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.

qmonnet avatar Jul 11 '23 09:07 qmonnet