Skip to content

Commit

Permalink
Fix build failure caused by clang version 11.1.0 in Linux (microsoft#…
Browse files Browse the repository at this point in the history
…4191)

Add `HAVE_MALLINFO2` flag and use `mallinfo2` instead of `mallinfo`
when `HAVE_MALLINFO2` flag is enabled.
  • Loading branch information
jaebaek authored Jan 18, 2022
1 parent 0917aa9 commit 46c9735
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ if( HAVE_SYS_UIO_H )
endif()
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(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Config/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
/* Define if mallinfo() is available on this platform. */
#cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO}

/* Define if mallinfo2() is available on this platform. */
#cmakedefine HAVE_MALLINFO2 ${HAVE_MALLINFO2}

/* Define to 1 if you have the <malloc.h> header file. */
#cmakedefine HAVE_MALLOC_H ${HAVE_MALLOC_H}

Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Config/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@
/* Define if mallinfo() is available on this platform. */
#undef HAVE_MALLINFO

/* Define if mallinfo() is available on this platform. */
#undef HAVE_MALLINFO2

/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H

Expand Down
6 changes: 5 additions & 1 deletion lib/Support/Unix/Process.inc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ unsigned Process::getPageSize() {
}

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;
Expand Down

0 comments on commit 46c9735

Please sign in to comment.