iovisor / iovisor/bcc

Compiling with CMAKE_USE_LIBBPG_PACKAGE results in linker error

Open
#2,908 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

I'm trying to compile bcc using libbpf packaged on Debian (libbpf0 and libbpf-dev). So I set the above flag while invoking cmake.
```
mkdir build
cd build
cmake .. -DCMAKE_USE_LIBBPF_PACKAGE=1 ...
```
But this ends up with following error
```
[ 23%] Linking CXX shared library libbcc.so
cd /home/vasudeva.sk/Documents/Debian/upstream/bcc/build/src/cc && /usr/bin/cmake -E cmake_link_script CMakeFiles/bcc-shared.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -Wall -fno-rtti -fPIC -DBCC_PROG_TAG_DIR='"/var/tmp/bcc"' -Wno-unused-result -DLLVM_MAJOR_VERSION=9 -O3 -DNDEBUG -static-libstdc++ -Wl,--exclude-libs=libclangFrontend.a -Wl,--exclude-libs=libclangSerialization.a -Wl,--exclude-libs=libclangDriver.a -Wl,--exclude-libs=libclangASTMatchers.a -Wl,--exclude-libs=libclangParse.a -Wl,--exclude-libs=libclangSema.a -Wl,--exclude-libs=libclangCodeGen.a -Wl,--exclude-libs=libclangAnalysis.a -Wl,--exclude-libs=libclangRewrite.a -Wl,--exclude-libs=libclangEdit.a -Wl,--exclude-libs=libclangAST.a -Wl,--exclude-libs=libclangLex.a -Wl,--exclude-libs=libclangBasic.a -Wl,--exclude-libs=libLLVM.a -shared -Wl,-soname,libbcc.so.0 -o libbcc.so.0.14.0 CMakeFiles/bcc-shared.dir/link_all.cc.o CMakeFiles/bcc-shared.dir/bcc_common.cc.o CMakeFiles/bcc-shared.dir/bpf_module.cc.o CMakeFiles/bcc-shared.dir/bcc_btf.cc.o CMakeFiles/bcc-shared.dir/exported_files.cc.o CMakeFiles/bcc-shared.dir/bcc_debug.cc.o CMakeFiles/bcc-shared.dir/bpf_module_rw_engine.cc.o CMakeFiles/bcc-shared.dir/table_storage.cc.o CMakeFiles/bcc-shared.dir/shared_table.cc.o CMakeFiles/bcc-shared.dir/bpffs_table.cc.o CMakeFiles/bcc-shared.dir/json_map_decl_visitor.cc.o CMakeFiles/bcc-shared.dir/bcc_syms.cc.o CMakeFiles/bcc-shared.dir/bcc_elf.c.o CMakeFiles/bcc-shared.dir/bcc_perf_map.c.o CMakeFiles/bcc-shared.dir/bcc_proc.c.o CMakeFiles/bcc-shared.dir/common.cc.o -Wl,-rpath,/usr/lib/llvm-9/lib: frontends/b/libb_frontend.a frontends/clang/libclang_frontend.a -Wl,--whole-archive /usr/lib/llvm-9/lib/libclangFrontend.a /usr/lib/llvm-9/lib/libclangSerialization.a /usr/lib/llvm-9/lib/libclangDriver.a /usr/lib/llvm-9/lib/libclangASTMatchers.a /usr/lib/llvm-9/lib/libclangParse.a /usr/lib/llvm-9/lib/libclangSema.a /usr/lib/llvm-9/lib/libclangCodeGen.a /usr/lib/llvm-9/lib/libclangAnalysis.a /usr/lib/llvm-9/lib/libclangRewrite.a /usr/lib/llvm-9/lib/libclangEdit.a /usr/lib/llvm-9/lib/libclangAST.a /usr/lib/llvm-9/lib/libclangLex.a /usr/lib/llvm-9/lib/libclangBasic.a /usr/lib/llvm-9/lib/libLLVM-9.so.1 -Wl,--no-whole-archive -lelf libbcc_bpf.a -Wl,--whole-archive api/libapi-static.a -Wl,--no-whole-archive usdt/libusdt-static.a
/usr/bin/ld: libbcc_bpf.a(libbpf.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
```
I'm not well versed with cmake to fix this can some one help me in fixing this erorr?. I'm trying to build bcc on Debian without embedding libbpf.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the CMake handling for CMAKE_USE_LIBBPF_PACKAGE and the generated src/cc/CMakeFiles/bcc-shared.dir/link.txt shown in the report. Reproduce the Debian build, inspect how libbcc_bpf.a is compiled and linked, and verify that libbcc.so builds successfully without embedding libbpf.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake, debian, linux
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.