diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -178,6 +178,19 @@ endif() endif() +# Select whether or not we want to link all built executables against the LLVM +# libc overlay. +set(LLVM_LINK_LIBC_OVERLAY OFF CACHE BOOL "Set to on to link all executables against the LLVM libc overlay") + +if(LLVM_LINK_LIBC_OVERLAY) + # The libc project must be enabled with this option so that we can link + # against the built overlay. + if (NOT "libc" IN_LIST LLVM_ENABLE_PROJECTS) + message(STATUS "Enabling libc project so that the overlay can be used at link time") + list(APPEND LLVM_ENABLE_PROJECTS "libc") + endif() +endif() + # LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the # `LLVM_ENABLE_PROJECTS` CMake cache variable. This exists for # several reasons: diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -1029,6 +1029,10 @@ target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB}) endif() + if (LLVM_LINK_LIBC_OVERLAY) + target_link_libraries(${name} PRIVATE libc) + endif() + llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH}) endmacro(add_llvm_executable name) diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst --- a/llvm/docs/CMake.rst +++ b/llvm/docs/CMake.rst @@ -677,6 +677,12 @@ either be absolute or relative to the *CMAKE_INSTALL_PREFIX*. Defaults to ``${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html``. +**LLVM_LINK_LIBC_OVERLAY**:BOOL + If enabled, LLVM libc will be built using the host compiler and then all + executables generated by the build will first be linked against the LLVM libc + overlay and the remaining unresolved symbols will be filled in by the system + libc. + **LLVM_LINK_LLVM_DYLIB**:BOOL If enabled, tools will be linked with the libLLVM shared library. Defaults to OFF. Setting LLVM_LINK_LLVM_DYLIB to ON also sets LLVM_BUILD_LLVM_DYLIB