From: Ehsan Akhgari Date: Tue, 9 Feb 2016 19:43:11 +0000 (+0000) Subject: clang-cl: Support loading plugins on Windows X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ae1cd1e7c301954bab703e9116a30b330902d43a;p=clang clang-cl: Support loading plugins on Windows 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 --- diff --git a/docs/ClangPlugins.rst b/docs/ClangPlugins.rst index 9a5bc14213..1aeff62e2f 100644 --- a/docs/ClangPlugins.rst +++ b/docs/ClangPlugins.rst @@ -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 X("my-plugin-name", "my plugin description"); + LLVM_EXPORT_REGISTRY(FrontendPluginRegistry) Putting it all together ======================= diff --git a/examples/PrintFunctionNames/PrintFunctionNames.cpp b/examples/PrintFunctionNames/PrintFunctionNames.cpp index 9f8f6e3f05..e2834b9ad2 100644 --- a/examples/PrintFunctionNames/PrintFunctionNames.cpp +++ b/examples/PrintFunctionNames/PrintFunctionNames.cpp @@ -121,3 +121,4 @@ protected: static FrontendPluginRegistry::Add X("print-fns", "print function names"); +LLVM_EXPORT_REGISTRY(FrontendPluginRegistry) diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 116590e537..90642abb5d 100644 --- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -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.