[PATCH] D110317: [Support] Fix mallinfo deprecation warning

Itay Bookstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 23 03:29:57 PDT 2021


nextsilicon-itay-bookstein created this revision.
nextsilicon-itay-bookstein added reviewers: chandlerc, dblaikie, rnk.
Herald added subscribers: dexonsmith, hiraditya, mgorny.
nextsilicon-itay-bookstein requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

mallinfo is deprecated since glibc-2.33, attempt using malloc2
first if available.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110317

Files:
  llvm/cmake/config-ix.cmake
  llvm/lib/Support/Unix/Process.inc


Index: llvm/lib/Support/Unix/Process.inc
===================================================================
--- llvm/lib/Support/Unix/Process.inc
+++ llvm/lib/Support/Unix/Process.inc
@@ -31,7 +31,7 @@
 #if HAVE_SIGNAL_H
 #include <signal.h>
 #endif
-#if defined(HAVE_MALLINFO)
+#if defined(HAVE_MALLINFO2) || defined(HAVE_MALLINFO)
 #include <malloc.h>
 #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;
Index: llvm/cmake/config-ix.cmake
===================================================================
--- llvm/cmake/config-ix.cmake
+++ llvm/cmake/config-ix.cmake
@@ -231,6 +231,7 @@
 check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)
 set(CMAKE_REQUIRED_DEFINITIONS "")
 check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
+check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
                     HAVE_MALLOC_ZONE_STATISTICS)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110317.374496.patch
Type: text/x-patch
Size: 1236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210923/d9f02dc0/attachment.bin>


More information about the llvm-commits mailing list