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

Chapter 7 Make error #29

Closed Faru0 closed 1 year ago

Faru0 commented 1 year ago

root@xxx:/tmp/learning-ebpf/chapter7# ls -larth total 2.9M -rw-r--r-- 1 root root 312 Jul 14 08:56 README.md -rw-r--r-- 1 root root 736 Jul 14 08:56 Makefile -rw-r--r-- 1 root root 143 Jul 14 08:56 hello.h -rw-r--r-- 1 root root 2.1K Jul 14 08:56 hello.c -rw-r--r-- 1 root root 5.4K Jul 14 08:56 hello.bpf.c drwxr-xr-x 12 root root 4.0K Jul 14 08:56 .. -rw-r--r-- 1 root root 2.8M Jul 14 12:54 vmlinux.h drwxr-xr-x 2 root root 4.0K Jul 14 12:57 . root@xxx:/tmp/learning-ebpf/chapter7# make clang \ -target bpf \ -D __BPF_TRACING \ -D TARGET_ARCH_x86 \ -Wall \ -O2 -g -o hello.bpf.o -c hello.bpf.c hello.bpf.c:27:43: error: expected identifier int BPF_KPROBE_SYSCALL(kprobe_sys_execve, const char *pathname) ^ hello.bpf.c:32:51: error: use of undeclared identifier 'pathname'; did you mean 'Opt_name'? bpf_printk("%s: pathname: %s", kprobe_sys_msg, pathname); ^~~~ Opt_name /usr/include/bpf/bpf_helpers.h:22:7: note: expanded from macro 'bpf_printk'

__VA_ARGS__); \

                       ^

./vmlinux.h:40369:2: note: 'Opt_name' declared here Opt_name = 3, ^ hello.bpf.c:37:55: error: use of undeclared identifier 'pathname' bpf_probe_read_user(&data.path, sizeof(data.path), pathname); ^ hello.bpf.c:39:26: error: use of undeclared identifier 'ctx' bpf_perf_event_output(ctx, &output, BPF_F_CURRENT_CPU, &data, sizeof(data)); ^ 4 errors generated. make: *** [Makefile:18: hello.bpf.o] Error 1 root@xxx:/tmp/learning-ebpf/chapter7#

Faru0 commented 1 year ago

fixed with bpftool/src/ -> make install