iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.24k stars 3.84k forks source link

BCC_KERNEL_SOURCE doesn't work on OpenSUSE #2897

Open harjoc opened 4 years ago

harjoc commented 4 years ago

On OpenSUSE 15.1 with kernel-devel and dependencies installed, running

BCC_KERNEL_SOURCE=/lib/modules/4.12.14-lp151.28.48-default/build tools/opensnoop.py

results in:

<built-in>:1:10: error: './include/linux/kconfig.h' file not found

and the same with /lib/modules/.../source instead of .../build.

Running opensnoop.py without BCC_KERNEL_SOURCE in the env works.

Building a plain C module works via make -C /lib/modules/.../build M=$PWD modules . Adding an #include <linux/kconfig.h> in the module's source file also works.

This is with llvm-7 and clang-7 built from source as per INSTALL.md (the distro rpm's don't include libLLVMCore and others).

devidasjadhav commented 4 years ago

one suggestion.

As /lib/modules/4.12.14-lp151.28.48-default/build is symlink to kernel source.

can you try absolute path and real path of kernel source/ header ?

as per document Kernel source directory

eBPF program compilation needs kernel sources or kernel headers with headers compiled. In case your kernel sources are at a non-standard location where BCC cannot find then, its possible to provide BCC the absolute path of the location by setting BCC_KERNEL_SOURCE to it.

harjoc commented 4 years ago

I can try, but at least with the build and source symlinks in /lib/modules/x.y.z, there's a trivial way for bcc to deduce both the source and build dirs, if BCC_KERNEL_SOURCE env var exists. With the absolute and real paths, it would probably be much harder.

I currently use a patched libbcc that can accept BCC_KERNEL_SOURCE and BCC_KERNEL_BUILD (which point to /lib/modules/x/source and .../x/build) both being defined. But I think I can improve it so bcc still only receives just BCC_KERNEL_SOURCE, and if that envvar actually points to source, use both build+source.

Currently, if libbcc receives BCC_KERNEL_SOURCE, it treats it as a build dir AFAICT.