diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
|---|---|---|
| committer | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
| commit | 38500d63e14ce340236840f60d356cdefb56a52c (patch) | |
| tree | 17edbec446ce9b50d2f215a483b83afb293a635d /libc/src/stdlib | |
| parent | 1a3d5daaef7a6a63448a497da3eff7fc9e23df26 (diff) | |
| parent | 27f30029741ecf023baece7b3dde1ff9011ffefc (diff) | |
Merge branch 'main' into users/meinersbur/flang_runtime_split-headersusers/meinersbur/flang_runtime_split-headers
Diffstat (limited to 'libc/src/stdlib')
| -rw-r--r-- | libc/src/stdlib/CMakeLists.txt | 38 | ||||
| -rw-r--r-- | libc/src/stdlib/baremetal/CMakeLists.txt | 50 | ||||
| -rw-r--r-- | libc/src/stdlib/baremetal/aligned_alloc.cpp (renamed from libc/src/stdlib/freelist_malloc.cpp) | 23 | ||||
| -rw-r--r-- | libc/src/stdlib/baremetal/calloc.cpp | 21 | ||||
| -rw-r--r-- | libc/src/stdlib/baremetal/free.cpp | 19 | ||||
| -rw-r--r-- | libc/src/stdlib/baremetal/malloc.cpp | 21 | ||||
| -rw-r--r-- | libc/src/stdlib/baremetal/realloc.cpp | 21 |
7 files changed, 143 insertions, 50 deletions
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt index 14d06534a604..40ba9ead9a7a 100644 --- a/libc/src/stdlib/CMakeLists.txt +++ b/libc/src/stdlib/CMakeLists.txt @@ -323,7 +323,7 @@ add_entrypoint_object( .rand_util ) -if(NOT LIBC_TARGET_OS_IS_GPU) +if(NOT LIBC_TARGET_OS_IS_BAREMETAL AND NOT LIBC_TARGET_OS_IS_GPU) if(LLVM_LIBC_INCLUDE_SCUDO) set(SCUDO_DEPS "") @@ -349,7 +349,7 @@ if(NOT LIBC_TARGET_OS_IS_GPU) list(APPEND SCUDO_DEPS RTScudoStandalone.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO} RTScudoStandaloneCWrappers.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}) - + if (COMPILER_RT_BUILD_GWP_ASAN) list(APPEND SCUDO_DEPS RTGwpAsan.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO} @@ -389,32 +389,8 @@ if(NOT LIBC_TARGET_OS_IS_GPU) ${SCUDO_DEPS} ) else() - # 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 - ) - get_target_property(freelist_malloc_is_skipped libc.src.stdlib.freelist_malloc "SKIPPED") - if(LIBC_TARGET_OS_IS_BAREMETAL AND NOT freelist_malloc_is_skipped) - add_entrypoint_object( - malloc - ALIAS - DEPENDS - .freelist_malloc - ) - else() - add_entrypoint_external( - malloc - ) - endif() - add_entrypoint_external( - free + malloc ) add_entrypoint_external( calloc @@ -425,6 +401,12 @@ if(NOT LIBC_TARGET_OS_IS_GPU) add_entrypoint_external( aligned_alloc ) + add_entrypoint_external( + free + ) + add_entrypoint_external( + mallopt + ) endif() endif() @@ -513,7 +495,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) endif() -if(LIBC_TARGET_OS_IS_GPU) +if(LIBC_TARGET_OS_IS_BAREMETAL OR LIBC_TARGET_OS_IS_GPU) add_entrypoint_object( malloc ALIAS diff --git a/libc/src/stdlib/baremetal/CMakeLists.txt b/libc/src/stdlib/baremetal/CMakeLists.txt index 551a83a36b20..67ab1979e4d1 100644 --- a/libc/src/stdlib/baremetal/CMakeLists.txt +++ b/libc/src/stdlib/baremetal/CMakeLists.txt @@ -5,3 +5,53 @@ add_entrypoint_object( HDRS ../abort.h ) + +add_entrypoint_object( + malloc + SRCS + malloc.cpp + HDRS + ../malloc.h + DEPENDS + libc.src.__support.freelist_heap +) + +add_entrypoint_object( + free + SRCS + free.cpp + HDRS + ../free.h + DEPENDS + libc.src.__support.freelist_heap +) + +add_entrypoint_object( + calloc + SRCS + calloc.cpp + HDRS + ../calloc.h + DEPENDS + libc.src.__support.freelist_heap +) + +add_entrypoint_object( + realloc + SRCS + realloc.cpp + HDRS + ../realloc.h + DEPENDS + libc.src.__support.freelist_heap +) + +add_entrypoint_object( + aligned_alloc + SRCS + aligned_alloc.cpp + HDRS + ../aligned_alloc.h + DEPENDS + libc.src.__support.freelist_heap +) diff --git a/libc/src/stdlib/freelist_malloc.cpp b/libc/src/stdlib/baremetal/aligned_alloc.cpp index fe56fad76937..e9548719c3a6 100644 --- a/libc/src/stdlib/freelist_malloc.cpp +++ b/libc/src/stdlib/baremetal/aligned_alloc.cpp @@ -6,35 +6,14 @@ // //===----------------------------------------------------------------------===// +#include "src/stdlib/aligned_alloc.h" #include "src/__support/freelist_heap.h" #include "src/__support/macros/config.h" -#include "src/stdlib/aligned_alloc.h" -#include "src/stdlib/calloc.h" -#include "src/stdlib/free.h" -#include "src/stdlib/malloc.h" -#include "src/stdlib/realloc.h" #include <stddef.h> namespace LIBC_NAMESPACE_DECL { -static LIBC_CONSTINIT FreeListHeap freelist_heap_symbols; -FreeListHeap *freelist_heap = &freelist_heap_symbols; - -LLVM_LIBC_FUNCTION(void *, malloc, (size_t size)) { - return freelist_heap->allocate(size); -} - -LLVM_LIBC_FUNCTION(void, free, (void *ptr)) { return freelist_heap->free(ptr); } - -LLVM_LIBC_FUNCTION(void *, calloc, (size_t num, size_t size)) { - return freelist_heap->calloc(num, size); -} - -LLVM_LIBC_FUNCTION(void *, realloc, (void *ptr, size_t size)) { - return freelist_heap->realloc(ptr, size); -} - LLVM_LIBC_FUNCTION(void *, aligned_alloc, (size_t alignment, size_t size)) { return freelist_heap->aligned_allocate(alignment, size); } diff --git a/libc/src/stdlib/baremetal/calloc.cpp b/libc/src/stdlib/baremetal/calloc.cpp new file mode 100644 index 000000000000..2b3b83cebc8a --- /dev/null +++ b/libc/src/stdlib/baremetal/calloc.cpp @@ -0,0 +1,21 @@ +//===-- Implementation for freelist_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/calloc.h" +#include "src/__support/freelist_heap.h" +#include "src/__support/macros/config.h" + +#include <stddef.h> + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(void *, calloc, (size_t num, size_t size)) { + return freelist_heap->calloc(num, size); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/baremetal/free.cpp b/libc/src/stdlib/baremetal/free.cpp new file mode 100644 index 000000000000..1e25fe5f2dcf --- /dev/null +++ b/libc/src/stdlib/baremetal/free.cpp @@ -0,0 +1,19 @@ +//===-- Implementation for freelist_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/free.h" +#include "src/__support/freelist_heap.h" +#include "src/__support/macros/config.h" + +#include <stddef.h> + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(void, free, (void *ptr)) { return freelist_heap->free(ptr); } + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/baremetal/malloc.cpp b/libc/src/stdlib/baremetal/malloc.cpp new file mode 100644 index 000000000000..a299282667fc --- /dev/null +++ b/libc/src/stdlib/baremetal/malloc.cpp @@ -0,0 +1,21 @@ +//===-- Implementation for freelist_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 "src/__support/freelist_heap.h" +#include "src/__support/macros/config.h" + +#include <stddef.h> + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(void *, malloc, (size_t size)) { + return freelist_heap->allocate(size); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/baremetal/realloc.cpp b/libc/src/stdlib/baremetal/realloc.cpp new file mode 100644 index 000000000000..fb25c68ec429 --- /dev/null +++ b/libc/src/stdlib/baremetal/realloc.cpp @@ -0,0 +1,21 @@ +//===-- Implementation for freelist_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/realloc.h" +#include "src/__support/freelist_heap.h" +#include "src/__support/macros/config.h" + +#include <stddef.h> + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(void *, realloc, (void *ptr, size_t size)) { + return freelist_heap->realloc(ptr, size); +} + +} // namespace LIBC_NAMESPACE_DECL |
