Open cydrain opened 2 years ago
Do you have kernel-devel
or kernel-headers
packages installed ?
Try this:
$ sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm
Hi @chenhengqi , I have tried both of your suggestions, it does not work.
include/uapi/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
^~~~~~~~~~~~~
It's should be types.h in Linux kernel source instead of gnu header /usr/include/x86_64-linux-gnu Maybe you should make sure you have types.h in your kernel source which BPF references.
@cydrain As folks already mentioned, the path for types.h (/usr/include/x86_64-linux-gnu/asm/types.h) is not correct. You should install kernel-devel package. The headers should be in build/arch/x86/include/generated/uapi/asm/types.h
.
Hi @yonghong-song , I have "types.h" under this directory, is it ok ?
❯ pwd
/usr/src/linux-headers-5.4.0-90-generic/arch/x86/include/generated/uapi/asm
❯ ll types.h
-rw-r--r-- 1 root root 31 Oct 22 16:46 types.h
Looks like your kernel src is in a different location. Maybe you can try BCC_KERNEL_SOURCE env variable? Please take a look at the following patch for details
commit 11f3a2739be5c1659c8459fd1b20a99bbd3c35ae
Author: Joel Fernandes <joelaf@google.com>
Date: Thu Feb 1 20:59:19 2018 -0500
clang/loader: Add support for specifying absolute path of kernel sources
Many developers have kernel sources at an specific location. Allow
clang to build from there by allowing to specify a single absolute
path to the kernel sources through a new env var BCC_KERNEL_SOURCE.
Hi @yonghong-song , after specify BCC_KERNEL_SOURCE, it reports another error.
❯ export BCC_KERNEL_SOURCE=/usr/src/linux-headers-5.4.0-90-generic/arch/x86
❯ ./hello_world.py
modprobe: ERROR: could not insert 'kheaders': Operation not permitted
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module) or installing the kernel development package for your running kernel version.
<built-in>:1:10: fatal error: './include/linux/kconfig.h' file not found
#include "./include/linux/kconfig.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Traceback (most recent call last):
File "./hello_world.py", line 12, in <module>
BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\\n"); return 0; }').trace_print()
File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 479, in __init__
raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>
❯ grep CONFIG_IKHEADERS /boot/config-5.4.0-90-generic
131:CONFIG_IKHEADERS=m
Hi @cydrain
export BCC_KERNEL_SOURCE=/usr/src/linux-headers-5.4.0-90-generic/arch/x86
The BCC_KERNEL_SOURCE should point to the root of kernel header, in your case, it should be something like below without ARCH path.
export BCC_KERNEL_SOURCE=/usr/src/linux-headers-5.4.0-90-generic/
Could you please take a shoot? Thank you.
Try this:
$ sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm
Solved, thanks @chenhengqi!
I build bcc from source successfully, but when I run memleak, it reports this error:
And actually this file "asm/types.h" exists in the default include directory:
My system is ubuntu 18.04. Can someone help to solve this issue?