[llvm] Export LLVM plugin entrypoint for windows shared library builds (PR #115431)

Thomas Fransham via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 09:00:28 PST 2025


https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/115431

>From bcbb5dce669ccde8631f87f7c10ea4d7a37d9782 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Thu, 7 Nov 2024 19:48:34 +0000
Subject: [PATCH 1/2] Export LLVM plugin entrypoint for windows shared library
 builds

Add Symbol visibility macro to llvmGetPassPluginInfo so plugins export it for
windows shared library builds with explicit symbol visibility macros enabled.
This avoids the need for existing plugins having to manually add visibility
macros to there llvmGetPassPluginInfo function to work on windows.

This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on window.
---
 llvm/include/llvm/Passes/PassPlugin.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Passes/PassPlugin.h b/llvm/include/llvm/Passes/PassPlugin.h
index 013b7a827c47dd..43310d0b9f14af 100644
--- a/llvm/include/llvm/Passes/PassPlugin.h
+++ b/llvm/include/llvm/Passes/PassPlugin.h
@@ -107,7 +107,7 @@ class PassPlugin {
 ///   };
 /// }
 /// ```
-extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK LLVM_ABI_EXPORT
 llvmGetPassPluginInfo();
 
 #endif /* LLVM_PASSES_PASSPLUGIN_H */

>From 66d3650a3801fbf2ebe2ff10ea263e8720b7835f Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 11 Nov 2024 22:47:01 +0000
Subject: [PATCH 2/2] Switch to just using dllexport for llvmGetPassPluginInfo
 declaration

---
 llvm/include/llvm/Passes/PassPlugin.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Passes/PassPlugin.h b/llvm/include/llvm/Passes/PassPlugin.h
index 43310d0b9f14af..967de9f29ba795 100644
--- a/llvm/include/llvm/Passes/PassPlugin.h
+++ b/llvm/include/llvm/Passes/PassPlugin.h
@@ -107,7 +107,13 @@ class PassPlugin {
 ///   };
 /// }
 /// ```
-extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK LLVM_ABI_EXPORT
+
+#if defined(_WIN32) && defined(LLVM_BUILD_LLVM_DYLIB)
+extern "C" ::llvm::PassPluginLibraryInfo __declspec(dllexport)
+llvmGetPassPluginInfo();
+#else
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
 llvmGetPassPluginInfo();
+#endif
 
 #endif /* LLVM_PASSES_PASSPLUGIN_H */



More information about the llvm-commits mailing list