| 1 | /*===------- llvm/Config/abi-breaking.h - llvm configuration -------*- C -*-===*/ |
| 2 | /* */ |
| 3 | /* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ |
| 4 | /* Exceptions. */ |
| 5 | /* See https://llvm.org/LICENSE.txt for license information. */ |
| 6 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 7 | /* */ |
| 8 | /*===----------------------------------------------------------------------===*/ |
| 9 | |
| 10 | /* This file controls the C++ ABI break introduced in LLVM public header. */ |
| 11 | |
| 12 | #ifndef LLVM_ABI_BREAKING_CHECKS_H |
| 13 | #define LLVM_ABI_BREAKING_CHECKS_H |
| 14 | |
| 15 | // llvm-config.h is required for LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS |
| 16 | #include "llvm/Config/llvm-config.h" |
| 17 | |
| 18 | /* Define to enable checks that alter the LLVM C++ ABI */ |
| 19 | #define LLVM_ENABLE_ABI_BREAKING_CHECKS 0 |
| 20 | |
| 21 | /* Define to enable reverse iteration of unordered llvm containers */ |
| 22 | #define LLVM_ENABLE_REVERSE_ITERATION 0 |
| 23 | |
| 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 | |
| 50 | /* Allow selectively disabling link-time mismatch checking so that header-only |
| 51 | ADT content from LLVM can be used without linking libSupport. */ |
| 52 | #if !defined(LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING) || !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING |
| 53 | |
| 54 | // ABI_BREAKING_CHECKS protection: provides link-time failure when clients build |
| 55 | // mismatch with LLVM |
| 56 | #if defined(_MSC_VER) |
| 57 | // Use pragma with MSVC |
| 58 | #define LLVM_XSTR(s) LLVM_STR(s) |
| 59 | #define LLVM_STR(s) #s |
| 60 | #pragma detect_mismatch("LLVM_ENABLE_ABI_BREAKING_CHECKS", LLVM_XSTR(LLVM_ENABLE_ABI_BREAKING_CHECKS)) |
| 61 | #undef LLVM_XSTR |
| 62 | #undef LLVM_STR |
| 63 | #elif defined(_WIN32) || defined(__CYGWIN__) // Win32 w/o #pragma detect_mismatch |
| 64 | // FIXME: Implement checks without weak. |
| 65 | #elif defined(__cplusplus) |
| 66 | #if !(defined(_AIX) && defined(__GNUC__) && !defined(__clang__)) |
| 67 | #define LLVM_HIDDEN_VISIBILITY __attribute__ ((visibility("hidden"))) |
| 68 | #else |
| 69 | // GCC on AIX does not support visibility attributes. Symbols are not |
| 70 | // exported by default on AIX. |
| 71 | #define LLVM_HIDDEN_VISIBILITY |
| 72 | #endif |
| 73 | namespace llvm { |
| 74 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS |
| 75 | ABI_BREAKING_EXPORT_ABI extern int EnableABIBreakingChecks; |
| 76 | LLVM_HIDDEN_VISIBILITY |
| 77 | __attribute__((weak)) int *VerifyEnableABIBreakingChecks = |
| 78 | &EnableABIBreakingChecks; |
| 79 | #else |
| 80 | ABI_BREAKING_EXPORT_ABI extern int DisableABIBreakingChecks; |
| 81 | LLVM_HIDDEN_VISIBILITY |
| 82 | __attribute__((weak)) int *VerifyDisableABIBreakingChecks = |
| 83 | &DisableABIBreakingChecks; |
| 84 | #endif |
| 85 | } |
| 86 | #undef LLVM_HIDDEN_VISIBILITY |
| 87 | #endif // _MSC_VER |
| 88 | |
| 89 | #endif // LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING |
| 90 | |
| 91 | #endif |
| 92 | |