Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -1029,6 +1029,10 @@ target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB}) endif() + if(CXX_LINKER_SUPPORTS_LLVM_LIBC) + target_link_libraries(${name} PRIVATE llvmlibc) + endif() + llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH}) endmacro(add_llvm_executable name) Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -1300,3 +1300,13 @@ set(LLVM_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party CACHE STRING "Directory containing third party software used by LLVM (e.g. googletest)") + +set(LLVM_ENABLE_LLVM_LIBC OFF CACHE BOOL "Set to on to link all LLVM executables against LLVM libc, assuming it is accessible by the host compiler") + +if(LLVM_ENABLE_LLVM_LIBC) + include(CheckCXXCompilerFlag) + llvm_check_linker_flag(CXX "-lllvmlibc" CXX_LINKER_SUPPORTS_LLVM_LIBC) + if(NOT CXX_LINKER_SUPPORTS_LLVM_LIBC) + message(WARNING "Unable to link against LLVM libc. LLVM will be built without linking against the LLVM libc overlay.") + endif() +endif() Index: llvm/docs/CMake.rst =================================================================== --- llvm/docs/CMake.rst +++ llvm/docs/CMake.rst @@ -509,6 +509,11 @@ passed to invocations of both so that the project is built using libc++ instead of stdlibc++. Defaults to OFF. +**LLVM_ENABLE_LLVM_LIBC**: BOOL + If the LLVM libc overlay is installed in a location where the host linker + can access it, all built executables will be linked against the LLVM libc + overlay before linking against the system libc. Defaults to OFF. + **LLVM_ENABLE_LIBPFM**:BOOL Enable building with libpfm to support hardware counter measurements in LLVM tools.