[PATCH] D16761: clang-cl: Support loading plugins on Windows

Ehsan Akhgari via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 5 14:55:02 PST 2016


ehsan updated this revision to Diff 47057.
ehsan added a comment.

Sorry for the noise, arconist fail...


http://reviews.llvm.org/D16761

Files:
  docs/ClangPlugins.rst
  examples/PrintFunctionNames/PrintFunctionNames.cpp
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  test/Frontend/plugins.c
  test/lit.cfg

Index: test/lit.cfg
===================================================================
--- test/lit.cfg
+++ test/lit.cfg
@@ -196,7 +196,7 @@
 
 # Plugins (loadable modules)
 # TODO: This should be supplied by Makefile or autoconf.
-if sys.platform in ['win32', 'cygwin']:
+if sys.platform in ['cygwin']:
     has_plugins = (config.enable_shared == 1)
 else:
     has_plugins = True
Index: test/Frontend/plugins.c
===================================================================
--- test/Frontend/plugins.c
+++ test/Frontend/plugins.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -load %llvmshlibdir/PrintFunctionNames%pluginext -plugin print-fns %s 2>&1 | FileCheck %s
+// RUN: %clang_cl -Xclang -load -Xclang %llvmshlibdir/PrintFunctionNames%pluginext -Xclang -plugin -Xclang print-fns %s 2>&1 | FileCheck %s
 // REQUIRES: plugins, examples
 
 // CHECK: top-level-decl: "x"
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===================================================================
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -184,9 +184,16 @@
          e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) {
     const std::string &Path = Clang->getFrontendOpts().Plugins[i];
     std::string Error;
-    if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
+    llvm::sys::DynamicLibrary DL(
+        llvm::sys::DynamicLibrary::getPermanentLibrary(Path.c_str(), &Error));
+    if (DL.isValid()) {
+      // On Windows, we need to import the plugin front-end action
+      // dynamically.
+      LLVM_IMPORT_REGISTRY(FrontendPluginRegistry, DL);
+    } else {
       Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
         << Path << Error;
+    }
   }
 
   // Honor -mllvm.
Index: examples/PrintFunctionNames/PrintFunctionNames.cpp
===================================================================
--- examples/PrintFunctionNames/PrintFunctionNames.cpp
+++ examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -121,3 +121,4 @@
 
 static FrontendPluginRegistry::Add<PrintFunctionNamesAction>
 X("print-fns", "print function names");
+LLVM_EXPORT_REGISTRY(FrontendPluginRegistry)
Index: docs/ClangPlugins.rst
===================================================================
--- docs/ClangPlugins.rst
+++ docs/ClangPlugins.rst
@@ -37,11 +37,14 @@
 ====================
 
 A plugin is loaded from a dynamic library at runtime by the compiler. To
-register a plugin in a library, use ``FrontendPluginRegistry::Add<>``:
+register a plugin in a library, use ``FrontendPluginRegistry::Add<>``.
+On Windows, you also need to export your plugin registry using
+``LLVM_EXPORT_REGISTRY``.  Here is an example:
 
 .. code-block:: c++
 
   static FrontendPluginRegistry::Add<MyPlugin> X("my-plugin-name", "my plugin description");
+  LLVM_EXPORT_REGISTRY(FrontendPluginRegistry)
 
 Putting it all together
 =======================


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16761.47057.patch
Type: text/x-patch
Size: 2945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160205/c06a7d3f/attachment-0001.bin>


More information about the cfe-commits mailing list