bpftools/linux-observability-with-bpf

need to build BPF programs for real-world target

mmelo-yottaa opened this issue · 3 comments

Its great you have a vagrantfile that spins up a VM that runs all your example code just perfectly. I'm guessing many people who buy your book (like me!) and run your examples want to use what they learn on a real linux host with a recent linux kernel. Do you provide any assist with using your sample code directly on an installed linux distro with a recent 5.x kernel?

i am running debian 10.5, stock kernel replaced with v5.8.5, LLVM/clang 7.0.1-8, bcc built from iovisor github download. your simplest example doesnt build:

clang -O2 -target bpf -c bpf_program.c -I/kernel-src/tools/testing/selftests/bpf -o bpf_program.o
clang -o monitor-exec -lelf -I/kernel-src/samples/bpf -I/kernel-src/tools/lib -I/kernel-src/tools/perf -I/kernel-src/tools/include -L/usr/local/lib64 -lbpf
/kernel-src/samples/bpf/bpf_load.c loader.c
loader.c:10:3: warning: implicit declaration of function 'read_trace_pipe' is invalid in C99 [-Wimplicit-function-declaration]
read_trace_pipe();
^
1 warning generated.
/usr/bin/ld: /tmp/bpf_load-27b31c.o: in function sys_perf_event_open': bpf_load.c:(.text+0x204e): undefined reference to test_attr__enabled'
/usr/bin/ld: bpf_load.c:(.text+0x2085): undefined reference to test_attr__open' /usr/bin/ld: /tmp/loader-e37255.o: in function main':
loader.c:(.text+0x51): undefined reference to `read_trace_pipe'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:28: bpfload] Error 1

thanks for any help!!

I suggest that it is the same problem as in #46
Fast fix this problem is adding -DHAVE_ATTR_TEST=0 for compiling loader.c.

thanks for quick reply!

your tip removes the undefined reference to test_attr__open (by avoiding its use), however the build still cannot resolve read_trace_pipe():

mike@debianT420Too:/files/yottaa/Debug/Cloudflare/linux-observability-with-bpf/code/chapter-2/hello_world$ clang -o monitor-exec -lelf -I/kernel-src/samples/bpf -DHAVE_ATTR_TEST=0 -I/kernel-src/tools/lib -I/kernel-src/tools/perf -I/kernel-src/tools/include -L/usr/local/lib64 -lbpf /kernel-src/samples/bpf/bpf_load.c loader.c
loader.c:10:3: warning: implicit declaration of function 'read_trace_pipe' is invalid in C99 [-Wimplicit-function-declaration]
read_trace_pipe();
^
1 warning generated.
/usr/bin/ld: /tmp/loader-17e35b.o: in function main': **loader.c:(.text+0x51): undefined reference to read_trace_pipe'**
clang: error: linker command failed with exit code 1 (use -v to see invocation)