Closed NobinPegasus closed 8 months ago
Hi, this seems to be an issue with libbpf's compilation. Do you have libelf installed (for example, package libelf-dev
on Ubuntu)? What's the output of make V=1
?
@qmonnet Yes I've libelf-dev
installed.
Output of make V=1:
pegasus@pegasus:~/Documents/eBPF/bpftool/src$ make V=1
Makefile.feature:34: Probing: feature-clang-bpf-co-re
Makefile.feature:35: printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo = {};' | clang -g -target bpf -S -o - -x c - | grep -q BTF_KIND_VAR && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
/bin/sh: 1: clang: not found
result: 0
Makefile.feature:54: Probing: feature-libbfd
Makefile.feature:55: printf '%b\n' '#include <bfd.h>\n' 'int main(void) {' ' bfd_demangle(0, 0, 0);' ' return 0;' '}' | cc -Wall -Werror -x c - -lbfd -ldl -o /dev/null >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:86: Probing: feature-disassembler-four-args
Makefile.feature:87: printf '%b\n' '#include <dis-asm.h>\n' 'int main(void) {' ' disassembler((enum bfd_architecture)0, 0, 0, NULL);' ' return 0;' '}' | cc -Wall -Werror -x c - -lbfd -lopcodes -S -o - >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:100: Probing: feature-disassembler-styled
Makefile.feature:101: printf '%b\n' '#include <dis-asm.h>\n' 'int main(void) {' ' init_disassemble_info(NULL, 0, NULL, NULL);' ' return 0;' '}' | cc -Wall -Werror -x c - -lbfd -lopcodes -S -o - >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:120: Probing: feature-libcap
Makefile.feature:121: printf '%b\n' '#include <sys/capability.h>\n' 'int main(void) {' ' cap_free(0);' ' return 0;' '}' | cc -Wall -Werror -x c - -lcap -S -o - >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:158: Probing: feature-llvm
Makefile.feature:159: printf '%b\n' '#include <llvm-c/Core.h>\n' '#include <llvm-c/TargetMachine.h>\n' 'int main(void) {' ' char *triple = LLVMNormalizeTargetTriple("");' ' LLVMDisposeMessage(triple);' ' return 0;' '}' | cc -I/usr/lib/llvm-15/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/usr/lib/llvm-15/lib -Wall -Werror -x c - -lLLVM-15 -o /dev/null >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
... libbfd: [ on ]
... clang-bpf-co-re: [ OFF ]
... llvm: [ on ]
... libcap: [ on ]
make -C /home/pegasus/Documents/eBPF/bpftool/libbpf/src OBJDIR=/home/pegasus/Documents/eBPF/bpftool/src/libbpf \
PREFIX=/home/pegasus/Documents/eBPF/bpftool/src/libbpf /home/pegasus/Documents/eBPF/bpftool/src/libbpf/libbpf.a install_headers
make[1]: Entering directory '/home/pegasus/Documents/eBPF/bpftool/libbpf/src'
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c usdt.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/usdt.o
usdt.c:572:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
572 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
| ^~~~~~~~~
| GElf_Shdr
usdt.c: In function ‘collect_usdt_targets’:
usdt.c:589:9: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
589 | GElf_Nhdr nhdr;
| ^~~~~~~~~
| GElf_Shdr
usdt.c:621:23: error: implicit declaration of function ‘gelf_getnote’; did you mean ‘gelf_getsym’? [-Werror=implicit-function-declaration]
621 | while ((off = gelf_getnote(data, off, &nhdr, &name_off, &desc_off)) > 0) {
| ^~~~~~~~~~~~
| gelf_getsym
usdt.c:627:23: error: implicit declaration of function ‘parse_usdt_note’; did you mean ‘parse_usdt_spec’? [-Werror=implicit-function-declaration]
627 | err = parse_usdt_note(elf, path, &nhdr, data->d_buf, name_off, desc_off, ¬e);
| ^~~~~~~~~~~~~~~
| parse_usdt_spec
usdt.c: At top level:
usdt.c:1133:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
1133 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
| ^~~~~~~~~
| GElf_Shdr
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: all warnings being treated as errors
make[1]: *** [Makefile:134: /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/usdt.o] Error 1
make[1]: Leaving directory '/home/pegasus/Documents/eBPF/bpftool/libbpf/src'
make: *** [Makefile:44: /home/pegasus/Documents/eBPF/bpftool/src/libbpf/libbpf.a] Error 2
pegasus@pegasus:~$ uname -a
Linux pegasus 6.4.0-060400-generic #202306271339 SMP PREEMPT_DYNAMIC Tue Jun 27 14:26:34 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
pegasus@pegasus:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 23.04"
NAME="Ubuntu"
VERSION_ID="23.04"
VERSION="23.04 (Lunar Lobster)"
VERSION_CODENAME=lunar
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=lunar
LOGO=ubuntu-logo
I've tried to reproduce in an Ubuntu 23.04 container, but it compiled just fine for me.
What are your gcc and libelf-dev versions? (gcc --version
, apt-cache policy libelf-dev
, I get 12.3.0 and 0.188-2.1, respectively).
I suppose you get the same error if you try to compile libbpf on its own?
Running CFLAGS=-H make
I see that I've got the libelf headers pulled during compilation, is this the case for you as well?
[...]
CC /tmp/bpftool/src/libbpf/staticobjs/usdt.o
[...]
/usr/include/libelf.h
[...]
.. /usr/include/elf.h
. /usr/include/gelf.h
gcc (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
pegasus@pegasus:~$ apt-cache policy libelf-dev
libelf-dev:
Installed: 0.188-2.1
Candidate: 0.188-2.1
Version table:
*** 0.188-2.1 500
500 http://bd.archive.ubuntu.com/ubuntu lunar/main amd64 Packages
100 /var/lib/dpkg/status
0.176-1.1build1 500
500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
pegasus@pegasus:~/Documents/eBPF/learning-ebpf/libbpf/src$ sudo make
pegasus@pegasus:~/Documents/eBPF/learning-ebpf/libbpf/src$ sudo make install
INSTALL bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h bpf_helpers.h bpf_helper_defs.h bpf_tracing.h bpf_endian.h bpf_core_read.h skel_internal.h libbpf_version.h usdt.bpf.h
INSTALL ./libbpf.pc
INSTALL ./libbpf.a ./libbpf.so ./libbpf.so.1 ./libbpf.so.1.0.1
pegasus@pegasus:~/Documents/eBPF/learning-ebpf/libbpf/src$ sudo CFLAGS=-H make
pegasus@pegasus:~/Documents/eBPF/learning-ebpf/libbpf/src$
Your sudo make
doesn't seem to build anything, it looks like the library was built already - please try make clean
before, or make -B
to force-rebuild.
It's weird if libbpf builds on its own but not with bpftool, the commands should be the same. Could you compare the output of make -B V=1
in bpftool, and make -B V=1
in libbpf, regarding usdt.o? In my case I get the same thing (only with absolute vs. relative paths):
qmonnet:~/bpftool/src$ make -B V=1
...
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -c usdt.c -o /home/qmonnet/bpftool/src/libbpf/staticobjs/usdt.o
...
qmonnet:~/libbpf/src$ make -B V=1
...
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -c usdt.c -o staticobjs/usdt.o
...
Any particular reason why you build with sudo
?
pegasus@pegasus:~/Documents/eBPF/learning-ebpf/libbpf/src$ make -B V=1
mkdir -p staticobjs
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c bpf.c -o staticobjs/bpf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c btf.c -o staticobjs/btf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c libbpf.c -o staticobjs/libbpf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c libbpf_errno.c -o staticobjs/libbpf_errno.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c netlink.c -o staticobjs/netlink.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c nlattr.c -o staticobjs/nlattr.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c str_error.c -o staticobjs/str_error.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c libbpf_probes.c -o staticobjs/libbpf_probes.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c bpf_prog_linfo.c -o staticobjs/bpf_prog_linfo.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c btf_dump.c -o staticobjs/btf_dump.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c hashmap.c -o staticobjs/hashmap.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c ringbuf.c -o staticobjs/ringbuf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c strset.c -o staticobjs/strset.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c linker.c -o staticobjs/linker.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c gen_loader.c -o staticobjs/gen_loader.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c relo_core.c -o staticobjs/relo_core.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c usdt.c -o staticobjs/usdt.o
usdt.c:566:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
566 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
| ^~~~~~~~~
| GElf_Shdr
usdt.c: In function ‘collect_usdt_targets’:
usdt.c:583:9: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
583 | GElf_Nhdr nhdr;
| ^~~~~~~~~
| GElf_Shdr
usdt.c:615:23: error: implicit declaration of function ‘gelf_getnote’; did you mean ‘gelf_getsym’? [-Werror=implicit-function-declaration]
615 | while ((off = gelf_getnote(data, off, &nhdr, &name_off, &desc_off)) > 0) {
| ^~~~~~~~~~~~
| gelf_getsym
usdt.c:621:23: error: implicit declaration of function ‘parse_usdt_note’; did you mean ‘parse_usdt_spec’? [-Werror=implicit-function-declaration]
621 | err = parse_usdt_note(elf, path, &nhdr, data->d_buf, name_off, desc_off, ¬e);
| ^~~~~~~~~~~~~~~
| parse_usdt_spec
usdt.c: At top level:
usdt.c:1093:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
1093 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
| ^~~~~~~~~
| GElf_Shdr
cc1: all warnings being treated as errors
make: *** [Makefile:130: staticobjs/usdt.o] Error 1
pegasus@pegasus:~/Documents/eBPF/bpftool/src$ make -B V=1
Makefile.feature:34: Probing: feature-clang-bpf-co-re
Makefile.feature:35: printf '%s\n' 'struct s { int i; } __attribute__((preserve_access_index)); struct s foo = {};' | clang -g -target bpf -S -o - -x c - | grep -q BTF_KIND_VAR && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
/bin/sh: 1: clang: not found
result: 0
Makefile.feature:54: Probing: feature-libbfd
Makefile.feature:55: printf '%b\n' '#include <bfd.h>\n' 'int main(void) {' ' bfd_demangle(0, 0, 0);' ' return 0;' '}' | cc -Wall -Werror -x c - -lbfd -ldl -o /dev/null >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:86: Probing: feature-disassembler-four-args
Makefile.feature:87: printf '%b\n' '#include <dis-asm.h>\n' 'int main(void) {' ' disassembler((enum bfd_architecture)0, 0, 0, NULL);' ' return 0;' '}' | cc -Wall -Werror -x c - -lbfd -lopcodes -S -o - >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:100: Probing: feature-disassembler-styled
Makefile.feature:101: printf '%b\n' '#include <dis-asm.h>\n' 'int main(void) {' ' init_disassemble_info(NULL, 0, NULL, NULL);' ' return 0;' '}' | cc -Wall -Werror -x c - -lbfd -lopcodes -S -o - >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:120: Probing: feature-libcap
Makefile.feature:121: printf '%b\n' '#include <sys/capability.h>\n' 'int main(void) {' ' cap_free(0);' ' return 0;' '}' | cc -Wall -Werror -x c - -lcap -S -o - >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
Makefile.feature:158: Probing: feature-llvm
Makefile.feature:159: printf '%b\n' '#include <llvm-c/Core.h>\n' '#include <llvm-c/TargetMachine.h>\n' 'int main(void) {' ' char *triple = LLVMNormalizeTargetTriple("");' ' LLVMDisposeMessage(triple);' ' return 0;' '}' | cc -I/usr/lib/llvm-15/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/usr/lib/llvm-15/lib -Wall -Werror -x c - -lLLVM-15 -o /dev/null >/dev/null && (echo 1 && >&2 echo result: 1) || (echo 0 && >&2 echo result: 0)
result: 1
... libbfd: [ on ]
... clang-bpf-co-re: [ OFF ]
... llvm: [ on ]
... libcap: [ on ]
mkdir -p /home/pegasus/Documents/eBPF/bpftool/src/libbpf/
make -C /home/pegasus/Documents/eBPF/bpftool/libbpf/src OBJDIR=/home/pegasus/Documents/eBPF/bpftool/src/libbpf \
PREFIX=/home/pegasus/Documents/eBPF/bpftool/src/libbpf /home/pegasus/Documents/eBPF/bpftool/src/libbpf/libbpf.a install_headers
make[1]: Entering directory '/home/pegasus/Documents/eBPF/bpftool/libbpf/src'
mkdir -p /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c bpf.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/bpf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c btf.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/btf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c libbpf.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/libbpf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c libbpf_errno.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/libbpf_errno.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c netlink.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/netlink.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c nlattr.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/nlattr.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c str_error.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/str_error.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c libbpf_probes.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/libbpf_probes.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c bpf_prog_linfo.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/bpf_prog_linfo.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c btf_dump.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/btf_dump.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c hashmap.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/hashmap.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c ringbuf.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/ringbuf.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c strset.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/strset.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c linker.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/linker.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c gen_loader.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/gen_loader.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c relo_core.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/relo_core.o
cc -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unknown-warning-option -Wno-format-overflow -I/usr/local/include/libelf -I/usr/local/include -c usdt.c -o /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/usdt.o
usdt.c:572:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
572 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
| ^~~~~~~~~
| GElf_Shdr
usdt.c: In function ‘collect_usdt_targets’:
usdt.c:589:9: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
589 | GElf_Nhdr nhdr;
| ^~~~~~~~~
| GElf_Shdr
usdt.c:621:23: error: implicit declaration of function ‘gelf_getnote’; did you mean ‘gelf_getsym’? [-Werror=implicit-function-declaration]
621 | while ((off = gelf_getnote(data, off, &nhdr, &name_off, &desc_off)) > 0) {
| ^~~~~~~~~~~~
| gelf_getsym
usdt.c:627:23: error: implicit declaration of function ‘parse_usdt_note’; did you mean ‘parse_usdt_spec’? [-Werror=implicit-function-declaration]
627 | err = parse_usdt_note(elf, path, &nhdr, data->d_buf, name_off, desc_off, ¬e);
| ^~~~~~~~~~~~~~~
| parse_usdt_spec
usdt.c: At top level:
usdt.c:1133:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
1133 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
| ^~~~~~~~~
| GElf_Shdr
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: all warnings being treated as errors
make[1]: *** [Makefile:134: /home/pegasus/Documents/eBPF/bpftool/src/libbpf/staticobjs/usdt.o] Error 1
make[1]: Leaving directory '/home/pegasus/Documents/eBPF/bpftool/libbpf/src'
make: *** [Makefile:44: /home/pegasus/Documents/eBPF/bpftool/src/libbpf/libbpf.a] Error 2
I'm sorry, I still don't know where the issue comes from.
If you want to try to debug this further, you can try to run make -H
again (making sure to rebuild the objects, e.g. make -B -H
, or directly cc -H -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c usdt.c -o staticobjs/usdt.o
, and look for the included files. For reference, I get the list below.
Another possibility would be to grep your /usr
and search for a file where GElf_Shdr
, but not GElf_Nhdr
, would be defined (both are typdef
-ed in /usr/include/gelf.h
only for me).
If instead you want more people to look into it, I'd recommend taking the issue to the libbpf repo or better yet, the BPF mailing list.
Reading again your initial description, when you mention the error bpftool: error while loading shared libraries: libLLVM-17.so: cannot open shared object file: No such file or directory
, what binary does this refer to? The one you tried to compile, or is it a binary you installed in another way?
@qmonnet When I cc I get this.
pegasus@pegasus:~/Documents/eBPF/xdp-tutorial$ cc -H -I. -I../include -I../include/uapi -g -O2 -Werror -Wall -std=gnu89 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/include/libelf -I/usr/local/include -c usdt.c -o staticobjs/usdt.o
cc1: fatal error: usdt.c: No such file or directory
compilation terminated.
And this is the grep output
pegasus@pegasus:~/Documents/eBPF/xdp-tutorial$ grep -r "GElf_Shdr" /usr
/usr/include/gelf.h:typedef Elf64_Shdr GElf_Shdr;
/usr/include/gelf.h:extern GElf_Shdr *gelf_getshdr (Elf_Scn *__scn, GElf_Shdr *__dst);
/usr/include/gelf.h:extern int gelf_update_shdr (Elf_Scn *__scn, GElf_Shdr *__src);
/usr/local/include/libelf/gelf.h:typedef Elf64_Shdr GElf_Shdr;
/usr/local/include/libelf/gelf.h:extern GElf_Shdr *gelf_getshdr __P((Elf_Scn *__scn, GElf_Shdr *__dst));
/usr/local/include/libelf/gelf.h:extern int gelf_update_shdr __P((Elf_Scn *__scn, GElf_Shdr *__src));
grep: /usr/local/lib/libelf.so.0.8.12: binary file matches
grep: /usr/local/lib/libelf.a: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/elf.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/check.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/objtool: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/objtool.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/arch/x86/decode.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/arch/x86/special.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/arch/x86/objtool-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/orc_dump.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/orc_gen.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/special.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/objtool/objtool-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/libbpf/libbpf.a: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/btf.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/usdt.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/resolve_btfids: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/resolve_btfids-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-39-generic/tools/bpf/resolve_btfids/main.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/elf.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/check.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/objtool: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/objtool.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/arch/x86/decode.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/arch/x86/special.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/arch/x86/objtool-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/orc_dump.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/orc_gen.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/special.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/objtool/objtool-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/libbpf/libbpf.a: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/btf.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/usdt.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/resolve_btfids: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/resolve_btfids-in.o: binary file matches
grep: /usr/src/linux-headers-6.2.0-37-generic/tools/bpf/resolve_btfids/main.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/elf.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/check.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/objtool: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/objtool.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/weak.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/arch/x86/decode.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/arch/x86/special.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/arch/x86/objtool-in.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/orc_dump.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/orc_gen.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/special.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/objtool-in.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/objtool/builtin-check.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/libbpf/libbpf.a: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/btf.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/usdt.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/libbpf/staticobjs/libbpf-in.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/resolve_btfids: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/resolve_btfids-in.o: binary file matches
grep: /usr/src/linux-headers-6.4.0-060400-generic/tools/bpf/resolve_btfids/main.o: binary file matches
grep: /usr/lib/virtualbox/VBoxVolInfo: Permission denied
grep: /usr/lib/virtualbox/VBoxNetDHCP: Permission denied
grep: /usr/lib/virtualbox/VBoxNetNAT: Permission denied
grep: /usr/lib/virtualbox/VBoxHeadless: Permission denied
grep: /usr/lib/virtualbox/VirtualBoxVM: Permission denied
grep: /usr/lib/virtualbox/VBoxNetAdpCtl: Permission denied
grep: /usr/lib/linux-tools-6.2.0-39/perf: binary file matches
grep: /usr/lib/linux-tools-6.2.0-39/bpftool: binary file matches
grep: /usr/lib/linux-nvidia-5.19-tools-5.19.0-1007/perf: binary file matches
grep: /usr/lib/linux-nvidia-5.19-tools-5.19.0-1007/bpftool: binary file matches
grep: /usr/lib64/libbpf.a: binary file matches
grep: /usr/lib64/libbpf.so.1.4.0: binary file matches
grep: /usr/lib64/libbpf.so.1.0.1: binary file matches
pegasus@pegasus:~/Documents/ho/ZenosAnthology-0.2.9.8-pc$ uname -a
Linux pegasus 6.4.0-060400-generic #202306271339 SMP PREEMPT_DYNAMIC Tue Jun 27 14:26:34 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
I solved the issue. It was an issue with libelf. I downloaded a latest libelf version. Then Configured and installed it. libelf also had some dependency missing like specific versions of sqlite, libcurl, libarchive
Great to hear you solved it, thanks for reporting back! For future reference, could you please indicate what was the libelf version that caused the issue, and what version number fixed it?
For me 0.188-2.1
caused the error. And It's the version of libelf-dev
. But what I then did was build elfutils-0.191
manually which solved the error. Don't exactly know if the issue is from version 0.188-2.1
or something else caused it.
Because still now when I dpkg-query -s libelf-dev
I find the version is 0.188-2.1
OK, thank you!
you need install libelf from source libelf source: https://github.com/arachsys/libelf
When I try to invoke the bpftool it shows the following error.
bpftool: error while loading shared libraries: libLLVM-17.so: cannot open shared object file: No such file or directory
And when I try to compile the bpftool I get the following error: