summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/ErrorHandling.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-07-13 16:56:24 +0000
committerReid Kleckner <rnk@google.com>2017-07-13 16:56:24 +0000
commit1c0f6ed45a3e4040c827ce0b49aa4c6c90ad5e25 (patch)
treecacfc3dd12d484cde4a34c15dc0e16e0da03ff22 /llvm/lib/Support/ErrorHandling.cpp
parente1088dc42b3e564b8f0f020594eacf88f70761f1 (diff)
downloadbcm5719-llvm-1c0f6ed45a3e4040c827ce0b49aa4c6c90ad5e25.tar.gz
bcm5719-llvm-1c0f6ed45a3e4040c827ce0b49aa4c6c90ad5e25.zip
Put std::mutex usage behind #ifdefs to pacify the sanitizer buildbot
llvm-svn: 307925
Diffstat (limited to 'llvm/lib/Support/ErrorHandling.cpp')
-rw-r--r--llvm/lib/Support/ErrorHandling.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
index fe69151665c..2fd4f3ea0d4 100644
--- a/llvm/lib/Support/ErrorHandling.cpp
+++ b/llvm/lib/Support/ErrorHandling.cpp
@@ -45,22 +45,36 @@ static void *ErrorHandlerUserData = nullptr;
static fatal_error_handler_t BadAllocErrorHandler = nullptr;
static void *BadAllocErrorHandlerUserData = nullptr;
+#if LLVM_ENABLE_THREADS == 1
// Mutexes to synchronize installing error handlers and calling error handlers.
// Do not use ManagedStatic, or that may allocate memory while attempting to
// report an OOM.
+//
+// This usage of std::mutex has to be conditionalized behind ifdefs because
+// of this script:
+// compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
+// That script attempts to statically link the LLVM symbolizer library with the
+// STL and hide all of its symbols with 'opt -internalize'. To reduce size, it
+// cuts out the threading portions of the hermetic copy of libc++ that it
+// builds. We can remove these ifdefs if that script goes away.
static std::mutex ErrorHandlerMutex;
static std::mutex BadAllocErrorHandlerMutex;
+#endif
void llvm::install_fatal_error_handler(fatal_error_handler_t handler,
void *user_data) {
+#if LLVM_ENABLE_THREADS == 1
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
+#endif
assert(!ErrorHandler && "Error handler already registered!\n");
ErrorHandler = handler;
ErrorHandlerUserData = user_data;
}
void llvm::remove_fatal_error_handler() {
+#if LLVM_ENABLE_THREADS == 1
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
+#endif
ErrorHandler = nullptr;
ErrorHandlerUserData = nullptr;
}
@@ -83,7 +97,9 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
{
// Only acquire the mutex while reading the handler, so as not to invoke a
// user-supplied callback under a lock.
+#if LLVM_ENABLE_THREADS == 1
std::lock_guard<std::mutex> Lock(ErrorHandlerMutex);
+#endif
handler = ErrorHandler;
handlerData = ErrorHandlerUserData;
}
@@ -112,14 +128,18 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler,
void *user_data) {
+#if LLVM_ENABLE_THREADS == 1
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
+#endif
assert(!ErrorHandler && "Bad alloc error handler already registered!\n");
BadAllocErrorHandler = handler;
BadAllocErrorHandlerUserData = user_data;
}
void llvm::remove_bad_alloc_error_handler() {
+#if LLVM_ENABLE_THREADS == 1
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
+#endif
BadAllocErrorHandler = nullptr;
BadAllocErrorHandlerUserData = nullptr;
}
@@ -130,7 +150,9 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) {
{
// Only acquire the mutex while reading the handler, so as not to invoke a
// user-supplied callback under a lock.
+#if LLVM_ENABLE_THREADS == 1
std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
+#endif
Handler = BadAllocErrorHandler;
HandlerData = BadAllocErrorHandlerUserData;
}
OpenPOWER on IntegriCloud