[libc-commits] [libc] POC: add snmalloc as an alternative allocator to libc (PR #122284)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Wed Jan 15 22:16:28 PST 2025
https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/122284
>From ddedf1e4b10a9b386fd334c3babcfd604bed6c62 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Thu, 9 Jan 2025 22:57:57 +0800
Subject: [PATCH 1/5] POC: add snmalloc as an alternative allocator to libc
---
libc/src/stdlib/CMakeLists.txt | 41 +++++++++++-
libc/src/stdlib/snmalloc/CMakeLists.txt | 75 ++++++++++++++++++++++
libc/src/stdlib/snmalloc/aligned_alloc.cpp | 0
libc/src/stdlib/snmalloc/calloc.cpp | 0
libc/src/stdlib/snmalloc/free.cpp | 0
libc/src/stdlib/snmalloc/malloc.cpp | 9 +++
libc/src/stdlib/snmalloc/mallopt.cpp | 0
libc/src/stdlib/snmalloc/realloc.cpp | 0
libc/src/stdlib/snmalloc/support.h | 14 ++++
9 files changed, 138 insertions(+), 1 deletion(-)
create mode 100644 libc/src/stdlib/snmalloc/CMakeLists.txt
create mode 100644 libc/src/stdlib/snmalloc/aligned_alloc.cpp
create mode 100644 libc/src/stdlib/snmalloc/calloc.cpp
create mode 100644 libc/src/stdlib/snmalloc/free.cpp
create mode 100644 libc/src/stdlib/snmalloc/malloc.cpp
create mode 100644 libc/src/stdlib/snmalloc/mallopt.cpp
create mode 100644 libc/src/stdlib/snmalloc/realloc.cpp
create mode 100644 libc/src/stdlib/snmalloc/support.h
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index 40ba9ead9a7ae6..7d0dfd1aa9da4b 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -324,7 +324,46 @@ add_entrypoint_object(
)
if(NOT LIBC_TARGET_OS_IS_BAREMETAL AND NOT LIBC_TARGET_OS_IS_GPU)
- if(LLVM_LIBC_INCLUDE_SCUDO)
+ if (NOT "${LLVM_LIBC_INCLUDE_SNMALLOC}" STREQUAL "")
+ message(STATUS "Including snmalloc as the allocator, source directory: ${LLVM_LIBC_INCLUDE_SNMALLOC}")
+ add_subdirectory(snmalloc)
+ add_entrypoint_object(
+ malloc
+ ALIAS
+ DEPENDS
+ .snmalloc.malloc
+ )
+ add_entrypoint_object(
+ calloc
+ ALIAS
+ DEPENDS
+ .snmalloc.calloc
+ )
+ add_entrypoint_object(
+ realloc
+ ALIAS
+ DEPENDS
+ .snmalloc.realloc
+ )
+ add_entrypoint_object(
+ aligned_alloc
+ ALIAS
+ DEPENDS
+ .snmalloc.aligned_alloc
+ )
+ add_entrypoint_object(
+ free
+ ALIAS
+ DEPENDS
+ .snmalloc.free
+ )
+ add_entrypoint_object(
+ mallopt
+ ALIAS
+ DEPENDS
+ .snmalloc.mallopt
+ )
+ elseif(LLVM_LIBC_INCLUDE_SCUDO)
set(SCUDO_DEPS "")
include(${LIBC_SOURCE_DIR}/../compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake)
diff --git a/libc/src/stdlib/snmalloc/CMakeLists.txt b/libc/src/stdlib/snmalloc/CMakeLists.txt
new file mode 100644
index 00000000000000..3971ea42db1744
--- /dev/null
+++ b/libc/src/stdlib/snmalloc/CMakeLists.txt
@@ -0,0 +1,75 @@
+set(SNMALLOC_USE_SELF_VENDORED_STL ON CACHE BOOL "use freestanding snmalloc setup" FORCE)
+set(SNMALLOC_BUILD_TESTING OFF CACHE BOOL "disable snmalloc tests" FORCE)
+set(SNMALLOC_HEADER_ONLY_LIBRARY ON CACHE BOOL "use snmalloc as header only library" FORCE)
+
+# Disable installation
+macro (install)
+endmacro ()
+
+add_subdirectory(${LLVM_LIBC_INCLUDE_SNMALLOC} ${CMAKE_CURRENT_BINARY_DIR}/snmalloc EXCLUDE_FROM_ALL)
+
+target_compile_options(
+ snmalloc
+ INTERFACE
+ -ffreestanding
+ -nostdinc
+ -Wno-newline-eof
+ -Wno-extra-semi
+ -Wno-unused-command-line-argument
+ -Wno-ctad-maybe-unsupported
+ # TODO: define this
+ -DSTDERR_FILENO=2
+ -include ${CMAKE_CURRENT_SOURCE_DIR}/support.h
+ # include_directories does not propagate, use options instead
+ -isystem ${COMPILER_RESOURCE_DIR}/include
+ -isystem ${LIBC_INCLUDE_DIR}
+)
+add_dependencies(snmalloc libc-headers)
+
+add_entrypoint_object(
+ malloc
+ SRCS
+ malloc.cpp
+ DEPENDS
+ snmalloc
+)
+
+add_entrypoint_object(
+ calloc
+ SRCS
+ calloc.cpp
+ DEPENDS
+ snmalloc
+)
+
+add_entrypoint_object(
+ realloc
+ SRCS
+ realloc.cpp
+ DEPENDS
+ snmalloc
+)
+
+add_entrypoint_object(
+ aligned_alloc
+ SRCS
+ aligned_alloc.cpp
+ DEPENDS
+ snmalloc
+)
+
+add_entrypoint_object(
+ free
+ SRCS
+ free.cpp
+ DEPENDS
+ snmalloc
+)
+
+add_entrypoint_object(
+ mallopt
+ SRCS
+ mallopt.cpp
+ DEPENDS
+ snmalloc
+)
diff --git a/libc/src/stdlib/snmalloc/aligned_alloc.cpp b/libc/src/stdlib/snmalloc/aligned_alloc.cpp
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/libc/src/stdlib/snmalloc/calloc.cpp b/libc/src/stdlib/snmalloc/calloc.cpp
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/libc/src/stdlib/snmalloc/free.cpp b/libc/src/stdlib/snmalloc/free.cpp
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/libc/src/stdlib/snmalloc/malloc.cpp b/libc/src/stdlib/snmalloc/malloc.cpp
new file mode 100644
index 00000000000000..644f2eef0ed2bf
--- /dev/null
+++ b/libc/src/stdlib/snmalloc/malloc.cpp
@@ -0,0 +1,9 @@
+#include "src/stdlib/malloc.h"
+#include "snmalloc/snmalloc.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(void *, malloc, (size_t size)) {
+ return snmalloc::libc::malloc(size);
+}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/snmalloc/mallopt.cpp b/libc/src/stdlib/snmalloc/mallopt.cpp
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/libc/src/stdlib/snmalloc/realloc.cpp b/libc/src/stdlib/snmalloc/realloc.cpp
new file mode 100644
index 00000000000000..e69de29bb2d1d6
diff --git a/libc/src/stdlib/snmalloc/support.h b/libc/src/stdlib/snmalloc/support.h
new file mode 100644
index 00000000000000..4909667c1a50d8
--- /dev/null
+++ b/libc/src/stdlib/snmalloc/support.h
@@ -0,0 +1,14 @@
+#include "src/sys/random/getrandom.h"
+
+// TODO: define this
+inline int getentropy(void *buf, size_t size) {
+ while (size > 0) {
+ ssize_t ret = LIBC_NAMESPACE::getrandom(buf, size, 0);
+ if (ret < 0) {
+ return -1;
+ }
+ buf = (char *)buf + ret;
+ size -= ret;
+ }
+ return 0;
+}
>From 96ebfa909efe6f6f31c6a28e99649a586f152404 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Thu, 16 Jan 2025 04:08:22 +0000
Subject: [PATCH 2/5] adjust build
---
libc/src/stdlib/snmalloc/CMakeLists.txt | 2 +-
libc/src/stdlib/snmalloc/free.cpp | 17 +++++++++++++++++
libc/src/stdlib/snmalloc/malloc.cpp | 8 ++++++++
libc/src/stdlib/snmalloc/support.h | 14 --------------
4 files changed, 26 insertions(+), 15 deletions(-)
delete mode 100644 libc/src/stdlib/snmalloc/support.h
diff --git a/libc/src/stdlib/snmalloc/CMakeLists.txt b/libc/src/stdlib/snmalloc/CMakeLists.txt
index 3971ea42db1744..516505c09a13d1 100644
--- a/libc/src/stdlib/snmalloc/CMakeLists.txt
+++ b/libc/src/stdlib/snmalloc/CMakeLists.txt
@@ -19,7 +19,7 @@ target_compile_options(
-Wno-ctad-maybe-unsupported
# TODO: define this
-DSTDERR_FILENO=2
- -include ${CMAKE_CURRENT_SOURCE_DIR}/support.h
+ -DSNMALLOC_USE_PTHREAD_DESTRUCTORS
# include_directories does not propagate, use options instead
-isystem ${COMPILER_RESOURCE_DIR}/include
-isystem ${LIBC_INCLUDE_DIR}
diff --git a/libc/src/stdlib/snmalloc/free.cpp b/libc/src/stdlib/snmalloc/free.cpp
index e69de29bb2d1d6..a3160c15d0df38 100644
--- a/libc/src/stdlib/snmalloc/free.cpp
+++ b/libc/src/stdlib/snmalloc/free.cpp
@@ -0,0 +1,17 @@
+//===-- Implementation of free --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdlib/free.h"
+#include "snmalloc/snmalloc.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(void, free, (void * ptr)) {
+ return snmalloc::libc::free(ptr);
+}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/snmalloc/malloc.cpp b/libc/src/stdlib/snmalloc/malloc.cpp
index 644f2eef0ed2bf..ab58e63743016a 100644
--- a/libc/src/stdlib/snmalloc/malloc.cpp
+++ b/libc/src/stdlib/snmalloc/malloc.cpp
@@ -1,3 +1,11 @@
+//===-- Implementation of malloc ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
#include "src/stdlib/malloc.h"
#include "snmalloc/snmalloc.h"
#include "src/__support/common.h"
diff --git a/libc/src/stdlib/snmalloc/support.h b/libc/src/stdlib/snmalloc/support.h
deleted file mode 100644
index 4909667c1a50d8..00000000000000
--- a/libc/src/stdlib/snmalloc/support.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "src/sys/random/getrandom.h"
-
-// TODO: define this
-inline int getentropy(void *buf, size_t size) {
- while (size > 0) {
- ssize_t ret = LIBC_NAMESPACE::getrandom(buf, size, 0);
- if (ret < 0) {
- return -1;
- }
- buf = (char *)buf + ret;
- size -= ret;
- }
- return 0;
-}
>From bc6eb843e3cff098a20adde7f408d8a7d38e9915 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Thu, 16 Jan 2025 04:26:12 +0000
Subject: [PATCH 3/5] implement all symbols
---
libc/src/stdlib/snmalloc/aligned_alloc.cpp | 17 +++++++++++++++++
libc/src/stdlib/snmalloc/calloc.cpp | 17 +++++++++++++++++
libc/src/stdlib/snmalloc/free.cpp | 2 +-
libc/src/stdlib/snmalloc/mallopt.cpp | 13 +++++++++++++
libc/src/stdlib/snmalloc/realloc.cpp | 17 +++++++++++++++++
5 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/libc/src/stdlib/snmalloc/aligned_alloc.cpp b/libc/src/stdlib/snmalloc/aligned_alloc.cpp
index e69de29bb2d1d6..ee1d74ca9c778c 100644
--- a/libc/src/stdlib/snmalloc/aligned_alloc.cpp
+++ b/libc/src/stdlib/snmalloc/aligned_alloc.cpp
@@ -0,0 +1,17 @@
+//===-- Implementation of aligned_alloc -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdlib/aligned_alloc.h"
+#include "snmalloc/snmalloc.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(void *, aligned_alloc, (size_t alignment, size_t size)) {
+ return snmalloc::libc::aligned_alloc(alignment, size);
+}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/snmalloc/calloc.cpp b/libc/src/stdlib/snmalloc/calloc.cpp
index e69de29bb2d1d6..39af67607bf709 100644
--- a/libc/src/stdlib/snmalloc/calloc.cpp
+++ b/libc/src/stdlib/snmalloc/calloc.cpp
@@ -0,0 +1,17 @@
+//===-- Implementation of calloc ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdlib/calloc.h"
+#include "snmalloc/snmalloc.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(void *, calloc, (size_t num, size_t size)) {
+ return snmalloc::libc::calloc(num, size);
+}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/snmalloc/free.cpp b/libc/src/stdlib/snmalloc/free.cpp
index a3160c15d0df38..eb403710fffada 100644
--- a/libc/src/stdlib/snmalloc/free.cpp
+++ b/libc/src/stdlib/snmalloc/free.cpp
@@ -11,7 +11,7 @@
#include "src/__support/common.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(void, free, (void * ptr)) {
+LLVM_LIBC_FUNCTION(void, free, (void *ptr)) {
return snmalloc::libc::free(ptr);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/snmalloc/mallopt.cpp b/libc/src/stdlib/snmalloc/mallopt.cpp
index e69de29bb2d1d6..c52d68e3d52230 100644
--- a/libc/src/stdlib/snmalloc/mallopt.cpp
+++ b/libc/src/stdlib/snmalloc/mallopt.cpp
@@ -0,0 +1,13 @@
+//===-- Implementation of mallopt stub ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(int, mallopt, (int, int)) { return 0; }
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/snmalloc/realloc.cpp b/libc/src/stdlib/snmalloc/realloc.cpp
index e69de29bb2d1d6..36972e0a2232ec 100644
--- a/libc/src/stdlib/snmalloc/realloc.cpp
+++ b/libc/src/stdlib/snmalloc/realloc.cpp
@@ -0,0 +1,17 @@
+//===-- Implementation of realloc -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdlib/realloc.h"
+#include "snmalloc/snmalloc.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(void *, realloc, (void *ptr, size_t size)) {
+ return snmalloc::libc::realloc(ptr, size);
+}
+} // namespace LIBC_NAMESPACE_DECL
>From 5f6651d0c0a8d7cfc270bca198cc5db9b09c8f45 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Thu, 16 Jan 2025 05:09:37 +0000
Subject: [PATCH 4/5] setup dependencies
---
libc/src/stdlib/snmalloc/CMakeLists.txt | 43 +++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/libc/src/stdlib/snmalloc/CMakeLists.txt b/libc/src/stdlib/snmalloc/CMakeLists.txt
index 516505c09a13d1..cc7172c947c4c2 100644
--- a/libc/src/stdlib/snmalloc/CMakeLists.txt
+++ b/libc/src/stdlib/snmalloc/CMakeLists.txt
@@ -24,8 +24,46 @@ target_compile_options(
-isystem ${COMPILER_RESOURCE_DIR}/include
-isystem ${LIBC_INCLUDE_DIR}
)
+
add_dependencies(snmalloc libc-headers)
+set(SNMALLOC_DEPS
+ # includes
+ libc.include.errno
+ libc.include.fcntl
+ libc.include.limits
+ libc.include.pthread
+ libc.include.stdio
+ libc.include.stdint
+ libc.include.stdlib
+ libc.include.string
+ libc.include.strings
+ libc.include.sys_mman
+ libc.include.sys_prctl
+ libc.include.sys_random
+ libc.include.sys_syscall
+ libc.include.sys_uio
+ libc.include.unistd
+ # symbols
+ libc.src.errno.errno
+ libc.src.fcntl.open
+ libc.src.pthread.pthread_key_create
+ libc.src.pthread.pthread_setspecific
+ libc.src.stdlib.abort
+ libc.src.stdlib.atexit
+ libc.src.string.memset
+ libc.src.string.strlen
+ libc.src.sys.mman.madvise
+ libc.src.sys.mman.mmap
+ libc.src.sys.uio.writev
+ libc.src.time.clock_gettime
+ libc.src.unistd.__llvm_libc_syscall
+ libc.src.unistd.close
+ libc.src.unistd.fsync
+ libc.src.unistd.getentropy
+ libc.src.unistd.read
+)
+
add_entrypoint_object(
malloc
SRCS
@@ -40,6 +78,7 @@ add_entrypoint_object(
calloc.cpp
DEPENDS
snmalloc
+ ${SNMALLOC_DEPS}
)
add_entrypoint_object(
@@ -48,6 +87,7 @@ add_entrypoint_object(
realloc.cpp
DEPENDS
snmalloc
+ ${SNMALLOC_DEPS}
)
add_entrypoint_object(
@@ -56,6 +96,7 @@ add_entrypoint_object(
aligned_alloc.cpp
DEPENDS
snmalloc
+ ${SNMALLOC_DEPS}
)
add_entrypoint_object(
@@ -64,6 +105,7 @@ add_entrypoint_object(
free.cpp
DEPENDS
snmalloc
+ ${SNMALLOC_DEPS}
)
add_entrypoint_object(
@@ -72,4 +114,5 @@ add_entrypoint_object(
mallopt.cpp
DEPENDS
snmalloc
+ ${SNMALLOC_DEPS}
)
>From 1382389b1f693f98f9b253ef53ee6a8985350899 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Thu, 16 Jan 2025 06:12:42 +0000
Subject: [PATCH 5/5] make hermetic build pass with snmalloc
---
libc/src/stdlib/snmalloc/CMakeLists.txt | 1 +
libc/src/stdlib/snmalloc/override.h | 32 +++++++++++++++++++++++++
libc/test/src/stdlib/CMakeLists.txt | 4 +++-
3 files changed, 36 insertions(+), 1 deletion(-)
create mode 100644 libc/src/stdlib/snmalloc/override.h
diff --git a/libc/src/stdlib/snmalloc/CMakeLists.txt b/libc/src/stdlib/snmalloc/CMakeLists.txt
index cc7172c947c4c2..e360b36f5fb3ad 100644
--- a/libc/src/stdlib/snmalloc/CMakeLists.txt
+++ b/libc/src/stdlib/snmalloc/CMakeLists.txt
@@ -21,6 +21,7 @@ target_compile_options(
-DSTDERR_FILENO=2
-DSNMALLOC_USE_PTHREAD_DESTRUCTORS
# include_directories does not propagate, use options instead
+ -include ${CMAKE_CURRENT_SOURCE_DIR}/override.h
-isystem ${COMPILER_RESOURCE_DIR}/include
-isystem ${LIBC_INCLUDE_DIR}
)
diff --git a/libc/src/stdlib/snmalloc/override.h b/libc/src/stdlib/snmalloc/override.h
new file mode 100644
index 00000000000000..a36a6316790fbd
--- /dev/null
+++ b/libc/src/stdlib/snmalloc/override.h
@@ -0,0 +1,32 @@
+//===-- Macro Override for SnMalloc ---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// skip special headers
+#define LLVM_LIBC_COMMON_H
+#define LLVM_LIBC_ERRNO_H
+
+// define common macros
+#define __BEGIN_C_DECLS namespace LIBC_NAMESPACE {
+#define __END_C_DECLS \
+ } \
+ using namespace LIBC_NAMESPACE;
+
+#define _Noreturn [[noreturn]]
+#define _Alignas alignas
+#define _Static_assert static_assert
+#define _Alignof alignof
+#define _Thread_local thread_local
+
+// Use empty definition to avoid spec mismatching
+// We are building internally anyway, hence noexcept does not matter here
+#define __NOEXCEPT
+
+// Enforce internal errno implementation
+#include "hdr/errno_macros.h"
+#include "src/errno/libc_errno.h"
+#define errno libc_errno
diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index 8cc0428632ba39..2346a8bae08f87 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -420,7 +420,9 @@ if(LLVM_LIBC_FULL_BUILD)
)
# Only baremetal and GPU has an in-tree 'malloc' implementation.
- if(LIBC_TARGET_OS_IS_BAREMETAL OR LIBC_TARGET_OS_IS_GPU)
+ if(LIBC_TARGET_OS_IS_BAREMETAL
+ OR LIBC_TARGET_OS_IS_GPU
+ OR NOT "${LLVM_LIBC_INCLUDE_SNMALLOC}" STREQUAL "")
add_libc_test(
malloc_test
HERMETIC_TEST_ONLY
More information about the libc-commits
mailing list