llvm.org GIT mirror llvm / 7b6b980
Add link-time detection of LLVM_ABI_BREAKING_CHECKS mismatch The macro LLVM_ENABLE_ABI_BREAKING_CHECKS is moved to a new header abi-breaking.h, from llvm-config.h. Only headers that are using the macro are including this new header. LLVM will define a symbol, either EnableABIBreakingChecks or DisableABIBreakingChecks depending on the configuration setting for LLVM_ABI_BREAKING_CHECKS. The abi-breaking.h header will add weak references to these symbols in every clients that includes this header. This should ensure that a mismatch triggers a link failure (or a load time failure for DSO). On MSVC, the pragma "detect_mismatch" is used instead. Differential Revision: https://reviews.llvm.org/D26876 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288082 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 3 years ago
8 changed file(s) with 60 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
714714 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
715715 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
716716 configure_file(
717 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake
718 ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)
719 configure_file(
717720 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
718721 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
719722
1515 #ifndef LLVM_ADT_EPOCH_TRACKER_H
1616 #define LLVM_ADT_EPOCH_TRACKER_H
1717
18 #include "llvm/Config/abi-breaking.h"
1819 #include "llvm/Config/llvm-config.h"
1920
2021 #include
99 #ifndef LLVM_ADT_ILIST_NODE_OPTIONS_H
1010 #define LLVM_ADT_ILIST_NODE_OPTIONS_H
1111
12 #include "llvm/Config/abi-breaking.h"
1213 #include "llvm/Config/llvm-config.h"
1314
1415 #include
0 /*===------- llvm/Config/abi-breaking.h - llvm configuration -------*- C -*-===*/
1 /* */
2 /* The LLVM Compiler Infrastructure */
3 /* */
4 /* This file is distributed under the University of Illinois Open Source */
5 /* License. See LICENSE.TXT for details. */
6 /* */
7 /*===----------------------------------------------------------------------===*/
8
9 /* This file controls the C++ ABI break introduced in LLVM public header. */
10
11 #ifndef LLVM_ABI_BREAKING_CHECKS_H
12 #define LLVM_ABI_BREAKING_CHECKS_H
13
14 /* Define to enable checks that alter the LLVM C++ ABI */
15 #cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS
16
17 // ABI_BREAKING_CHECKS protection: provides link-time failure when clients build
18 // mismatch with LLVM
19 #if defined(_MSC_VER)
20 // Use pragma with MSVC
21 #define LLVM_XSTR(s) LLVM_STR(s)
22 #define LLVM_STR(s) #s
23 #pragma detect_mismatch("LLVM_ENABLE_ABI_BREAKING_CHECKS", LLVM_XSTR(LLVM_ENABLE_ABI_BREAKING_CHECKS))
24 #undef LLVM_XSTR
25 #undef LLVM_STR
26 #elif defined(__cplusplus)
27 namespace llvm {
28 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
29 extern int EnableABIBreakingChecks;
30 __attribute__((weak, visibility ("hidden"))) int *VerifyEnableABIBreakingChecks = &EnableABIBreakingChecks;
31 #else
32 extern int DisableABIBreakingChecks;
33 __attribute__((weak, visibility ("hidden"))) int *VerifyDisableABIBreakingChecks = &DisableABIBreakingChecks;
34 #endif
35 }
36 #endif // _MSC_VER
37
38 #endif
332332 /* Doesn't use `cmakedefine` because it is allowed to be empty. */
333333 #define LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}"
334334
335 /* Define to enable checks that alter the LLVM C++ ABI */
336 #cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS
337
338335 /* Define if threads enabled */
339336 #cmakedefine01 LLVM_ENABLE_THREADS
340337
1818
1919 /* Target triple LLVM will generate code for by default */
2020 #cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}"
21
22 /* Define to enable checks that alter the LLVM C++ ABI */
23 #cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS
2421
2522 /* Define if threads enabled */
2623 #cmakedefine01 LLVM_ENABLE_THREADS
1717 #include "llvm/ADT/STLExtras.h"
1818 #include "llvm/ADT/StringExtras.h"
1919 #include "llvm/ADT/Twine.h"
20 #include "llvm/Config/abi-breaking.h"
2021 #include "llvm/Support/Debug.h"
2122 #include "llvm/Support/ErrorOr.h"
2223 #include "llvm/Support/raw_ostream.h"
111111 }
112112
113113 }
114
115 #ifndef _MSC_VER
116 namespace llvm {
117
118 // One of these two variables will be referenced by a symbol defined in
119 // llvm-config.h. We provide a link-time (or load time for DSO) failure when
120 // there is a mismatch in the build configuration of the API client and LLVM.
121 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
122 int EnableABIBreakingChecks;
123 #else
124 int DisableABIBreakingChecks;
125 #endif
126
127 } // end namespace llvm
128 #endif