iovisor / gobpf

Go bindings for creating BPF programs.
Apache License 2.0
2.14k stars 314 forks source link

NewModule how to pass flags for debug #331

Closed vimalk78 closed 1 year ago

vimalk78 commented 1 year ago

While calling NewModule https://github.com/iovisor/gobpf/blob/master/bcc/module.go#L138 how to pass cflags to this function which makes bcc loader print detailed compilation output?

I am running a program which loads a bpf program. It runs fine if i run it with sudo, but it gives compilation errors while compiling the bpf program if executed without sudo.

I looked into bcc https://github.com/iovisor/bcc/blob/master/src/cc/frontends/clang/loader.cc#L193 and i see that it tries to look into kernel modules for kernel header and tries to compile the bpf code.

My laptop has /lib/module/6.1.15-200.fc37.x86_64 folder with source and debug folders.

the bpf program does get compiled if the program is run with root permissions, but otherwise it gives compilation warnings and fails. why?

thats why i am looking for some compilation flags to be passed to clang via NewModule so that i can get more verbose output.

vimalk78 commented 1 year ago

i found the reason for compilation errors.

The bpf program uses a TRACEPOINT_PROBE and to compile the generated function we need access to /sys/kernel/debug/tracing/events/ to read the format of the input args.

and without sudo, the compilation process cannot access this path, and hence the error.