lizrice / learning-ebpf

Learning eBPF, published by O'Reilly - out now! Here's where you'll find a VM config for the examples, and more
https://www.amazon.com/Learning-eBPF-Programming-Observability-Networking/dp/1098135121
Apache License 2.0
1.19k stars 255 forks source link

error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’? #39

Closed NobinPegasus closed 6 months ago

NobinPegasus commented 6 months ago

While trying to build the bpftool I'm facing the following errors:

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, &note);
      |                       ^~~~~~~~~~~~~~~
      |                       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
NobinPegasus commented 6 months ago

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