Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to build bpftool from source #17

Closed
chenhengqi opened this issue Mar 30, 2022 · 10 comments · Fixed by #110
Closed

Failed to build bpftool from source #17

chenhengqi opened this issue Mar 30, 2022 · 10 comments · Fixed by #110
Labels
bug Something isn't working

Comments

@chenhengqi
Copy link
Contributor

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);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@qmonnet
Copy link
Member

qmonnet commented Mar 30, 2022

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

@chenhengqi
Copy link
Contributor Author

Yes, I tried it on 5.4 and 5.11.

@withlin
Copy link

withlin commented Apr 6, 2022

+1 5.11.0-49-generic

@qmonnet
Copy link
Member

qmonnet commented Apr 6, 2022

Thanks for the reports!

Since d97300d, 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.

@chenhengqi
Copy link
Contributor Author

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

@qmonnet
Copy link
Member

qmonnet commented Apr 21, 2022

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

@liusy58
Copy link

liusy58 commented Jul 6, 2022

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.

@adamzhoul
Copy link

same issue. +1

@qmonnet qmonnet added the bug Something isn't working label Jan 8, 2023
@qmonnet
Copy link
Member

qmonnet commented May 12, 2023

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
Copy link
Member

qmonnet commented Jul 11, 2023

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.

mtardy added a commit to cilium/tetragon that referenced this issue Jan 12, 2024
Some previous version failed to build on old kernels, see issue
libbpf/bpftool#17 for more information.

Signed-off-by: Mahe Tardy <[email protected]>
mtardy added a commit to cilium/tetragon that referenced this issue Jan 12, 2024
Previous version failed to build on old kernels, see libbpf/bpftool#17
for more information.

Signed-off-by: Mahe Tardy <[email protected]>
mtardy added a commit to cilium/tetragon that referenced this issue Jan 15, 2024
Previous version failed to build on old kernels, see libbpf/bpftool#17
for more information.

Signed-off-by: Mahe Tardy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants