[llvm] [llvm] revisions to `LLVM_ABI` export macro definitions (PR #144598)

Andrew Rogers via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 18 17:05:31 PDT 2025


================
@@ -184,19 +179,8 @@
 // Marker to add to classes or functions in public headers that should not have
 // export macros added to them by the clang tool
 #define LLVM_ABI_NOT_EXPORTED
-#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) ||       \
-    defined(LLVM_ENABLE_PLUGINS)
-// Some libraries like those for tablegen are linked in to tools that used
-// in the build so can't depend on the llvm shared library. If export macros
-// were left enabled when building these we would get duplicate or
-// missing symbol linker errors on windows.
-#if defined(LLVM_BUILD_STATIC)
-#define LLVM_ABI
-#define LLVM_ABI_FRIEND
-#define LLVM_TEMPLATE_ABI
-#define LLVM_EXPORT_TEMPLATE
-#define LLVM_ABI_EXPORT
-#elif defined(_WIN32) && !defined(__MINGW32__)
+#if defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) && !defined(LLVM_BUILD_STATIC)
----------------
andrurogerz wrote:

> The headers are associated with a build, that build can only be used one way (static or dynamic). 

I just don't see a way to eliminate support for `llvm_add_library`'s `DISABLE_LLVM_LINK_LLVM_DYLIB` argument, which is what dynamically defines `LLVM_BUILD_STATIC` at build time in the few cases it is needed. See [AddLLVM.cmake](https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/AddLLVM.cmake#L500-L502).

Here's why I believe we need to have a second variable as a dynamic override to the one in `llvm-config.h`:
- TableGen depends on the LLVM Support library
- TableGen is required to build the LLVM DLL, so it has to statically link the Support library
- When statically linking the Support library, the associated headers must not have `__declspec(dllimport)` annotations on symbol declarations

Is there a better way to solve this? Generate a second llvm-config.h for this purpose maybe?

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


More information about the llvm-commits mailing list