Skip to content

Commit

Permalink
Add link-time detection of LLVM_ABI_BREAKING_CHECKS mismatch
Browse files Browse the repository at this point in the history
Summary:
LLVM will define a symbol, either EnableABIBreakingChecks or
DisableABIBreakingChecks depending on the configuration setting for
LLVM_ABI_BREAKING_CHECKS.

The llvm-config.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.

Reviewers: rnk, jroelofs

Subscribers: llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D26841

llvm-svn: 287352
  • Loading branch information
joker-eph committed Nov 18, 2016
1 parent 395be57 commit c311528
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions llvm/include/llvm/Config/llvm-config.h.cmake
Expand Up @@ -80,4 +80,25 @@
/* LLVM version string */
#define LLVM_VERSION_STRING "${PACKAGE_VERSION}"

// 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
16 changes: 16 additions & 0 deletions llvm/lib/Support/Error.cpp
Expand Up @@ -112,3 +112,19 @@ 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

0 comments on commit c311528

Please sign in to comment.