[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 13:16:21 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:
> I assume that at some point we will want to make `LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS` always true and remove that from the conditional check here? `LLVM_BUILD_STATIC` should be able to control the behaviour as needed.
@compnerd I haven't figured out a way of gating these macros with a single preprocessor definition. Here is my thinking:
1. We require a `#define` that gets emitted to `llvm-config.h` (via a `#cmakedefine`) so that it will be present when LLVM clients are built. This is so clients will pick-up the `__declspec(dllimport)` annotation when building on Windows. I added `LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS` for this purpose, and I expect to add two similar definitions for the llvm-c and Demangle libraries.
2. We need a mechanism to override the definitions in `llvm-config.h` when building some tools/utils (e.g. `tablegen`) that prefer to statically link against LLVM. This was already working with `LLVM_BUILD_STATIC`.
Do you have a suggestion to achieve this with a single define?
https://github.com/llvm/llvm-project/pull/144598
More information about the llvm-commits
mailing list