[libc] add option to use SCUDO as the allocator
authorMichael Jones <michaelrj@google.com>
Wed, 21 Jul 2021 22:17:15 +0000 (22:17 +0000)
committerMichael Jones <michaelrj@google.com>
Fri, 23 Jul 2021 17:36:09 +0000 (17:36 +0000)
This patch adds LLVM_LIBC_INCLUDE_SCUDO as a flag. When enabled it
should link in the standalone version of SCUDO as the allocator for LLVM
libc.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106502

libc/CMakeLists.txt
libc/cmake/modules/LLVMLibCLibraryRules.cmake
libc/lib/CMakeLists.txt

index 9e599be..37d996f 100644 (file)
@@ -71,6 +71,13 @@ elseif(LLVM_LIBC_FULL_BUILD)
     (pass -DLLVM_LIBC_ENABLE_LINTING=ON to cmake).")
 endif()
 
+option(LLVM_LIBC_INCLUDE_SCUDO "Include the SCUDO standalone as the allocator for LLVM libc" OFF)
+if(LLVM_LIBC_INCLUDE_SCUDO)
+  if (NOT "compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS)
+    message(FATAL_ERROR "SCUDO cannot be included without adding compiler-rt to LLVM_ENABLE_PROJECTS")
+  endif()
+endif()
+
 include(CMakeParseArguments)
 include(LLVMLibCRules)
 include(LLVMLibCCheckCpuFeatures)
index c863f22..a5dc804 100644 (file)
@@ -42,6 +42,7 @@ endfunction(collect_object_file_deps)
 # Usage:
 #     add_entrypoint_library(
 #       DEPENDS <list of add_entrypoint_object targets>
+#       EXT_DEPS <list of external object targets, no type checking is done>
 #     )
 #
 # NOTE: If one wants an entrypoint to be availabe in a library, then they will
@@ -52,7 +53,7 @@ function(add_entrypoint_library target_name)
     "ENTRYPOINT_LIBRARY"
     "" # No optional arguments
     "" # No single value arguments
-    "DEPENDS" # Multi-value arguments
+    "DEPENDS;EXT_DEPS" # Multi-value arguments
     ${ARGN}
   )
   if(NOT ENTRYPOINT_LIBRARY_DEPENDS)
@@ -76,6 +77,11 @@ function(add_entrypoint_library target_name)
   foreach(dep IN LISTS all_deps)
     list(APPEND objects $<TARGET_OBJECTS:${dep}>)
   endforeach(dep)
+
+  foreach(dep IN LISTS ENTRYPOINT_LIBRARY_EXT_DEPS)
+    list(APPEND objects $<TARGET_OBJECTS:${dep}>)
+  endforeach(dep)
+
   add_library(
     ${target_name}
     STATIC
index c5d48e8..3966658 100644 (file)
@@ -1,7 +1,15 @@
+set(SCUDO_DEP "")
+
+if(LLVM_LIBC_INCLUDE_SCUDO)
+  list(APPEND SCUDO_DEP RTScudoStandalone.${LIBC_TARGET_ARCHITECTURE})
+endif()
+
 add_entrypoint_library(
   llvmlibc
   DEPENDS
   ${TARGET_LLVMLIBC_ENTRYPOINTS}
+  EXT_DEPS
+  ${SCUDO_DEP}
 )
 
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)