Fix compile errors on Ubuntu 17.10 (#29)
authorAndrey Kvochko/SRR-Compiler Lab/./삼성전자 <a.kvochko@samsung.com>
Thu, 15 Feb 2018 09:19:20 +0000 (12:19 +0300)
committerDmitri Botcharnikov/SRR-Compiler Lab/./삼성전자 <dmitry.b@samsung.com>
Thu, 15 Feb 2018 09:19:20 +0000 (12:19 +0300)
* Use check_symbol_exists() to check if cfree() is available

Thanks to Daniel Vratil for the initial work.

heaptrack now compiles on Fedora rawhide and Arch Linux x86_64
with glibc 2.26 or newer.

Differential Revision: https://phabricator.kde.org/D7621

* Move Docker build to Ubuntu 17.10

CMakeLists.txt
Dockerfile
src/track/heaptrack_inject.cpp
src/track/heaptrack_preload.cpp
src/util/config.h.cmake
tests/manual/CMakeLists.txt
tests/manual/test.cpp

index ca00270..73913f9 100644 (file)
@@ -79,6 +79,11 @@ check_cxx_source_compiles(
     int main() { return 0; }"
     HAVE_FUTURE_SUPPORT)
 
+# cfree() does not exist in glibc 2.26+.
+# See: https://bugs.kde.org/show_bug.cgi?id=383889
+include(CheckSymbolExists)
+check_symbol_exists(cfree malloc.h HAVE_CFREE)
+
 set(BIN_INSTALL_DIR "bin")
 set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)")
 set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
index 446a730..c823f4a 100644 (file)
@@ -1,4 +1,4 @@
-FROM ubuntu:17.04
+FROM ubuntu:17.10
 
 RUN apt-get update && apt-get -y install cmake libsparsehash-dev \
   build-essential libunwind8-dev libunwind8 libboost-dev \
@@ -7,8 +7,8 @@ RUN apt-get update && apt-get -y install cmake libsparsehash-dev \
   libkf5coreaddons-dev libkf5i18n-dev libkf5itemmodels-dev \
   libkf5threadweaver-dev libkf5configwidgets-dev libkf5kiocore5 \
   libkf5kiowidgets5 kio-dev cpio rpm2cpio clang libkchart2 \
-  libkchart-dev binutils-arm-linux-gnueabi gcc-arm-linux-gnueabi gettext \
-  g++-arm-linux-gnueabi wget
+  libkchart-dev binutils-arm-linux-gnueabi gcc-6-arm-linux-gnueabi gettext \
+  g++-6-arm-linux-gnueabi wget
 
 #prepare folder structure
 RUN mkdir -p /rootfs/rpms && \
@@ -56,7 +56,7 @@ RUN cd /heaptrack/build-x64 && cmake .. && make -j4 && cp -r bin lib \
     /heaptrack-common/x64
 #build armel heaptrack collection modules without GUI
 RUN cd /heaptrack/build-armel && \
-    CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ CPLUS_INCLUDE_PATH=/rootfs/usr/lib/gcc/armv7l-tizen-linux-gnueabi/6.2.1/include/c++:/rootfs/usr/lib/gcc/armv7l-tizen-linux-gnueabi/6.2.1/include/c++/armv7l-tizen-linux-gnueabi cmake .. -DHEAPTRACK_BUILD_GUI=OFF -DCMAKE_TOOLCHAIN_FILE=/heaptrack/profiler/profiler/cross/armel/toolchain.cmake && \
+    CC=arm-linux-gnueabi-gcc-6 CXX=arm-linux-gnueabi-g++-6 CPLUS_INCLUDE_PATH=/rootfs/usr/lib/gcc/armv7l-tizen-linux-gnueabi/6.2.1/include/c++:/rootfs/usr/lib/gcc/armv7l-tizen-linux-gnueabi/6.2.1/include/c++/armv7l-tizen-linux-gnueabi cmake .. -DHEAPTRACK_BUILD_GUI=OFF -DCMAKE_TOOLCHAIN_FILE=/heaptrack/profiler/profiler/cross/armel/toolchain.cmake && \
     make -j4 && cp -r bin lib /heaptrack-common/armel
 #build managed profiler module
 ARG ARCH=""
index 6265da7..84cc671 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "libheaptrack.h"
+#include "util/config.h"
 
 #include <cstdlib>
 #include <cstring>
 #error unsupported word size
 #endif
 
-#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(__USE_MISC)
-#define HAVE_CFREE 1
-#else
-#define HAVE_CFREE 0
-#endif
-
 namespace {
 
 namespace Elf {
index 177e01d..980831a 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "libheaptrack.h"
+#include "util/config.h"
 
 #include <cstdio>
 #include <cstdlib>
@@ -37,11 +38,6 @@ using namespace std;
 #else
 #  define HAVE_ALIGNED_ALLOC 0
 #endif
-#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(__USE_MISC)
-#  define HAVE_CFREE 1
-#else
-#  define HAVE_CFREE 0
-#endif
 
 extern "C" {
 __attribute__((weak)) void __libc_freeres();
index 7bad362..861c1f7 100644 (file)
@@ -29,4 +29,8 @@
 
 #define HEAPTRACK_DEBUG_BUILD @HEAPTRACK_DEBUG_BUILD@
 
+// cfree() does not exist in glibc 2.26+.
+// See: https://bugs.kde.org/show_bug.cgi?id=383889
+#cmakedefine01 HAVE_CFREE
+
 #endif // HEAPTRACK_CONFIG_H
index 8811837..05c056f 100644 (file)
@@ -8,6 +8,10 @@ if (HAVE_FUTURE_SUPPORT)
     target_link_libraries(threaded ${CMAKE_THREAD_LIBS_INIT})
 endif()
 
+set_target_properties(test_cpp PROPERTIES
+  INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/../../src/
+)
+
 add_executable(callgraph callgraph.cpp)
 
 add_library(testlib SHARED lib.cpp)
index a77dbd7..4c7b0d2 100644 (file)
@@ -19,6 +19,8 @@
 #include <cstdio>
 #include <cstdlib>
 
+#include "util/config.h"
+
 #if defined(_ISOC11_SOURCE)
 #  define HAVE_ALIGNED_ALLOC 1
 #else
@@ -82,7 +84,11 @@ int main()
 
     buf = calloc(5, 5);
     printf("calloc: %p\n", buf);
+#if HAVE_CFREE
     cfree(buf);
+#else
+    free(buf);
+#endif
 
 #if HAVE_ALIGNED_ALLOC
     buf = aligned_alloc(16, 160);