[PATCH] D151013: [CMake] Add option to link LLVM/subproject executables

Aiden Grossman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 19 20:37:08 PDT 2023


aidengrossman created this revision.
aidengrossman added reviewers: phosek, sivachandra, lntue.
Herald added a subscriber: ekilmer.
Herald added a project: All.
aidengrossman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch adds in CMake option LLVM_LINK_LIBC_OVERLAY which when set to
true automatically builds LLVM libc in overlay mode and links all
generated executables against the libc overlay.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151013

Files:
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/docs/CMake.rst


Index: llvm/docs/CMake.rst
===================================================================
--- llvm/docs/CMake.rst
+++ 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
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 (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)
 
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151013.523988.patch
Type: text/x-patch
Size: 2152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230520/1eabcc41/attachment.bin>


More information about the llvm-commits mailing list