[libc-commits] [libc] [libc][stdlib] Only use freelist_malloc for baremetal targets. (PR #96355)

via libc-commits libc-commits at lists.llvm.org
Fri Jun 21 13:25:58 PDT 2024


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/96355

None

>From 7d41aeee1f22252df202c61f6ef30fbeb1666ff6 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 21 Jun 2024 20:23:36 +0000
Subject: [PATCH] [libc][stdlib] Only use freelist_malloc for baremetal
 targets.

---
 libc/src/stdlib/CMakeLists.txt         | 24 +++++++++++++++---------
 libc/test/src/__support/CMakeLists.txt |  2 +-
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index 51d53e0d02ea2..7d99fdf38141a 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -380,18 +380,24 @@ elseif(LIBC_TARGET_OS_IS_GPU)
     aligned_alloc
   )
 else()
-  # Only add malloc in full build mode.  Use the system malloc in overlay mode.
-  if(LLVM_LIBC_FULL_BUILD)
+  # Only use freelist malloc for baremetal targets.
+  add_entrypoint_object(
+    freelist_malloc
+    SRCS
+      freelist_malloc.cpp
+    HDRS
+      malloc.h
+    DEPENDS
+      libc.src.__support.freelist_heap
+    COMPILE_OPTIONS
+      -DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
+  )
+  if(LIBC_TARGET_OS_IS_BAREMETAL)
     add_entrypoint_object(
       malloc
-      SRCS
-        freelist_malloc.cpp
-      HDRS
-        malloc.h
+      ALIAS
       DEPENDS
-        libc.src.__support.freelist_heap
-      COMPILE_OPTIONS
-        -DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
+        .freelist_malloc
     )
   else()
     add_entrypoint_external(
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index 082a002959c95..e224e82c922f0 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -36,7 +36,7 @@ if(LLVM_LIBC_FULL_BUILD)
     DEPENDS
       libc.src.__support.CPP.span
       libc.src.__support.freelist_heap
-      libc.src.stdlib.malloc
+      libc.src.stdlib.freelist_malloc
       libc.src.string.memcmp
       libc.src.string.memcpy
   )



More information about the libc-commits mailing list