diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -232,6 +232,7 @@ set(CMAKE_REQUIRED_DEFINITIONS "") check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL) check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) +check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2) check_symbol_exists(malloc_zone_statistics malloc/malloc.h HAVE_MALLOC_ZONE_STATISTICS) check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT) diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -136,6 +136,9 @@ /* Define to 1 if you have the `mallinfo' function. */ #cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO} +/* Define to 1 if you have the `mallinfo2' function. */ +#cmakedefine HAVE_MALLINFO2 ${HAVE_MALLINFO2} + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_MALLOC_MALLOC_H ${HAVE_MALLOC_MALLOC_H} diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -31,7 +31,7 @@ #if HAVE_SIGNAL_H #include #endif -#if defined(HAVE_MALLINFO) +#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2) #include #endif #if defined(HAVE_MALLCTL) @@ -89,7 +89,11 @@ } size_t Process::GetMallocUsage() { -#if defined(HAVE_MALLINFO) +#if defined(HAVE_MALLINFO2) + struct mallinfo2 mi; + mi = ::mallinfo2(); + return mi.uordblks; +#elif defined(HAVE_MALLINFO) struct mallinfo mi; mi = ::mallinfo(); return mi.uordblks;