diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -520,8 +520,14 @@ set(LLVM_INTEGRATED_CRT_ALLOC "" CACHE PATH "Replace the Windows CRT allocator with any of {rpmalloc|mimalloc|snmalloc}. Only works with /MT enabled.") if(LLVM_INTEGRATED_CRT_ALLOC) - if(NOT WIN32) - message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows.") + if(NOT (CMAKE_SYSTEM_NAME MATCHES "(Linux|Windows)")) + message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows and Linux.") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + if(NOT (LLVM_INTEGRATED_CRT_ALLOC MATCHES "mimalloc$")) + message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC currently only supports mimalloc on Linux!") + elseif(LLVM_BUILD_LLVM_DYLIB AND LLVM_LINK_LLVM_DYLIB) + message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used with LLVM_LINK_LLVM_DYLIB on Linux!") + endif() endif() if(LLVM_USE_SANITIZER) message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used along with LLVM_USE_SANITIZER!") diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -72,11 +72,18 @@ set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/src/override/malloc.cc" "${LLVM_INTEGRATED_CRT_ALLOC}/src/override/new.cc") set(system_libs ${system_libs} "mincore.lib" "-INCLUDE:malloc") elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "mimalloc$") - set(MIMALLOC_LIB "${LLVM_INTEGRATED_CRT_ALLOC}/out/msvc-x64/Release/mimalloc-static.lib") - if(NOT EXISTS "${MIMALLOC_LIB}") - message(FATAL_ERROR "Cannot find the mimalloc static library. To build it, first apply the patch from https://github.com/microsoft/mimalloc/issues/268 then build the Release x64 target through ${LLVM_INTEGRATED_CRT_ALLOC}\\ide\\vs2019\\mimalloc.sln") + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(MI_OVERRIDE ON CACHE BOOL "Override the standard malloc") + add_subdirectory(${LLVM_INTEGRATED_CRT_ALLOC} mimalloc) + export(EXPORT mimalloc) + set(system_libs ${system_libs} "mimalloc-static") + else() + set(MIMALLOC_LIB "${LLVM_INTEGRATED_CRT_ALLOC}/out/msvc-x64/Release/mimalloc-static.lib") + if(NOT EXISTS "${MIMALLOC_LIB}") + message(FATAL_ERROR "Cannot find the mimalloc static library. To build it, first apply the patch from https://github.com/microsoft/mimalloc/issues/268 then build the Release x64 target through ${LLVM_INTEGRATED_CRT_ALLOC}\\ide\\vs2019\\mimalloc.sln") + endif() + set(system_libs ${system_libs} "${MIMALLOC_LIB}" "-INCLUDE:malloc") endif() - set(system_libs ${system_libs} "${MIMALLOC_LIB}" "-INCLUDE:malloc") endif() endif()