Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 809347

Summary: dev-util/bcc has a run-time dependency on the sources of current running kernel (fatal error: './include/linux/kconfig.h' file not found)
Product: Gentoo Linux Reporter: WGH <wgh>
Component: Current packagesAssignee: Zac Medico <zmedico>
Status: RESOLVED UPSTREAM    
Severity: normal CC: chutzpah
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
URL: https://github.com/iovisor/bcc/pull/3588
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: bcc patch to chech the existence of /lib/modules/$(uname -r)/build/include/linux/kconfig.h

Description WGH 2021-08-21 08:16:42 UTC
dev-util/bcc stops functioning after unmerging the sources of the currently running kernel.

Reproducible: Always

Steps to Reproduce:
1. Unmerge gentoo-sources of the currently running kernel.
2. Run any bcc tool, e.g. /usr/share/bcc/tools/opensnoop
Actual Results:  
Password:
<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 "/usr/lib/python-exec/python3.9/opensnoop", line 261, in <module>
    b = BPF(text='')
  File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 365, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

Expected Results:  
It works.

bcc tools need the kernel's kconfig.h to function. It tries to find it under path
 /lib/modules/$(uname -r)/build/include/linux/kconfig.h[1][2].

However, when you unmerge gentoo-sources of the currently running kernel, that file is gone.

bcc has a fallback when it tries to extract the headers using kheaders module (/sys/kernel/kheaders.tar.xz). However, the fallback path is not triggered because /lib/modules/$(uname -r)/build still exists until you delete eiter the leftover kernel build directory or /lib/modules/$(uname -r)/build symlink manually[3]. (this is a workaround)

I suppose bcc could be fixed to actually check the existence of /lib/modules/$(uname -r)/build/include/linux/kconfig.h instead of just checking for /lib/modules/$(uname -r)/{build,source}.
 
[1] https://github.com/iovisor/bcc/blob/40d6e8556b380e2fd10b865da884f66e7bfdae35/src/cc/frontends/clang/loader.cc#L166-L167
[2] https://github.com/iovisor/bcc/blob/d089013e8c6ee0b82d012c1814f822b00695691f/src/cc/frontends/clang/kbuild_helper.cc#L99-L116
[3] https://github.com/iovisor/bcc/blob/40d6e8556b380e2fd10b865da884f66e7bfdae35/src/cc/frontends/clang/loader.cc#L173
Comment 1 WGH 2021-08-21 08:28:37 UTC
Created attachment 734734 [details, diff]
bcc patch to chech the existence of /lib/modules/$(uname -r)/build/include/linux/kconfig.h
Comment 2 WGH 2021-10-08 18:48:27 UTC
This got fixed upstream in 0.22.0 (see liked GitHub PR), and Gentoo already has a new version.