eunomia-bpf / bpftime

Userspace eBPF runtime for Observability, Network & General Extensions Framework
https://eunomia.dev/bpftime/
MIT License
834 stars 78 forks source link

Unknown Type `__u32` when Compiling BPFTime #360

Closed TheAhmad closed 1 week ago

TheAhmad commented 2 weeks ago

Hi, I used the following command to download the repo: git clone --recursive https://github.com/eunomia-bpf/bpftime.git

Then I created a build directory and executed the following two commands inside that directory: sudo cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=Release -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO -G "Unix Makefiles" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. sudo cmake --build build --config Release --target install

[ 80%] Building CXX object runtime/CMakeFiles/runtime.dir/src/attach/bpf_attach_ctx.cpp.o cd /home/ahmad/Programs/bpftime/build/build/runtime && /usr/bin/c++ -DBPFTIME_BUILD_WITH_LIBBPF=1 -DSPDLOG_COMPILED_LIB -I/home/ahmad/Programs/bpftime/runtime/../vm/include -I/home/ahmad/Programs/bpftime/runtime/../runtime/include -I/home/ahmad/Programs/bpftime/runtime/../runtime -I/home/ahmad/Programs/bpftime/build/build/runtime -I/home/ahmad/Programs/bpftime/runtime/../third_party -I/home/ahmad/Programs/bpftime/third_party/spdlog/include -I/home/ahmad/Programs/bpftime/build/build/libbpf/uapi -I/home/ahmad/Programs/bpftime/build/build/libbpf -I/home/ahmad/Programs/bpftime/build/build/FridaGum-prefix/src/FridaGum -I/home/ahmad/Programs/bpftime/runtime/include -I/home/ahmad/Programs/bpftime/runtime/src -I/home/ahmad/Programs/bpftime/vm/vm-core/./include -I/home/ahmad/Programs/bpftime/vm/compat/include -I/home/ahmad/Programs/bpftime/attach/base_attach_impl -fno-omit-frame-pointer -O3 -DNDEBUG -std=gnu++20 -fPIC -Wall -Wextra -Wno-shadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wformat=2 -fPIE -fPIC -fno-common -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-missing-field-initializers -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wlogical-op -MD -MT runtime/CMakeFiles/runtime.dir/src/attach/bpf_attach_ctx.cpp.o -MF CMakeFiles/runtime.dir/src/attach/bpf_attach_ctx.cpp.o.d -o CMakeFiles/runtime.dir/src/attach/bpf_attach_ctx.cpp.o -c /home/ahmad/Programs/bpftime/runtime/src/attach/bpf_attach_ctx.cpp In file included from /home/ahmad/Programs/bpftime/runtime/src/attach/bpf_attach_ctx.cpp:8: /home/ahmad/Programs/bpftime/runtime/../runtime/include/bpftime_shm.hpp:224:17: error: ‘__u32’ does not name a type 224 | __u32 prog_fd; /* eBPF program to attach */ | ^~~~~

It seems that a kernel type (i.e., __u32) is not known to the compiler. I have found a definition, here: /home/ahmad/Programs/bpftime/third_party/vmlinux/x86/vmlinux.h

But adding this folder to the included paths causes many more bugs. I use Ubuntu 18.04 with a vanilla Linux 5.8.0 kernel. The manually built GCC version is 13.1.0. How can I resolve this issue?

Thanks for the much needed tool! I'm looking forward to your reply. Regards.

Officeyutong commented 1 week ago

These may happen due to massed headers in out development environment so we made some wrong includes. Try modifying __u32 to uint32_t should solve it, they are identical types with different alias

TheAhmad commented 1 week ago

I had to these two lines to runtime/include/bpftime_shm.hpp:

#include <asm-generic/int-ll64.h> #include <linux/types.h>

Regards.

TheAhmad commented 1 week ago

I also had to add the following line to runtime/src/bpf_map/userspace/ringbuf_map.cpp , for a similar error:

#include <asm-generic/int-ll64.h>

Regards.