iovisor / bcc

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

bcc doesn't find llvm cmake files on Ubuntu Xenial #492

Open drzaeus77 opened 8 years ago

drzaeus77 commented 8 years ago

There is an upstream bug related to cmake+llvm that is affecting our ability to build on Ubuntu Xenial. That bug is tracked at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=819072.

The cmake .. phase of our build break with:

$ cmake ..
-- Latest recognized Git tag is v0.1.8
-- Git HEAD is 3036b96e4ba4f03868ff2271765adb031edf21d6
-- Revision is 0.1.8-3036b96e
CMake Error at /usr/share/llvm-3.8/cmake/LLVMConfig.cmake:178 (include):
  include could not find load file:

    /usr/share/llvm/cmake/LLVMExports.cmake
Call Stack (most recent call first):
  CMakeLists.txt:17 (find_package)

CMake Error at /usr/share/llvm-3.8/cmake/LLVMConfig.cmake:181 (include):
  include could not find load file:

    /usr/share/llvm/cmake/LLVM-Config.cmake
Call Stack (most recent call first):
  CMakeLists.txt:17 (find_package)

-- Found LLVM: /usr/include
CMake Error at CMakeLists.txt:36 (message):
  Unable to find clang libraries

-- Configuring incomplete, errors occurred!

As a workaround, I was able to do the following manually:

sudo apt-get install -y llvm-3.8-dev libclang-3.8-dev
sudo mkdir -p /usr/lib/llvm-3.8/share/llvm
sudo ln -s /usr/share/llvm-3.8/cmake /usr/lib/llvm-3.8/share/llvm/cmake
sudo sed -i -e '/get_filename_component(LLVM_INSTALL_PREFIX/ {s|^|#|}' -e '/^# Compute the installation prefix/i set(LLVM_INSTALL_PREFIX "/usr/lib/llvm-3.8")' /usr/lib/llvm-3.8/share/llvm/cmake/LLVMConfig.cmake
sudo sed -i '/_IMPORT_CHECK_TARGETS Polly/ {s|^|#|}' /usr/lib/llvm-3.8/share/llvm/cmake/LLVMExports-relwithdebinfo.cmake
sudo sed -i '/_IMPORT_CHECK_TARGETS sancov/ {s|^|#|}' /usr/lib/llvm-3.8/share/llvm/cmake/LLVMExports-relwithdebinfo.cmake
sudo ln -s /usr/lib/x86_64-linux-gnu/libLLVM-3.8.so.1 /usr/lib/llvm-3.8/lib/

This /issue should serve as a placeholder until the upstream is fixed.

drzaeus77 commented 8 years ago

Just to update that the debian bug seems to have been resolved, hopefully the fix propagates downstream soon.

dark commented 7 years ago

For the record, this issue is still open as of today, for package versions:

ii llvm-3.8-dev 1:3.8-2ubuntu4 amd64 Modular compiler and toolchain technologies, libraries and headers ii libclang-3.8-dev 1:3.8-2ubuntu4 amd64 clang library - Development package

HammiSaif commented 7 years ago

No solution for the above error ?

drzaeus77 commented 7 years ago

Not that I am aware of. Would be curious whether it works on 16.10 and above, which may depend on whether 3.9 gets packaged or not.

HammiSaif commented 7 years ago

So how can I build an LLVM pass using cmake on ubuntu 16.04 ?

drzaeus77 commented 7 years ago

The workaround mentioned above (symbolic linking and sed commands) is what I use on the buildbots for bcc.

HammiSaif commented 7 years ago

Well from this error: Make Error at /usr/share/llvm-3.8/cmake/LLVMConfig.cmake:178 (include): include could not find load file:

/usr/share/llvm/cmake/LLVMExports.cmake

Call Stack (most recent call first): CMakeLists.txt:17 (find_package)

It seems like path to the LLVMExports.cmake file is not set correctly in LLVMConfig.cmake. I changed the line 174 of my LLVMConfig.cmake from " set(LLVM_CMAKE_DIR "${LLVM_INSTALL_PREFIX}/share/llvm/cmake") " to " set(LLVM_CMAKE_DIR "${LLVM_INSTALL_PREFIX}/share/llvm-3.8/cmake")" and above cmake error was removed. I am using Ubuntu 16.04 and installed cmake + llvm using Ubuntu packages.

butterl commented 7 years ago

@HammiSaif I followed your instruction and fix the previous error but got below error,did you meet it, I also using ubuntu 16.04 and install llvm from apt

CMake Error at /usr/share/llvm-3.8/cmake/LLVMExports.cmake:1034 (message):
  The imported target "LLVMSupport" references the file

     "/usr/lib/libLLVMSupport.a"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/usr/share/llvm-3.8/cmake/LLVMExports.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /usr/share/llvm-3.8/cmake/LLVMConfig.cmake:178 (include)
  CMakeLists.txt:22 (find_package)
gabhijit commented 7 years ago

@drzaeus77 @butterl

I somehow managed to get all the CMake errors resolved (broadly following what @drzaeus77 has suggested), but then I got a number of warnings of the type -

In file included from /usr/lib/llvm-3.8/include/clang/AST/Decl.h:17:0,
                 from /usr/lib/llvm-3.8/include/clang/AST/ASTTypeTraits.h:20,
                 from /usr/lib/llvm-3.8/include/clang/AST/ASTContext.h:18,
                 from /usr/lib/llvm-3.8/include/clang/Frontend/ASTUnit.h:18,
                 from /usr/lib/llvm-3.8/include/clang/Frontend/FrontendAction.h:24,
                 from /usr/lib/llvm-3.8/include/clang/CodeGen/CodeGenAction.h:13,
                 from /home/path-to-bcc/bcc/src/cc/frontends/clang/loader.cc:37:
/usr/lib/llvm-3.8/include/clang/AST/APValue.h: In member function ‘clang::APValue::APSInt& clang::APValue::getInt()’:
/usr/lib/llvm-3.8/include/clang/AST/APValue.h:202:34: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     return *(APSInt*)(char*)Data.buffer;

This looked like chasing rabbit holes. So I finally decided to give llvm and clang 3.8 a pass and built using clang-3.7 and llvm-3.7. ( I had to clean up all llvm-3.8 packages that were installed using apt-get remove llvm-3.8 clang-3.8)

Other than a couple of warnings like this - the compilation was successful.

bcc/build/src/cc/frontends/b/lexer.ll.cc:764:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for ( yyl = 0; yyl < yyleng; ++yyl )

So you might want to try 3.7 instead of 3.8 (Note also: There is a hard-coded reference to 3.7 in CMakeLists.txt - line 41 or something - so may be that is expected version?).

drandynisbet commented 5 years ago

Similar/related problem persists on ubuntu cosmic 18.10 (development - but soon to be an ubuntu release)
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -- Latest recognized Git tag is v0.7.0 -- Git HEAD is 4263e1ae1c60a1b2655a31d4832fba0eaf5bc41e -- Revision is 0.7.0-4263e1ae -- Found LLVM: /usr/lib/llvm-6.0/include 6.0.1 CMake Error at CMakeLists.txt:50 (message): Unable to find clang libraries

-- Configuring incomplete, errors occurred!

Fix for the cmake for me ... was to update the CMakeLists.txt in the bcc directory to reflect the clang/llvm version for my distribution .... 35 set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.9/lib;${LLVM_LIBRARY_DIRS}")

clang include files are incorrectly set ... so build fails but working on it

Hmm... strange mismatch between clang and LLVM_MAJOR_VERSION ... on cosmic

erriapo commented 5 years ago

In case people have the same problem, I can confirm that @drandynisbet hack works. In my case, I am using llvm-7. Just do the following:

$ sudo apt-get install libclang-7-dev

Then edit CMakeLists.txt by adding the path to the directory containing the clang static files *.a

Clcanny commented 5 years ago

In case people have the same problem, I can confirm that @drandynisbet hack works. In my case, I am using llvm-7. Just do the following:

$ sudo apt-get install libclang-7-dev

Then edit CMakeLists.txt by adding the path to the directory containing the clang static files *.a

Actually, I use command sudo apt-get install libclang-dev to solve this problem.

drandynisbet commented 5 years ago

OK I am still having a few issues after coming back to this today,... I have built the current clone of the repo on cosmic, 4.18.0-15-generic ... - the kernel has BPF support, yet running as root I get .... /usr/share/bcc/introspection/bps BID TYPE UID #MAPS LoadTime NAME
Require CAP_SYS_ADMIN capability. Please retry as root

/usr/share/bcc/tools/biosnoop could not open bpf map: events is map type enabled in your kernel? Traceback (most recent call last): File "/usr/share/bcc/tools/biosnoop", line 123, in """, debug=0) File "/usr/lib/python2.7/dist-packages/bcc/init.py", line 323, in init raise Exception("Failed to compile BPF text") Exception: Failed to compile BPF text root@drandynisbet-XPS-13-9360:/home/drandynisbet/bcc/build#

ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 62643 max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) unlimited cpu time (seconds, -t) unlimited max user processes (-u) 62643 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

Any ideas here .on what to check - on supported ubuntu releases I haven't had a problem ...

Additional information ... cat /boot/config-4.18.0-15-generic | grep BPF CONFIG_CGROUP_BPF=y CONFIG_BPF=y CONFIG_BPF_SYSCALL=y CONFIG_BPF_JIT_ALWAYS_ON=y CONFIG_IPV6_SEG6_BPF=y CONFIG_NETFILTER_XT_MATCH_BPF=m CONFIG_BPFILTER=y CONFIG_BPFILTER_UMH=m CONFIG_NET_CLS_BPF=m CONFIG_NET_ACT_BPF=m CONFIG_BPF_JIT=y CONFIG_BPF_STREAM_PARSER=y CONFIG_LWTUNNEL_BPF=y CONFIG_HAVE_EBPF_JIT=y CONFIG_BPF_EVENTS=y CONFIG_BPF_KPROBE_OVERRIDE=y

drandynisbet commented 5 years ago

OK, so going into the BIOS and turning off secure boot seems to have done the trick - or at least tests/cc/test_libbcc test cases: 29 | 27 passed | 2 failed assertions: 592 | 590 passed | 2 failed /home/drandynisbet/bcc/tests/cc/test_usdt_probes.cc:46: FAILED: /home/drandynisbet/bcc/tests/cc/test_usdt_probes.cc:156: FAILED:

/usr/share/bcc/introspection/bps BID TYPE UID #MAPS LoadTime NAME
2 cgroup skb 0 2 Feb11/14:29
3 cgroup skb 0 2 Feb11/14:29
4 cgroup skb 0 2 Feb11/14:29
5 cgroup skb 0 2 Feb11/14:29
6 cgroup skb 0 2 Feb11/14:29
7 cgroup skb 0 2 Feb11/14:29

russoue commented 2 years ago

Actually, I use command sudo apt-get install libclang-dev to solve this problem.

The solution worked for me too in a CentOS 8 machine:

sudo dnf install -y clang-devel