[libc-commits] [libc] 7eb5cb7 - [libc] Fix allocator inclusion
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Fri Feb 11 14:58:27 PST 2022
Author: Michael Jones
Date: 2022-02-11T14:58:21-08:00
New Revision: 7eb5cb7f9e35bb1545804ce989baccd46748a374
URL: https://github.com/llvm/llvm-project/commit/7eb5cb7f9e35bb1545804ce989baccd46748a374
DIFF: https://github.com/llvm/llvm-project/commit/7eb5cb7f9e35bb1545804ce989baccd46748a374.diff
LOG: [libc] Fix allocator inclusion
Previously, allocator functions were only available if they were included
from scudo or by using the system libc headers (i.e. by turning off the
full build). This patch changes the logic to include the prototypes for
the allocator functitons in all cases, which allows the linker to link
in the system's allocator.
Reviewed By: sivachandra, abrachet
Differential Revision: https://reviews.llvm.org/D119587
Added:
Modified:
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/src/__support/CPP/CMakeLists.txt
libc/src/stdlib/CMakeLists.txt
libc/test/utils/CPP/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 8575ab8f048da..c80e6bee82b76 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -55,6 +55,10 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok
libc.src.string.strtok_r
+ # string.h entrypoints that depend on malloc
+ libc.src.string.strdup
+ libc.src.string.strndup
+
# inttypes.h entrypoints
libc.src.inttypes.imaxdiv
libc.src.inttypes.strtoimax
@@ -81,6 +85,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.strtoul
libc.src.stdlib.strtoull
+ # stdlib.h external entrypoints
+ libc.src.stdlib.malloc
+ libc.src.stdlib.calloc
+ libc.src.stdlib.realloc
+ libc.src.stdlib.free
+
# sys/stat.h entrypoints
libc.src.sys.stat.mkdir
libc.src.sys.stat.mkdirat
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 3de1e6ef72adc..f21d032464dc4 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -55,6 +55,10 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok
libc.src.string.strtok_r
+ # string.h entrypoints that depend on malloc
+ libc.src.string.strdup
+ libc.src.string.strndup
+
# inttypes.h entrypoints
libc.src.inttypes.imaxdiv
libc.src.inttypes.strtoimax
@@ -81,6 +85,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.strtoul
libc.src.stdlib.strtoull
+ # stdlib.h external entrypoints
+ libc.src.stdlib.malloc
+ libc.src.stdlib.calloc
+ libc.src.stdlib.realloc
+ libc.src.stdlib.free
+
# sys/mman.h entrypoints
libc.src.sys.mman.mmap
libc.src.sys.mman.munmap
@@ -251,25 +261,6 @@ if(LLVM_LIBC_FULL_BUILD)
)
endif()
-if(LLVM_LIBC_INCLUDE_SCUDO)
- list(APPEND TARGET_LIBC_ENTRYPOINTS
-
- # stdlib.h external entrypoints
- libc.src.stdlib.malloc
- libc.src.stdlib.calloc
- libc.src.stdlib.realloc
- libc.src.stdlib.free
- )
-endif()
-
-if(LLVM_LIBC_INCLUDE_SCUDO OR NOT LLVM_LIBC_FULL_BUILD)
- list(APPEND TARGET_LIBC_ENTRYPOINTS
- # string.h entrypoints that depend on malloc
- libc.src.string.strdup
- libc.src.string.strndup
- )
-endif()
-
set(TARGET_LLVMLIBC_ENTRYPOINTS
${TARGET_LIBC_ENTRYPOINTS}
${TARGET_LIBM_ENTRYPOINTS}
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index 8a61fc76922f9..b591734a6b6f6 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -12,12 +12,10 @@ add_header_library(
TypeTraits.h
)
-if(LLVM_LIBC_INCLUDE_SCUDO OR NOT LLVM_LIBC_FULL_BUILD)
- add_header_library(
- vector
- HDRS
- vector.h
- DEPENDS
- libc.include.stdlib
- )
-endif()
+add_header_library(
+ vector
+ HDRS
+ vector.h
+ DEPENDS
+ libc.include.stdlib
+)
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index b333def651e64..cb3aeb8089493 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -230,7 +230,19 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
DEPENDS
${SCUDO_DEPS}
)
-
+else()
+ add_entrypoint_external(
+ malloc
+ )
+ add_entrypoint_external(
+ calloc
+ )
+ add_entrypoint_external(
+ realloc
+ )
+ add_entrypoint_external(
+ free
+ )
endif()
if(NOT LLVM_LIBC_FULL_BUILD)
diff --git a/libc/test/utils/CPP/CMakeLists.txt b/libc/test/utils/CPP/CMakeLists.txt
index a02636a07abb4..7d4f15b7af5c5 100644
--- a/libc/test/utils/CPP/CMakeLists.txt
+++ b/libc/test/utils/CPP/CMakeLists.txt
@@ -40,14 +40,12 @@ add_libc_unittest(
libc.src.__support.CPP.standalone_cpp
)
-if(LLVM_LIBC_INCLUDE_SCUDO OR NOT LLVM_LIBC_FULL_BUILD)
- add_libc_unittest(
- vector_test
- SUITE
- libc_cpp_utils_unittests
- SRCS
- vector_test.cpp
- DEPENDS
- libc.src.__support.CPP.vector
- )
-endif()
+add_libc_unittest(
+ vector_test
+ SUITE
+ libc_cpp_utils_unittests
+ SRCS
+ vector_test.cpp
+ DEPENDS
+ libc.src.__support.CPP.vector
+)
More information about the libc-commits
mailing list