Skip to content

Commit 11d97b3

Browse files
authored
[llvm] annotate ABIBreakingChecks symbols for DLL export (#149198)
## Purpose This PR is a re-application of #145575 with independent definition of `ABI_BREAKING_EXPORT_ABI` that does not depend on `llvm/Support/Compiler.h`. It is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the ABI Breaking Checks interface in llvm/config. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background The effort to build LLVM as a Windows DLL is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent 6d90715 commit 11d97b3

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

llvm/include/llvm/Config/abi-breaking.h.cmake

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,41 @@
1212
#ifndef LLVM_ABI_BREAKING_CHECKS_H
1313
#define LLVM_ABI_BREAKING_CHECKS_H
1414

15+
// llvm-config.h is required for LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
16+
#include "llvm/Config/llvm-config.h"
17+
1518
/* Define to enable checks that alter the LLVM C++ ABI */
1619
#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS
1720

1821
/* Define to enable reverse iteration of unordered llvm containers */
1922
#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION
2023

24+
#if !defined(__has_attribute)
25+
#define __has_attribute(attribute) 0
26+
#endif
27+
28+
// Properly annotate EnableABIBreakingChecks or DisableABIBreakingChecks for
29+
// export from shared library.
30+
// TODO(https://github.com/llvm/llvm-project/issues/145406): eliminate need for
31+
// two preprocessor definitions to gate LLVM_ABI macro definitions.
32+
#if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
33+
#define ABI_BREAKING_EXPORT_ABI
34+
#else
35+
#if defined(_WIN32)
36+
#if defined(LLVM_EXPORTS)
37+
#define ABI_BREAKING_EXPORT_ABI __declspec(dllexport)
38+
#else
39+
#define ABI_BREAKING_EXPORT_ABI __declspec(dllimport)
40+
#endif
41+
#else
42+
#if __has_attribute(visibility)
43+
#define ABI_BREAKING_EXPORT_ABI __attribute__((__visibility__("default")))
44+
#else
45+
#define ABI_BREAKING_EXPORT_ABI
46+
#endif
47+
#endif
48+
#endif
49+
2150
/* Allow selectively disabling link-time mismatch checking so that header-only
2251
ADT content from LLVM can be used without linking libSupport. */
2352
#if !defined(LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING) || !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING
@@ -43,12 +72,12 @@
4372
#endif
4473
namespace llvm {
4574
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
46-
extern int EnableABIBreakingChecks;
75+
ABI_BREAKING_EXPORT_ABI extern int EnableABIBreakingChecks;
4776
LLVM_HIDDEN_VISIBILITY
4877
__attribute__((weak)) int *VerifyEnableABIBreakingChecks =
4978
&EnableABIBreakingChecks;
5079
#else
51-
extern int DisableABIBreakingChecks;
80+
ABI_BREAKING_EXPORT_ABI extern int DisableABIBreakingChecks;
5281
LLVM_HIDDEN_VISIBILITY
5382
__attribute__((weak)) int *VerifyDisableABIBreakingChecks =
5483
&DisableABIBreakingChecks;

0 commit comments

Comments
 (0)