[llvm] [RFC][llvm] Enable BUILD_SHARED_LIBS with MinGW (PR #174266)

Vedran Miletić via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 9 08:14:06 PST 2026


https://github.com/vedranmiletic updated https://github.com/llvm/llvm-project/pull/174266

>From ed1cc2bedff29869a3b1605c57d73f2191d2c6de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vedran=20Mileti=C4=87?= <vedran at miletic.net>
Date: Fri, 2 Jan 2026 21:08:34 +0100
Subject: [PATCH] [llvm] Fixed BUILD_SHARED_LIBS with MinGW GCC

When compiling with MinGW GCC, using LLVM_ALWAYS_EXPORT macro limits
the symbol visibility to only those symbols, which is likely not the
intended behavior.

This causes issues when linking libLLVMOrcTargetProcess.dll.a, where
only the symbols __jit_debug_descriptor and __jit_debug_register_code
are marked with LLVM_ALWAYS_EXPORT and other simbols in the library
are therefore not visible.

With LLVM_ABI macro, we make sure that __declspec(dllexport) is not used
on Windows with MinGW or Cygwin, but only with MSVC. This patch applies
the same logic to the LLVM_ALWAYS_EXPOT macro and fixes the linking
issue on MinGW GCC cross-build.
---
 llvm/include/llvm/Support/Compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 56f498a36ae52..1e91030f208f3 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -143,7 +143,7 @@
 #define LLVM_LIBRARY_VISIBILITY_NAMESPACE LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
 #endif
 #define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
-#elif defined(_WIN32)
+#elif defined(_WIN32) && !defined(__MINGW32__)
 #define LLVM_ALWAYS_EXPORT __declspec(dllexport)
 #define LLVM_LIBRARY_VISIBILITY
 #define LLVM_LIBRARY_VISIBILITY_NAMESPACE



More information about the llvm-commits mailing list