[clang] [llvm] [Windows] Fix plugin registry symbols not exported/linked with CLANG_LINK_CLANG_DYLIB (PR #163391)

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 17 01:10:58 PDT 2025


================
@@ -55,6 +55,25 @@
 #include <set>
 #include <system_error>
 
+#if defined(CLANG_PLUGIN_SUPPORT) && defined(_WIN32)
+#include "clang/Frontend/FrontendPluginRegistry.h"
+
+// Force plugin registry symbols into clang.exe on Windows so plugins can
+// register. These methods exist in libraries but aren't linked by default
+// because they're unreferenced. Taking their addresses forces the linker to
+// include them.
+namespace {
+void ForcePluginRegistrySymbols() {
+  using PluginRegistry = llvm::Registry<clang::PluginASTAction>;
+  // Use volatile to prevent the compiler from optimizing away these references
+  volatile auto add_node_ptr = &PluginRegistry::add_node;
+  volatile auto begin_ptr = &PluginRegistry::begin;
+  (void)add_node_ptr;
+  (void)begin_ptr;
+}
+} // anonymous namespace
+#endif
+
----------------
zmodem wrote:

This doesn't look right to me. I think the plugin registry symbols are used in clang.exe already, e.g. at https://github.com/llvm/llvm-project/blob/558d935e93c20fea42fa8af54b401a74962c94c6/clang/lib/Frontend/FrontendAction.cpp#L435

https://github.com/llvm/llvm-project/pull/163391


More information about the cfe-commits mailing list