diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-11-28 22:23:53 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-11-28 22:23:53 +0000 |
commit | 7b6b980178ddf686d1cceb37124b139828108808 (patch) | |
tree | 3b34ab92f689c4cb667e69d2dc9a151afa8fd2de | |
parent | 78a68061a39878c1b3a5ba9b899d22ca1fb87021 (diff) |
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
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | include/llvm/ADT/EpochTracker.h | 1 | ||||
-rw-r--r-- | include/llvm/ADT/ilist_node_options.h | 1 | ||||
-rw-r--r-- | include/llvm/Config/abi-breaking.h.cmake | 39 | ||||
-rw-r--r-- | include/llvm/Config/config.h.cmake | 3 | ||||
-rw-r--r-- | include/llvm/Config/llvm-config.h.cmake | 3 | ||||
-rw-r--r-- | include/llvm/Support/Error.h | 1 | ||||
-rw-r--r-- | lib/Support/Error.cpp | 15 |
8 files changed, 60 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d90baefeb9e..82e0c5c8573 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -715,6 +715,9 @@ configure_file( ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h) configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake + ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h) +configure_file( ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h) diff --git a/include/llvm/ADT/EpochTracker.h b/include/llvm/ADT/EpochTracker.h index 671025367b7..db39ba4e0c5 100644 --- a/include/llvm/ADT/EpochTracker.h +++ b/include/llvm/ADT/EpochTracker.h @@ -16,6 +16,7 @@ #ifndef LLVM_ADT_EPOCH_TRACKER_H #define LLVM_ADT_EPOCH_TRACKER_H +#include "llvm/Config/abi-breaking.h" #include "llvm/Config/llvm-config.h" #include <cstdint> diff --git a/include/llvm/ADT/ilist_node_options.h b/include/llvm/ADT/ilist_node_options.h index 6086a1fd22b..c33df1eeb81 100644 --- a/include/llvm/ADT/ilist_node_options.h +++ b/include/llvm/ADT/ilist_node_options.h @@ -10,6 +10,7 @@ #ifndef LLVM_ADT_ILIST_NODE_OPTIONS_H #define LLVM_ADT_ILIST_NODE_OPTIONS_H +#include "llvm/Config/abi-breaking.h" #include "llvm/Config/llvm-config.h" #include <type_traits> diff --git a/include/llvm/Config/abi-breaking.h.cmake b/include/llvm/Config/abi-breaking.h.cmake new file mode 100644 index 00000000000..f923a1e2f4a --- /dev/null +++ b/include/llvm/Config/abi-breaking.h.cmake @@ -0,0 +1,39 @@ +/*===------- llvm/Config/abi-breaking.h - llvm configuration -------*- C -*-===*/ +/* */ +/* The LLVM Compiler Infrastructure */ +/* */ +/* This file is distributed under the University of Illinois Open Source */ +/* License. See LICENSE.TXT for details. */ +/* */ +/*===----------------------------------------------------------------------===*/ + +/* This file controls the C++ ABI break introduced in LLVM public header. */ + +#ifndef LLVM_ABI_BREAKING_CHECKS_H +#define LLVM_ABI_BREAKING_CHECKS_H + +/* Define to enable checks that alter the LLVM C++ ABI */ +#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS + +// ABI_BREAKING_CHECKS protection: provides link-time failure when clients build +// mismatch with LLVM +#if defined(_MSC_VER) +// Use pragma with MSVC +#define LLVM_XSTR(s) LLVM_STR(s) +#define LLVM_STR(s) #s +#pragma detect_mismatch("LLVM_ENABLE_ABI_BREAKING_CHECKS", LLVM_XSTR(LLVM_ENABLE_ABI_BREAKING_CHECKS)) +#undef LLVM_XSTR +#undef LLVM_STR +#elif defined(__cplusplus) +namespace llvm { +#if LLVM_ENABLE_ABI_BREAKING_CHECKS +extern int EnableABIBreakingChecks; +__attribute__((weak, visibility ("hidden"))) int *VerifyEnableABIBreakingChecks = &EnableABIBreakingChecks; +#else +extern int DisableABIBreakingChecks; +__attribute__((weak, visibility ("hidden"))) int *VerifyDisableABIBreakingChecks = &DisableABIBreakingChecks; +#endif +} +#endif // _MSC_VER + +#endif diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake index 05bc724d339..ebe33d5fea3 100644 --- a/include/llvm/Config/config.h.cmake +++ b/include/llvm/Config/config.h.cmake @@ -333,9 +333,6 @@ /* Doesn't use `cmakedefine` because it is allowed to be empty. */ #define LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" -/* Define to enable checks that alter the LLVM C++ ABI */ -#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS - /* Define if threads enabled */ #cmakedefine01 LLVM_ENABLE_THREADS diff --git a/include/llvm/Config/llvm-config.h.cmake b/include/llvm/Config/llvm-config.h.cmake index 4121e865ea0..35999705761 100644 --- a/include/llvm/Config/llvm-config.h.cmake +++ b/include/llvm/Config/llvm-config.h.cmake @@ -20,9 +20,6 @@ /* Target triple LLVM will generate code for by default */ #cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" -/* Define to enable checks that alter the LLVM C++ ABI */ -#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS - /* Define if threads enabled */ #cmakedefine01 LLVM_ENABLE_THREADS diff --git a/include/llvm/Support/Error.h b/include/llvm/Support/Error.h index a09a212c12f..01ee0354337 100644 --- a/include/llvm/Support/Error.h +++ b/include/llvm/Support/Error.h @@ -18,6 +18,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" +#include "llvm/Config/abi-breaking.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/Support/Error.cpp b/lib/Support/Error.cpp index 7436a1fd38e..60854f12667 100644 --- a/lib/Support/Error.cpp +++ b/lib/Support/Error.cpp @@ -112,3 +112,18 @@ void report_fatal_error(Error Err, bool GenCrashDiag) { } } + +#ifndef _MSC_VER +namespace llvm { + +// One of these two variables will be referenced by a symbol defined in +// llvm-config.h. We provide a link-time (or load time for DSO) failure when +// there is a mismatch in the build configuration of the API client and LLVM. +#if LLVM_ENABLE_ABI_BREAKING_CHECKS +int EnableABIBreakingChecks; +#else +int DisableABIBreakingChecks; +#endif + +} // end namespace llvm +#endif
\ No newline at end of file |