Bug 435155 - Heaptrack 1.2.0 fails to build with libunwind 1.5.0
Summary: Heaptrack 1.2.0 fails to build with libunwind 1.5.0
Status: RESOLVED WORKSFORME
Alias: None
Product: Heaptrack
Classification: Applications
Component: general (other bugs)
Version First Reported In: 1.2.0
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Milian Wolff
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-30 16:01 UTC by Gergely Kun
Modified: 2021-03-31 21:44 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gergely Kun 2021-03-30 16:01:46 UTC
SUMMARY
Heaptrack 1.2.0 fails to build when using a static version of libunwind 1.5.0

STEPS TO REPRODUCE
1. A clean source build of libunwind 1.5.0 prefixed to /heaptrack/build (with the configure options of "--disable-shared --enable-static --disable-coredump --disable-documentation --prefix=/heaptrack/build")
2. curl -L -O https://github.com/KDE/heaptrack/archive/v1.2.0.tar.gz && tar -xzf v1.2.0.tar.gz && cd heaptrack-1.2.0 &&   mkdir build && cd build
3.  PKG_CONFIG_PATH="/heaptrack/build/lib/pkgconfig" cmake -DCMAKE_BUILD_TYPE=Release -DHEAPTRACK_BUILD_PRINT=OFF -DHEAPTRACK_BUILD_GUI=ON -DCMAKE_INSTALL_PREFIX=/heaptrack/build ..
4. make && make install


OBSERVED RESULT
Cmake fails with the cryptic "libunwind is missing" error:

-- The following REQUIRED packages have not been found:

 * Libunwind

CMake Error at /usr/share/cmake/Modules/FeatureSummary.cmake:430 (message):
  feature_summary() Error: REQUIRED package(s) are missing, aborting CMake
  run.
Call Stack (most recent call first):
  CMakeLists.txt:151 (feature_summary)

The following errors appears in the config output:
...
-- Performing Test LIBUNWIND_HAS_UNW_GETCONTEXT
-- Performing Test LIBUNWIND_HAS_UNW_GETCONTEXT - Success
-- Performing Test LIBUNWIND_HAS_UNW_INIT_LOCAL
-- Performing Test LIBUNWIND_HAS_UNW_INIT_LOCAL - Failed
-- Performing Test LIBUNWIND_HAS_UNW_BACKTRACE
-- Performing Test LIBUNWIND_HAS_UNW_BACKTRACE - Failed
-- Performing Test LIBUNWIND_HAS_UNW_BACKTRACE_SKIP
-- Performing Test LIBUNWIND_HAS_UNW_BACKTRACE_SKIP - Failed
-- Performing Test LIBUNWIND_HAS_UNW_SET_CACHE_SIZE
-- Performing Test LIBUNWIND_HAS_UNW_SET_CACHE_SIZE - Failed
-- Could NOT find LibUnwind (missing:  LIBUNWIND_HAS_UNW_BACKTRACE) (found version "1.5")
...


CMakeError.log shows the following errors (among others):
...
Performing C SOURCE FILE Test LIBUNWIND_HAS_UNW_BACKTRACE failed with the following output:
Change Dir: /heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp

Run Build Command:/usr/bin/gmake "cmTryCompileExec3966086559/fast"
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec3966086559.dir/build.make CMakeFiles/cmTryCompileExec3966086559.dir/build
gmake[1]: Entering directory `/heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec3966086559.dir/src.c.o
/usr/bin/cc   -DLIBUNWIND_HAS_UNW_BACKTRACE -I/heaptrack/build/include    -o CMakeFiles/cmTryCompileExec3966086559.dir/src.c.o   -c /heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp/src.c
/heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp/src.c: In function 'main':
/heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp/src.c:3:1: warning: passing argument 1 of 'unw_backtrace' from incompatible pointer type [enabled by default]
 int main() { void* buf[10]; unw_backtrace(&buf, 10); return 0; }
 ^
In file included from /heaptrack/build/include/libunwind-x86_64.h:129:0,
                 from /heaptrack/build/include/libunwind.h:25,
                 from /heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp/src.c:2:
/heaptrack/build/include/libunwind-common.h:290:12: note: expected 'void **' but argument is of type 'void * (*)[10]'
 extern int unw_backtrace (void **, int);
            ^
Linking C executable cmTryCompileExec3966086559
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3966086559.dir/link.txt --verbose=1
/usr/bin/cc   -DLIBUNWIND_HAS_UNW_BACKTRACE    CMakeFiles/cmTryCompileExec3966086559.dir/src.c.o  -o cmTryCompileExec3966086559 -rdynamic /heaptrack/build/lib/libunwind.a
/heaptrack/build/lib/libunwind.a(elf64.o): In function `xz_uncompressed_size':
elf64.c:(.text+0x608): undefined reference to `lzma_stream_footer_decode'
elf64.c:(.text+0x66d): undefined reference to `lzma_index_buffer_decode'
elf64.c:(.text+0x684): undefined reference to `lzma_index_size'
elf64.c:(.text+0x699): undefined reference to `lzma_index_uncompressed_size'
elf64.c:(.text+0x6ae): undefined reference to `lzma_index_end'
/heaptrack/build/lib/libunwind.a(elf64.o): In function `_Uelf64_extract_minidebuginfo':
elf64.c:(.text+0x7f3): undefined reference to `lzma_stream_buffer_decode'
collect2: error: ld returned 1 exit status
gmake[1]: *** [cmTryCompileExec3966086559] Error 1
gmake[1]: Leaving directory `/heaptrack/src/heaptrack-1.2.0/build/CMakeFiles/CMakeTmp'
gmake: *** [cmTryCompileExec3966086559/fast] Error 2

Source file was:
#define UNW_LOCAL_ONLY 1
#include <libunwind.h>
int main() { void* buf[10]; unw_backtrace(&buf, 10); return 0; }
...


EXPECTED RESULT
A successful heaptrack build


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: CentOS 7.9 on an x86_64 system via Docker


ADDITIONAL INFORMATION
Apparently the cmake module FindLibunwind fails to find liblzma on its own, which is all the more puzzling given the fact that pkg-config finds it without any problems whatsoever:
[root@1fb759bd1336 build]# pkg-config --libs liblzma
-llzma
[root@1fb759bd1336 build]#

My solution to the problem was to simply "substitute in" the name of the library into the flags for the CHECK_C_SOURCE_COMPILES macro via sed:
sed -i "s/CMAKE_REQUIRED_LIBRARIES \${LIBUNWIND_LIBRARY}/CMAKE_REQUIRED_LIBRARIES \${LIBUNWIND_LIBRARY} lzma/" cmake/FindLibunwind.cmake

After that the compilation went through fine without any problems whatsoever
Comment 1 Milian Wolff 2021-03-31 21:44:42 UTC
the reason is probably that a static library doesn't automatically pull in its dependencies - and you seem to be linking your static libunwind against a dynamic liblzma. I don't know how to detect this best, quite frankly I think that's a pretty custom setup which requires custom code like you have done. personally I'm always using the shared libraries for libunwind and that works just fine. if you want to improve support for static libs - patches welcome!