[PATCH] D53778: [CMAKE] Specify all_load when exporting symbols from an executable (macOS)

Joe Ranieri via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 4 19:10:45 PST 2018


jranieri-grammatech updated this revision to Diff 172539.
jranieri-grammatech added a comment.

Specify -bundle_loader when giving a PLUGIN_TOOL to add_llvm_loadable_module. This doesn't limit what executables can load the resulting shared library and just informs the static linker what functions will be present when the library is loaded.


https://reviews.llvm.org/D53778

Files:
  cmake/modules/AddLLVM.cmake
  cmake/modules/HandleLLVMOptions.cmake


Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -130,8 +130,6 @@
   if(LLVM_ENABLE_LLD AND LLVM_ENABLE_LTO)
     message(FATAL_ERROR "lld does not support LTO on Darwin")
   endif()
-  # Darwin-specific linker flags for loadable modules.
-  set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
 endif()
 
 # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
Index: cmake/modules/AddLLVM.cmake
===================================================================
--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -671,6 +671,7 @@
 endmacro(add_llvm_library name)
 
 macro(add_llvm_loadable_module name)
+  cmake_parse_arguments(ARG "" "PLUGIN_TOOL" "" ${ARGN})
   llvm_add_library(${name} MODULE ${ARGN})
   if(NOT TARGET ${name})
     # Add empty "phony" target
@@ -701,6 +702,23 @@
       set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
     endif()
   endif()
+  if(APPLE)
+    if(ARG_PLUGIN_TOOL)
+      if(TARGET ${ARG_PLUGIN_TOOL})
+        add_dependencies(${name} ${ARG_PLUGIN_TOOL})
+      endif()
+      set_property(
+        TARGET ${name}
+        APPEND_STRING
+        PROPERTY LINK_FLAGS
+                 " -bundle_loader ${LLVM_TOOLS_BINARY_DIR}/${ARG_PLUGIN_TOOL}")
+    else()
+      set_property(TARGET ${name}
+                   APPEND_STRING
+                   PROPERTY LINK_FLAGS
+                            "  -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
+    endif()
+  endif()
 
   set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
 endmacro(add_llvm_loadable_module name)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53778.172539.patch
Type: text/x-patch
Size: 1785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181105/52880e2e/attachment.bin>


More information about the llvm-commits mailing list