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 compile error: bcc_elf.c: undefined reference to `debuginfod_begin' #2411

Closed

Conversation

Rtoax
Copy link
Contributor

@Rtoax Rtoax commented Nov 3, 2022

If libdebuginfod is installed on the system and bpftrace is compiled with static linking to BCC (STATIC_BPF_BCC), then libbcc.a requires the dynamic library -ldebuginfod, in which case a compilation error will be reported if bpftrace is compiled without linking libdebuginfod. We just need to add bcc's FindLibDebuginfod.cmake to bpftrace to solve this problem.

How to reproduce the error:

$ sudo dnf install -y elfutils-debuginfod*
$ cd bpftrace
$ mkdir build && cd build
$ ../build-libs.sh
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/ -DCMAKE_BUILD_TYPE=Debug .. $ make -j$(nproc)
...
[ 91%] Linking CXX executable bpftrace
[ 92%] Linking CXX executable bpftrace_test
/usr/bin/ld: ../build-libs/lib64/libbcc.a(bcc_elf.c.o): in function `find_debug_file': bcc_elf.c:(.text+0x10df): undefined reference to `debuginfod_begin' /usr/bin/ld: bcc_elf.c:(.text+0x10fd): undefined reference to `debuginfod_find_debuginfo' /usr/bin/ld: bcc_elf.c:(.text+0x1110): undefined reference to `debuginfod_end' collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/bpftrace.dir/build.make:121: src/bpftrace] Error 1 make[1]: *** [CMakeFiles/Makefile2:1328: src/CMakeFiles/bpftrace.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: ../build-libs/lib64/libbcc.a(bcc_elf.c.o): in function `find_debug_file': bcc_elf.c:(.text+0x10df): undefined reference to `debuginfod_begin' /usr/bin/ld: bcc_elf.c:(.text+0x10fd): undefined reference to `debuginfod_find_debuginfo' /usr/bin/ld: bcc_elf.c:(.text+0x1110): undefined reference to `debuginfod_end' collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/bpftrace_test.dir/build.make:364: tests/bpftrace_test] Error 1 make[1]: *** [CMakeFiles/Makefile2:2230: tests/CMakeFiles/bpftrace_test.dir/all] Error 2 make: *** [Makefile:146: all] Error 2

@Rtoax Rtoax force-pushed the patch-33-cmake-findlibdebuginfod branch from 729aa50 to 44cbb4d Compare November 3, 2022 15:02
If libdebuginfod is installed on the system and bpftrace is compiled with
static linking to BCC (STATIC_BPF_BCC), then libbcc.a requires the dynamic
library -ldebuginfod, in which case a compilation error will be reported if
bpftrace is compiled without linking libdebuginfod. We just need to add
bcc's FindLibDebuginfod.cmake to bpftrace to solve this problem.

How to reproduce the error:

$ sudo dnf install -y elfutils-debuginfod*
$ cd bpftrace
$ mkdir build && cd build
$ ../build-libs.sh
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/ -DCMAKE_BUILD_TYPE=Debug ..
$ make -j$(nproc)
...
[ 91%] Linking CXX executable bpftrace
[ 92%] Linking CXX executable bpftrace_test
/usr/bin/ld: ../build-libs/lib64/libbcc.a(bcc_elf.c.o): in function `find_debug_file':
bcc_elf.c:(.text+0x10df): undefined reference to `debuginfod_begin'
/usr/bin/ld: bcc_elf.c:(.text+0x10fd): undefined reference to `debuginfod_find_debuginfo'
/usr/bin/ld: bcc_elf.c:(.text+0x1110): undefined reference to `debuginfod_end'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/bpftrace.dir/build.make:121: src/bpftrace] Error 1
make[1]: *** [CMakeFiles/Makefile2:1328: src/CMakeFiles/bpftrace.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: ../build-libs/lib64/libbcc.a(bcc_elf.c.o): in function `find_debug_file':
bcc_elf.c:(.text+0x10df): undefined reference to `debuginfod_begin'
/usr/bin/ld: bcc_elf.c:(.text+0x10fd): undefined reference to `debuginfod_find_debuginfo'
/usr/bin/ld: bcc_elf.c:(.text+0x1110): undefined reference to `debuginfod_end'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/bpftrace_test.dir/build.make:364: tests/bpftrace_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2230: tests/CMakeFiles/bpftrace_test.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Signed-off-by: Rong Tao <[email protected]>
@Rtoax Rtoax force-pushed the patch-33-cmake-findlibdebuginfod branch from 44cbb4d to 15edc4b Compare November 3, 2022 15:05
@BurntBrunch
Copy link

BurntBrunch commented Nov 3, 2022

I landed iovisor/bcc#4308 in bcc to add ENABLE_LIBDEBUGINFOD, so we can configure it without it. In general this know-about-all-your-dependencies-trees approach is absolutely unsustainable.

We could use this as an opportunity to test the vendored libs flow:

  1. update the bcc submodule to that commit
  2. use the new flag in build-libs.sh
  3. note somewhere (v0.17 issue?) that we need this commit to make it to an official bcc version before we push out v0.17 (though that's debatable!)

BurntBrunch pushed a commit to BurntBrunch/bpftrace that referenced this pull request Nov 3, 2022
As an alternative to bpftrace#2411, this updates to the exact
commit in bcc that adds ENABLE_LIBDEBUGINFOD and passes that flag in our
local build.

Because we're not using any functionality not in v0.25, this technically
does not raise the minimum bcc version for the bpftrace package -
distros would build against a dynamic, system bcc anyway.
@Rtoax
Copy link
Contributor Author

Rtoax commented Nov 4, 2022

@BurntBrunch thanks a lot, i'll try use ENABLE_LIBDEBUGINFOD.

Rtoax added a commit to Rtoax/bpftrace that referenced this pull request Nov 4, 2022
If libdebuginfod is installed on the system and bpftrace is compiled with static
linking to BCC (STATIC_BPF_BCC), then libbcc.a requires the dynamic library
-ldebuginfod, in which case a compilation error will be reported if bpftrace is
compiled without linking libdebuginfod.

checkout bcc to commit 8c0272979e40("Allow libdebuginfod to be excluded even if
present") and disable libdebuginfod in build-libs.sh, solved undefined reference
to `debuginfod_begin' compile error.

How to reproduce the error:

$ sudo dnf install -y elfutils-debuginfod*
$ cd bpftrace
$ mkdir build && cd build
$ ../build-libs.sh
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/ -DCMAKE_BUILD_TYPE=Debug ..
$ make -j$(nproc)
...
[ 91%] Linking CXX executable bpftrace
[ 92%] Linking CXX executable bpftrace_test
/usr/bin/ld: ../build-libs/lib64/libbcc.a(bcc_elf.c.o): in function `find_debug_file':
bcc_elf.c:(.text+0x10df): undefined reference to `debuginfod_begin'
/usr/bin/ld: bcc_elf.c:(.text+0x10fd): undefined reference to `debuginfod_find_debuginfo'
/usr/bin/ld: bcc_elf.c:(.text+0x1110): undefined reference to `debuginfod_end'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/bpftrace.dir/build.make:121: src/bpftrace] Error 1
make[1]: *** [CMakeFiles/Makefile2:1328: src/CMakeFiles/bpftrace.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: ../build-libs/lib64/libbcc.a(bcc_elf.c.o): in function `find_debug_file':
bcc_elf.c:(.text+0x10df): undefined reference to `debuginfod_begin'
/usr/bin/ld: bcc_elf.c:(.text+0x10fd): undefined reference to `debuginfod_find_debuginfo'
/usr/bin/ld: bcc_elf.c:(.text+0x1110): undefined reference to `debuginfod_end'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/bpftrace_test.dir/build.make:364: tests/bpftrace_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2230: tests/CMakeFiles/bpftrace_test.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Link: bpftrace#2411
Signed-off-by: Rong Tao <[email protected]>
@Rtoax
Copy link
Contributor Author

Rtoax commented Nov 4, 2022

@BurntBrunch @danobi Hi, i just start a new PR #2415, maybe close this PR later.

@BurntBrunch BurntBrunch closed this Nov 4, 2022
BurntBrunch pushed a commit that referenced this pull request Nov 4, 2022
As an alternative to #2411, this updates to the exact
commit in bcc that adds ENABLE_LIBDEBUGINFOD and passes that flag in our
local build.

Because we're not using any functionality not in v0.25, this technically
does not raise the minimum bcc version for the bpftrace package -
distros would build against a dynamic, system bcc anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants