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) Defining pragmas ================ Index: examples/AnnotateFunctions/AnnotateFunctions.cpp =================================================================== --- examples/AnnotateFunctions/AnnotateFunctions.cpp +++ examples/AnnotateFunctions/AnnotateFunctions.cpp @@ -86,3 +86,6 @@ static PragmaHandlerRegistry::Add Y("enable_annotate","enable annotation"); + +LLVM_EXPORT_REGISTRY(FrontendPluginRegistry) +LLVM_EXPORT_REGISTRY(PragmaHandlerRegistry) 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 @@ -22,6 +22,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/Frontend/Utils.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Rewrite/Frontend/FrontendActions.h" #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "llvm/Option/OptTable.h" @@ -191,9 +192,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 registries dynamically. + LLVM_IMPORT_REGISTRY(FrontendPluginRegistry, DL); + LLVM_IMPORT_REGISTRY(PragmaHandlerRegistry, DL); + } else { Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin) << Path << Error; + } } // Check if any of the loaded plugins replaces the main AST action