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 X("my-plugin-name", "my plugin description"); + LLVM_EXPORT_REGISTRY(FrontendPluginRegistry) Putting it all together ======================= Index: examples/PrintFunctionNames/PrintFunctionNames.cpp =================================================================== --- examples/PrintFunctionNames/PrintFunctionNames.cpp +++ examples/PrintFunctionNames/PrintFunctionNames.cpp @@ -121,3 +121,4 @@ static FrontendPluginRegistry::Add X("print-fns", "print function names"); +LLVM_EXPORT_REGISTRY(FrontendPluginRegistry) 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: 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: 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