[PATCH] D72372: [CMake] Force static linking for registered plugins on Windows.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 15:53:37 PST 2020


Meinersbur created this revision.
Meinersbur added reviewers: serge-sans-paille, MaskRay, fhahn.
Herald added a subscriber: mgorny.
Herald added a project: LLVM.

Pass plugins introduced D61446 <https://reviews.llvm.org/D61446> do not support dynamic linking on Windows, hence the option `LLVM_${name_upper}_LINK_INTO_TOOLS` can only work being set to "ON". Currently, it defaults to "OFF" such that such plugins are inoperable by default on Windows.

Note that it might be possible to support a DLL-plugin infrastructure on Windows if the LLVM symbols are itself in a DLL that is loaded by the executable (BUILD_SHARED_LIBS or LLVM_LINK_LLVM_DYLIB). However, DLLs also have a maximum of 65535 exported symbols, fewer than LLVM actually exports, i.e. both of the are also unsupported in Windows.


https://reviews.llvm.org/D72372

Files:
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -855,7 +855,17 @@
 
   string(TOUPPER ${name} name_upper)
 
-  option(LLVM_${name_upper}_LINK_INTO_TOOLS "Statically link ${name} into tools (if available)" OFF)
+  if (WIN32)
+    # Dynamically linked pass plugins are not supported on Windows: the plugin
+    # DLL needs to specify for each symbol from the LLVM framework from which
+    # file it is imported, which in case of statically linked executables is
+    # different for each tool (opt, bugpoint, clang, ...).
+    # See llvm/lib/Transforms/Hello for an example that can be
+    # loaded (only) into opt.exe.
+    set(LLVM_${name_upper}_LINK_INTO_TOOLS ON)
+  else ()
+    option(LLVM_${name_upper}_LINK_INTO_TOOLS "Statically link ${name} into tools (if available)" OFF)
+  endif ()
 
   # process_llvm_pass_plugins takes care of the actual linking, just create an
   # object library as of now


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72372.236703.patch
Type: text/x-patch
Size: 1044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200107/9522d994/attachment.bin>


More information about the llvm-commits mailing list