Bug 441125

Summary: Fails to build on CentOS 7.2
Product: [Applications] Heaptrack Reporter: olig9
Component: generalAssignee: Milian Wolff <mail>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: RedHat Enterprise Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description olig9 2021-08-18 09:50:17 UTC
SUMMARY
Current Heaptrack Git version (2a1e0710) fails to build on CentOS 7, due to several build errors.

This happens with CentOS 7.2, g++ 4.8.5 20150623 (Red Hat 4.8.5-4), libdwarf-devel-20130207-4.el7.x86_64, elfutils-devel-0.163-3.el7.x86_64, libunwind-devel-1.1-5.el7.x86_64.


Problem 1): 3rdparty/libbacktrace/dwarf.c build fails because DW_FORM_data16 is undeclared:

[ 14%] Building C object 3rdparty/libbacktrace/CMakeFiles/backtrace.dir/dwarf.c.o
/work/og/inst/heaptrack/3rdparty/libbacktrace/dwarf.c: In function ‘read_attribute’:
/work/og/inst/heaptrack/3rdparty/libbacktrace/dwarf.c:789:10: error: ‘DW_FORM_data16’ undeclared (first use in this function)
     case DW_FORM_data16:
          ^

I suppose the DW_FORM_data16 identifier is not available with the libdwarf version in CentOS 7.2.


Problem 2): I also tried to build a slightly older Heaptrack version (Git 4408287d, from 2021-02-19), but it failed in src/track/trace_libunwind.cpp:

[ 51%] Building CXX object src/track/CMakeFiles/heaptrack_unwind.dir/trace_libunwind.cpp.o
/work/og/inst/heaptrack/src/track/trace_libunwind.cpp: In static member function ‘static void Trace::print()’:
/work/og/inst/heaptrack/src/track/trace_libunwind.cpp:54:40: error: expected ‘)’ before ‘PRIxPTR’
         fprintf(stderr, "#%-2d 0x%016" PRIxPTR " sp=0x%016" PRIxPTR " %s + 0x%" PRIxPTR "\n", frameNr,
                                        ^

Looks like this problem can be solved with this patch:

diff --git a/src/track/trace_libunwind.cpp b/src/track/trace_libunwind.cpp
index c76337c..734c9fd 100644
--- a/src/track/trace_libunwind.cpp
+++ b/src/track/trace_libunwind.cpp
@@ -20,6 +20,9 @@
  * @brief A libunwind based backtrace.
  */
 
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
 #include "trace.h"
 
 #include "util/libunwind_config.h"



STEPS TO REPRODUCE
1. build current Heaptrack Git version on CentOS 7.2, according to instructions from README.md (mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=Release ..; make)

OBSERVED RESULT
Build fails during "make" stage.


EXPECTED RESULT
Build succeeds; or alternatively "cmake" states which libraries are too old.


SOFTWARE/OS VERSIONS
This happens with CentOS 7.2, g++ 4.8.5 20150623 (Red Hat 4.8.5-4), libdwarf-devel-20130207-4.el7.x86_64, elfutils-devel-0.163-3.el7.x86_64, libunwind-devel-1.1-5.el7.x86_64.
Comment 1 Milian Wolff 2021-08-19 08:07:47 UTC
Git commit 925ca2f84f1446c49885916ea991ccb9139fbfcf by Milian Wolff.
Committed on 19/08/2021 at 08:07.
Pushed by mwolff into branch 'master'.

Add copy of dwarf.h with support for DWARF5

The newer libbacktrace version we are shipping is using newer
defines from that header which are not yet available on the dwarf.h
shipped with Centos 7. Thankfully, this header is nicely portable
and self-contained, and licensing (LGPL2.1) should allow shipping
it with our source code too.

Obviously, this now means we'll have to update both, libbacktrace
and libdwarf. But I plan to port heaptrack to use elfutils soon
anyways. At that point, we will be able to remove both again.

M  +1    -8    3rdparty/libbacktrace/CMakeLists.txt
A  +1590 -0    3rdparty/libdwarf/dwarf.h  *
M  +0    -1    README.md
M  +1    -1    tools/Dockerfile

The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://invent.kde.org/sdk/heaptrack/commit/925ca2f84f1446c49885916ea991ccb9139fbfcf
Comment 2 Milian Wolff 2021-08-19 08:07:55 UTC
Git commit af26c60e7e9bc60e7ceb73a09f0151eb81d3881f by Milian Wolff.
Committed on 19/08/2021 at 06:56.
Pushed by mwolff into branch 'master'.

Include cinttypes to ensure PRIxPTR is accessible

IIUC, then we don't need to set __STDC_FORMAT_MACROS as that's
handled by C++ and the cinttypes header for us.

M  +2    -1    src/track/trace_libunwind.cpp

https://invent.kde.org/sdk/heaptrack/commit/af26c60e7e9bc60e7ceb73a09f0151eb81d3881f
Comment 3 olig9 2021-08-19 14:26:37 UTC
Thanks for the fixes! Did some tests just now:

- the change in trace_libunwind.cpp doesn't work yet; apparently cinttypes must be included before libunwind.h.
I guess that libunwind.h includes inttypes.h on its own and therefore any later inclusion of that file is ignored.


- with the default CentOS 7.2 compiler (g++ 4.8.5) there are several build errors:

1)
/work/og/inst/heaptrack/src/track/libheaptrack.cpp:170:61: error: parameter packs not expanded with ‘...’:
  - this looks like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226, ie. a GCC bug


2)
/work/og/inst/heaptrack/src/analyze/accumulatedtracedata.cpp: In lambda function:
/work/og/inst/heaptrack/src/analyze/accumulatedtracedata.cpp:219:61: error: no matching function for call to ‘Suppression::Suppression(<brace-enclosed initializer list>)’
                            return Suppression {pattern, 0, 0};
                                                             ^
  - incomplete C++11 support, I guess?


AFAIK GCC 4.8.5 only has partial support for C++11. I have now used GCC 7.3.1 from RedHats "Developer Toolset 7" suite instead, and after making the change in trace_libunwind.cpp it compiles fine, and "heaptrack ls" works.

Personally I think it is not worth the trouble to support GCC 4.8.5.
I haven't found a good way though to enforce a good compiler though, apart from a hardcoded version check like this:

if (CMAKE_COMPILER_IS_GNUCC)
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3)
        message(FATAL_ERROR "Require at least GCC 7.3")
    endif()
endif()
Comment 4 Milian Wolff 2021-08-20 12:47:00 UTC
the default compiler is too old, you will have to update to a newer one through devtoolset e.g.
Comment 5 Milian Wolff 2021-08-20 15:23:04 UTC
Git commit 6cf21c2817374bbc850c9c93614b7dd73acf1fa4 by Milian Wolff.
Committed on 20/08/2021 at 15:22.
Pushed by mwolff into branch 'master'.

Include cinttypes before libunwind.h

This should fix compilation on Centos 7 with older compilers

M  +3    -3    src/track/trace_libunwind.cpp

https://invent.kde.org/sdk/heaptrack/commit/6cf21c2817374bbc850c9c93614b7dd73acf1fa4