Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Ubuntu llvm/clang packages #76

Closed
brendangregg opened this issue Sep 11, 2018 · 27 comments · Fixed by delphix/bpftrace#3
Closed

fix Ubuntu llvm/clang packages #76

brendangregg opened this issue Sep 11, 2018 · 27 comments · Fixed by delphix/bpftrace#3
Labels
build Issues or PRs related to bpftrace building help wanted Extra attention is needed
Milestone

Comments

@brendangregg
Copy link
Contributor

This ticket is to (somehow) get the ubuntu/debian llvm/clang packages updated.

INSTALL.md has instructions for adding apt.llvm.org as a repository. If you don't do that, and use the default Ubuntu ones, you get this:

# mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=DEBUG ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found LibElf: /usr/lib/x86_64-linux-gnu/libelf.so
-- Performing Test ELF_GETSHDRSTRNDX
-- Performing Test ELF_GETSHDRSTRNDX - Success
-- Found BISON: /usr/bin/bison (found version "3.0.4")
-- Found FLEX: /usr/bin/flex (found version "2.6.4")
CMake Error at CMakeLists.txt:67 (find_package):
  By not providing "FindClang.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Clang", but
  CMake did not find one.

  Could not find a package configuration file provided by "Clang" with any of
  the following names:

    ClangConfig.cmake
    clang-config.cmake

  Add the installation prefix of "Clang" to CMAKE_PREFIX_PATH or set
  "Clang_DIR" to a directory containing one of the above files.  If "Clang"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/mnt/src/bpftrace/build/CMakeFiles/CMakeOutput.log".

Someone should fix that so the default repository works. At least we have the apt.llvm.org workaround.

@mlen
Copy link
Contributor

mlen commented Oct 10, 2018

This appears to be an upstream bug from debian packaging.

@bobrik
Copy link

bobrik commented Oct 10, 2018

BCC also depends on Clang parts, but it manages to avoid this problem somehow.

@dalehamel
Copy link
Contributor

Related to #266, it would be great to also run a static build from ubuntu as it would link libc instead of musl, which seems to be the cause of crashes for the bpftrace static binary.

@vincentbernat
Copy link
Contributor

The Debian bug has been fixed. I am able to compile bpftrace on Debian Sid using llvm 7.

@bobrik
Copy link

bobrik commented Jan 9, 2019

I managed to package bpftool with the following patch on llvm-6.0:

diff -rup ./ClangConfig.cmake /usr/share/llvm-6.0/cmake/ClangConfig.cmake
--- ./ClangConfig.cmake	2019-01-09 00:29:01.334985035 +0000
+++ /usr/share/llvm-6.0/cmake/ClangConfig.cmake	2019-01-09 00:29:39.700589050 +0000
@@ -15,7 +15,7 @@ set(CLANG_CMAKE_DIR "${CLANG_INSTALL_PRE
 set(CLANG_INCLUDE_DIRS "${CLANG_INSTALL_PREFIX}/include")
 
 # Provide all our library targets to users.
-include("${CLANG_CMAKE_DIR}/ClangTargets.cmake")
+include("/usr/share/llvm-6.0/cmake/ClangTargets.cmake")
 
 # By creating clang-tablegen-targets here, subprojects that depend on Clang's
 # tablegen-generated headers can always depend on this target whether building
diff -rup ./ClangTargets-relwithdebinfo.cmake /usr/share/llvm-6.0/cmake/ClangTargets-relwithdebinfo.cmake
--- ./ClangTargets-relwithdebinfo.cmake	2019-01-09 00:41:49.440472014 +0000
+++ /usr/share/llvm-6.0/cmake/ClangTargets-relwithdebinfo.cmake	2019-01-09 00:42:19.617219014 +0000
@@ -278,11 +278,11 @@ list(APPEND _IMPORT_CHECK_FILES_FOR_clan
 # Import target "clang" for configuration "RelWithDebInfo"
 set_property(TARGET clang APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
 set_target_properties(clang PROPERTIES
-  IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/bin/clang-6.0"
+  IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/bin/clang"
   )
 
 list(APPEND _IMPORT_CHECK_TARGETS clang )
-list(APPEND _IMPORT_CHECK_FILES_FOR_clang "${_IMPORT_PREFIX}/bin/clang-6.0" )
+list(APPEND _IMPORT_CHECK_FILES_FOR_clang "${_IMPORT_PREFIX}/bin/clang" )
 
 # Import target "clang-format" for configuration "RelWithDebInfo"
 set_property(TARGET clang-format APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
diff -rup ./ClangTargets.cmake /usr/share/llvm-6.0/cmake/ClangTargets.cmake
--- ./ClangTargets.cmake	2019-01-09 00:35:48.562625012 +0000
+++ /usr/share/llvm-6.0/cmake/ClangTargets.cmake	2019-01-09 00:37:07.801493046 +0000
@@ -59,6 +59,8 @@ if(_IMPORT_PREFIX STREQUAL "/")
   set(_IMPORT_PREFIX "")
 endif()
 
+set(_IMPORT_PREFIX "/usr/lib/llvm-6.0")
+
 # Create imported target clangBasic
 add_library(clangBasic STATIC IMPORTED)
 

Assuming ephemeral build environment, this can be applied with:

patch -d /usr/share/llvm-6.0/cmake < cmake-6.0-debian-hack.patch

Build requirements from llvm/clang side:

$ dpkg -l | fgrep llvm
ii  libllvm6.0:amd64           1:6.0-1                        amd64        Modular compiler and toolchain technologies, runtime library
ii  llvm-6.0                   1:6.0-1                        amd64        Modular compiler and toolchain technologies
ii  llvm-6.0-dev               1:6.0-1                        amd64        Modular compiler and toolchain technologies, libraries and headers
ii  llvm-6.0-runtime           1:6.0-1                        amd64        Modular compiler and toolchain technologies, IR interpreter
$ dpkg -l | fgrep clang
ii  clang-6.0                  1:6.0-1                        amd64        C, C++ and Objective-C compiler
ii  clang-format-6.0           1:6.0-1                        amd64        Tool to format C/C++/Obj-C code
ii  clang-tidy-6.0             1:6.0-1                        amd64        clang-based C++ linter tool
ii  clang-tools-6.0            1:6.0-1                        amd64        clang-based tools for C/C++ developments
ii  libclang-6.0-dev           1:6.0-1                        amd64        clang library - Development package
ii  libclang-common-6.0-dev    1:6.0-1                        amd64        clang library - Common development package
ii  libclang1-6.0:amd64        1:6.0-1                        amd64        C interface to the clang library

Build steps then:

mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/usr/share/llvm-6.0/cmake ..
make

Resulting binary also depends on libllvm6.0 and libclang1-6.0:

$ ldd $(which bpftrace)
	linux-vdso.so.1 (0x00007ffd8fde7000)
	libelf.so.1 => /usr/lib/x86_64-linux-gnu/libelf.so.1 (0x00007ffb4a4d3000)
	libLLVM-6.0.so.1 => /usr/lib/x86_64-linux-gnu/libLLVM-6.0.so.1 (0x00007ffb46a10000)
	libclang-6.0.so.1 => /usr/lib/x86_64-linux-gnu/libclang-6.0.so.1 (0x00007ffb45089000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ffb44d07000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffb44a03000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ffb447ec000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffb4444d000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ffb44233000)
	/lib64/ld-linux-x86-64.so.2 (0x00007ffb4aba3000)
	libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007ffb4402a000)
	libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007ffb43df2000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ffb43bea000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ffb439e6000)
	libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ffb437bc000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffb4359f000)
	libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5 (0x00007ffb4337c000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007ffb43166000)

Still seems like the proper way would be to reuse what BCC does as it seems to work out of the box and without runtime dependencies. Maybe #327 will help with the latter, I'm not sure.

@bobrik
Copy link

bobrik commented Jan 11, 2019

I'm still struggling to build a static binary version on Debian Stretch.

I end up with the following while linking bpftool:

[ 39%] Linking CXX executable bpftrace
cd /cfsetup_build/bpftrace/tmp/build/bpftrace-0.8.0/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/bpftrace.dir/link.txt --verbose=1
/usr/bin/c++     -static CMakeFiles/bpftrace.dir/attached_probe.cpp.o CMakeFiles/bpftrace.dir/bpftrace.cpp.o CMakeFiles/bpftrace.dir/clang_parser.cpp.o CMakeFiles/bpftrace.dir/driver.cpp.o CMakeFiles/bpftrace.dir/fake_map.cpp.o CMakeFiles/bpftrace.dir/main.cpp.o CMakeFiles/bpftrace.dir/map.cpp.o CMakeFiles/bpftrace.dir/mapkey.cpp.o CMakeFiles/bpftrace.dir/printf.cpp.o CMakeFiles/bpftrace.dir/resolve_cgroupid.cpp.o CMakeFiles/bpftrace.dir/tracepoint_format_parser.cpp.o CMakeFiles/bpftrace.dir/types.cpp.o CMakeFiles/bpftrace.dir/list.cpp.o  -o bpftrace -Wl,-rpath,/usr/lib/llvm-6.0/lib: -rdynamic arch/libarch.a ast/libast.a ../libparser.a ../resources/libresources.a ../bcc-prefix/src/bcc-build/src/cc/libbpf.a ../bcc-prefix/src/bcc-build/src/cc/libbcc-loader-static.a ../bcc-prefix/src/bcc-build/src/cc/libbcc.a ../bcc-prefix/src/bcc-build/src/cc/frontends/clang/libclang_frontend.a -lelf arch/libarch.a -lclang /usr/lib/llvm-6.0/lib/libclangIndex.a /usr/lib/llvm-6.0/lib/libclangFormat.a /usr/lib/llvm-6.0/lib/libclangFrontend.a /usr/lib/llvm-6.0/lib/libclangDriver.a /usr/lib/llvm-6.0/lib/libclangParse.a /usr/lib/llvm-6.0/lib/libclangSerialization.a /usr/lib/llvm-6.0/lib/libclangSema.a /usr/lib/llvm-6.0/lib/libclangAnalysis.a /usr/lib/llvm-6.0/lib/libclangEdit.a /usr/lib/llvm-6.0/lib/libclangToolingCore.a /usr/lib/llvm-6.0/lib/libclangAST.a /usr/lib/llvm-6.0/lib/libclangRewrite.a /usr/lib/llvm-6.0/lib/libclangLex.a /usr/lib/llvm-6.0/lib/libclangBasic.a -Wl,-Bdynamic /usr/lib/llvm-6.0/lib/libLLVM-6.0.so.1 /usr/lib/llvm-6.0/lib/libLLVMBPFCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMMCJIT.a /usr/lib/llvm-6.0/lib/libLLVMOrcJIT.a /usr/lib/llvm-6.0/lib/libLLVMExecutionEngine.a /usr/lib/llvm-6.0/lib/libLLVMRuntimeDyld.a /usr/lib/llvm-6.0/lib/libLLVMAArch64CodeGen.a /usr/lib/llvm-6.0/lib/libLLVMAArch64AsmParser.a /usr/lib/llvm-6.0/lib/libLLVMAArch64Disassembler.a /usr/lib/llvm-6.0/lib/libLLVMAArch64Desc.a /usr/lib/llvm-6.0/lib/libLLVMAArch64AsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMAArch64Info.a /usr/lib/llvm-6.0/lib/libLLVMAArch64Utils.a /usr/lib/llvm-6.0/lib/libLLVMAMDGPUCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMAMDGPUAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMAMDGPUDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMAMDGPUDesc.a /usr/lib/llvm-6.0/lib/libLLVMAMDGPUAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMAMDGPUInfo.a /usr/lib/llvm-6.0/lib/libLLVMAMDGPUUtils.a /usr/lib/llvm-6.0/lib/libLLVMARMCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMARMAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMARMDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMARMDesc.a /usr/lib/llvm-6.0/lib/libLLVMARMAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMARMInfo.a /usr/lib/llvm-6.0/lib/libLLVMARMUtils.a /usr/lib/llvm-6.0/lib/libLLVMBPFAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMBPFDesc.a /usr/lib/llvm-6.0/lib/libLLVMBPFAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMBPFDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMBPFInfo.a /usr/lib/llvm-6.0/lib/libLLVMHexagonCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMHexagonAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMHexagonDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMHexagonDesc.a /usr/lib/llvm-6.0/lib/libLLVMHexagonInfo.a /usr/lib/llvm-6.0/lib/libLLVMLanaiCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMLanaiAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMLanaiDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMLanaiDesc.a /usr/lib/llvm-6.0/lib/libLLVMLanaiAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMLanaiInfo.a /usr/lib/llvm-6.0/lib/libLLVMMipsCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMMipsAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMMipsDesc.a /usr/lib/llvm-6.0/lib/libLLVMMipsAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMMipsDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMMipsInfo.a /usr/lib/llvm-6.0/lib/libLLVMMSP430CodeGen.a /usr/lib/llvm-6.0/lib/libLLVMMSP430Desc.a /usr/lib/llvm-6.0/lib/libLLVMMSP430AsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMMSP430Info.a /usr/lib/llvm-6.0/lib/libLLVMNVPTXCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMipo.a /usr/lib/llvm-6.0/lib/libLLVMIRReader.a /usr/lib/llvm-6.0/lib/libLLVMAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMInstrumentation.a /usr/lib/llvm-6.0/lib/libLLVMLinker.a /usr/lib/llvm-6.0/lib/libLLVMVectorize.a /usr/lib/llvm-6.0/lib/libLLVMNVPTXDesc.a /usr/lib/llvm-6.0/lib/libLLVMNVPTXAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMNVPTXInfo.a /usr/lib/llvm-6.0/lib/libLLVMPowerPCCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMPowerPCAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMPowerPCDesc.a /usr/lib/llvm-6.0/lib/libLLVMPowerPCAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMPowerPCDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMPowerPCInfo.a /usr/lib/llvm-6.0/lib/libLLVMSparcCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMSparcAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMSparcDesc.a /usr/lib/llvm-6.0/lib/libLLVMSparcAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMSparcDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMSparcInfo.a /usr/lib/llvm-6.0/lib/libLLVMSystemZCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMSystemZAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMSystemZDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMSystemZDesc.a /usr/lib/llvm-6.0/lib/libLLVMSystemZAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMSystemZInfo.a /usr/lib/llvm-6.0/lib/libLLVMX86CodeGen.a /usr/lib/llvm-6.0/lib/libLLVMGlobalISel.a /usr/lib/llvm-6.0/lib/libLLVMX86AsmParser.a /usr/lib/llvm-6.0/lib/libLLVMX86Desc.a /usr/lib/llvm-6.0/lib/libLLVMX86AsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMX86Disassembler.a /usr/lib/llvm-6.0/lib/libLLVMX86Info.a /usr/lib/llvm-6.0/lib/libLLVMX86Utils.a /usr/lib/llvm-6.0/lib/libLLVMXCoreCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMXCoreDesc.a /usr/lib/llvm-6.0/lib/libLLVMXCoreAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMXCoreDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMXCoreInfo.a /usr/lib/llvm-6.0/lib/libLLVMWebAssemblyCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMWebAssemblyDesc.a /usr/lib/llvm-6.0/lib/libLLVMWebAssemblyAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMWebAssemblyDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMWebAssemblyInfo.a /usr/lib/llvm-6.0/lib/libLLVMAVRCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMDebugInfoCodeView.a /usr/lib/llvm-6.0/lib/libLLVMDebugInfoMSF.a /usr/lib/llvm-6.0/lib/libLLVMSelectionDAG.a /usr/lib/llvm-6.0/lib/libLLVMCodeGen.a /usr/lib/llvm-6.0/lib/libLLVMBitWriter.a /usr/lib/llvm-6.0/lib/libLLVMScalarOpts.a /usr/lib/llvm-6.0/lib/libLLVMInstCombine.a /usr/lib/llvm-6.0/lib/libLLVMTransformUtils.a /usr/lib/llvm-6.0/lib/libLLVMTarget.a /usr/lib/llvm-6.0/lib/libLLVMAnalysis.a /usr/lib/llvm-6.0/lib/libLLVMObject.a /usr/lib/llvm-6.0/lib/libLLVMBitReader.a /usr/lib/llvm-6.0/lib/libLLVMProfileData.a /usr/lib/llvm-6.0/lib/libLLVMCore.a /usr/lib/llvm-6.0/lib/libLLVMBinaryFormat.a /usr/lib/llvm-6.0/lib/libLLVMAVRAsmParser.a /usr/lib/llvm-6.0/lib/libLLVMMCParser.a /usr/lib/llvm-6.0/lib/libLLVMAVRDesc.a /usr/lib/llvm-6.0/lib/libLLVMAVRAsmPrinter.a /usr/lib/llvm-6.0/lib/libLLVMAVRDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMMCDisassembler.a /usr/lib/llvm-6.0/lib/libLLVMAVRInfo.a /usr/lib/llvm-6.0/lib/libLLVMMC.a /usr/lib/llvm-6.0/lib/libLLVMSupport.a -Wl,-Bstatic -lz -lrt -ldl -ltinfo -lpthread -lm /usr/lib/llvm-6.0/lib/libLLVMDemangle.a
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/libstdc++.a(eh_globals.o): undefined reference to symbol '__tls_get_addr@@GLIBC_2.3'
//lib/x86_64-linux-gnu/ld-linux-x86-64.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

@mmarchini
Copy link
Contributor

Building a static binary is an issue today because only Apline provides the static libclang file (libclang.a). libclang.a is not available on Fedora, Debian, Ubuntu, etc. releases nor in the LLVM official release files.

If we could somehow only rely on partial libclang libraries (libclangBasic and family) we would be able to build static binaries more reliably across different distributions.

@bobrik
Copy link

bobrik commented Jan 11, 2019

I patched llvm build to ship with libclang.a to work around that already, so that issue is solved. The error doesn't seem to complain about that part.

@danobi
Copy link
Member

danobi commented Jan 11, 2019

@bobrik

undefined reference to symbol '__tls_get_addr@@GLIBC_2.3'

What glibc version do you have installed? Best guess at this error is clang is trying to use a versioned symbol your glibc doesn't have.

@danobi
Copy link
Member

danobi commented Jan 11, 2019

On second thought, you probably compiled clang on your machine. A revised guess is you're using two different toolchains on different parts of the build. You need to stick with one.

@brendangregg
Copy link
Contributor Author

What's the path forward? Is this correct?:

  • llvm7 on Ubuntu: it should now just work from the standard repository, as per @vincentbernat . We could update build instructions to recommend llvm7.
  • llvm6 on Ubuntu: requires @bobrik 's patch. Does it make sense to upstream that with llvm6?

@brendangregg
Copy link
Contributor Author

I just tried standard Ubuntu bionic, and it doesn't have llvm 7 packages yet.

So I tried the Ubuntu llvm 6.0 packages, and hit the same error:

(root) /mnt/src/bpftrace/build # cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found LibBcc: /usr/lib/x86_64-linux-gnu/libbcc.so  
-- Found LibElf: /usr/lib/x86_64-linux-gnu/libelf.so  
-- Performing Test ELF_GETSHDRSTRNDX
-- Performing Test ELF_GETSHDRSTRNDX - Success
-- Found BISON: /usr/bin/bison (found version "3.0.4") 
-- Found FLEX: /usr/bin/flex (found version "2.6.4") 
-- Looking for name_to_handle_at
-- Looking for name_to_handle_at - found
CMake Error at CMakeLists.txt:56 (find_package):
  By not providing "FindClang.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Clang", but
  CMake did not find one.

  Could not find a package configuration file provided by "Clang" with any of
  the following names:

    ClangConfig.cmake
    clang-config.cmake

  Add the installation prefix of "Clang" to CMAKE_PREFIX_PATH or set
  "Clang_DIR" to a directory containing one of the above files.  If "Clang"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/mnt/src/bpftrace/build/CMakeFiles/CMakeOutput.log".

so it's not fixed there yet.

I tried @bobrik 's patch, but got:

CMake Error at /usr/share/llvm-6.0/cmake/ClangTargets.cmake:498 (message):
  The imported target "clang-format" references the file

     "/usr/lib/llvm-6.0/bin/clang-format"

  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-6.0/cmake/ClangTargets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /usr/share/llvm-6.0/cmake/ClangConfig.cmake:18 (include)
  CMakeLists.txt:56 (find_package)


-- Configuring incomplete, errors occurred!
See also "/mnt/src/bpftrace/build/CMakeFiles/CMakeOutput.log".

...

If this is fixed in Debian Sid, is the real path forward to get the Ubuntu package mantainers to update their llvm's? If I were to email the right people at Canonical, what should I be asking for? :-)

@vincentbernat
Copy link
Contributor

llvm-7 is available in bionic-proposed. It seems it is scheduled for Bionic 18.04.2: https://bugs.launchpad.net/ubuntu/+source/libdrm/+bug/1798597. It should be available to regular users early February.

@mmarchini mmarchini added help wanted Extra attention is needed build Issues or PRs related to bpftrace building labels Jan 14, 2019
@mmarchini mmarchini added this to the 1.0 milestone Jan 14, 2019
@deeptir18
Copy link

@brendangregg - I was wondering if you found a way past this installation error?
I tried the patch, but got the same error that you listed above.
Thanks!

@brendangregg
Copy link
Contributor Author

I'm currently using the instructions from INSTALL.md for Ubuntu: getting llvm/clang from the llvm.org repositories.

@deeptir18
Copy link

deeptir18 commented Jan 26, 2019

I also run into this error (even when using llvm/clang from the llvm.org repos),
Did you ever see this?

  include could not find load file:

    /usr/lib/cmake/clang/ClangTargets.cmake
Call Stack (most recent call first):
  CMakeLists.txt:58 (find_package)


-- Configuring incomplete, errors occurred!```

@brendangregg
Copy link
Contributor Author

No, I don't think I've seen that before. Hmm. I hope there isn't a new package error you are the first to encounter (those llvm.org repose get updated nightly I believe).

@dalehamel
Copy link
Contributor

I patched llvm build to ship with libclang.a to work around that already, so that issue is solved. The error doesn't seem to complain about that part.

@bobrik would you mind sharing what you've done in #266 as it looks like you got further than I did towards building a static bpftrace on ubuntu, and I think that a static build based on ubuntu (using static libclang) is probably the best way to solve this problem, as it will link glibc instead of musl.

@saurabh83
Copy link

@brendangregg I am getting same error on centos 7.6. Is it possible to get past them?

@fbs
Copy link
Contributor

fbs commented May 1, 2019

llvm-7 is available in bionic-proposed. It seems it is scheduled for Bionic 18.04.2: https://bugs.launchpad.net/ubuntu/+source/libdrm/+bug/1798597. It should be available to regular users early February.

Can confirm that it builds with the new packages. Still need to compile bcc from source however as bcc_usdt.h is missing from bcc shipped with 18.04.

clang-7                         1:7-3~ubuntu0.18.04.1
libclang-7-dev                  1:7-3~ubuntu0.18.04.1
libclang-common-7-dev           1:7-3~ubuntu0.18.04.1
libclang1-7:amd64               1:7-3~ubuntu0.18.04.1
libllvm7:amd64                  1:7-3~ubuntu0.18.04.1
llvm-7                          1:7-3~ubuntu0.18.04.1
llvm-7-dev                      1:7-3~ubuntu0.18.04.1
llvm-7-runtime                  1:7-3~ubuntu0.18.04.1

@mmarchini
Copy link
Contributor

As per #596, this seems to be fixed, so I'll close it. If there's still something to be done here feel free to reopen it.

@bobrik
Copy link

bobrik commented Jul 2, 2019

I was able to build bpfrtrace with llvm-8 and libbcc 0.10 on Debian Stretch, thanks all 🎉

@commander-trashdin
Copy link

I am still unable to build it:

cmake -DCMAKE_INSTALL_PREFIX\=/home/aun/.emacs.d/.local/etc/irony-server/  /home/aun/.emacs.d/.local/straight/build/irony/server && cmake --build . --use-stderr --config Release --target install
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/lib/llvm-7/lib/cmake/clang/ClangTargets.cmake:544 (message):
  The imported target "clangBasic" references the file

     "/usr/lib/llvm-7/lib/libclangBasic.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/lib/llvm-7/lib/cmake/clang/ClangTargets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /usr/lib/cmake/clang-7/ClangConfig.cmake:19 (include)
  src/CMakeLists.txt:4 (find_package)

@danobi
Copy link
Member

danobi commented Dec 10, 2019

@thrashdin Can you file a new issue? And include other info like distro version, installed packages, etc.

@eyalroz
Copy link

eyalroz commented May 28, 2020

@commander-trashdin : Did you ever resolve this ? I've this very issue with another project (doxygen), and it was due to only some of the clang-related packages being installed. when I sudo apt install libclang-7-dev this went away,

@commander-trashdin
Copy link

Yes, I did @eyalroz but I completely forgot how. I am however reasonably sure my solution was very unremarkable and the problem almost somehow resolved itself, i.e. it was some stupid problem.

@NeoJolt
Copy link

NeoJolt commented Jan 13, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues or PRs related to bpftrace building help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.