]> granicus.if.org Git - clang/commitdiff
clang-cl: Support loading plugins on Windows
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Tue, 9 Feb 2016 19:43:11 +0000 (19:43 +0000)
committerEhsan Akhgari <ehsan.akhgari@gmail.com>
Tue, 9 Feb 2016 19:43:11 +0000 (19:43 +0000)
This builds on the support being added to LLVM to import and export
registries from DLLs.  This will allow us to pick up the registry
entries added in the DLL's copy of FrontendPluginRegistry.

This will allow us to use plugins on Windows using:
$ clang-cl -Xclang -load -Xclang plugin.dll \
           -Xclang -add-plugin -Xclang foo

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260265 91177308-0d34-0410-b5e6-96231b3b80d8

docs/ClangPlugins.rst
examples/PrintFunctionNames/PrintFunctionNames.cpp
lib/FrontendTool/ExecuteCompilerInvocation.cpp

index 9a5bc142130b7f3000b3bd834b4bb7122fe247dc..1aeff62e2fd8ce735058d5fa28d7cb86a0d15796 100644 (file)
@@ -37,11 +37,14 @@ Registering a plugin
 ====================
 
 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
 =======================
index 9f8f6e3f050a5650fadc268528b754b5bfafff58..e2834b9ad234f919d4b92e01c1f1e30c4d4786a7 100644 (file)
@@ -121,3 +121,4 @@ protected:
 
 static FrontendPluginRegistry::Add<PrintFunctionNamesAction>
 X("print-fns", "print function names");
+LLVM_EXPORT_REGISTRY(FrontendPluginRegistry)
index 116590e5375a622a5f1cc70bc23ac217b622863e..90642abb5d5169cfb52ea01b9bb2c893b6e5749e 100644 (file)
@@ -189,9 +189,16 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
          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.