[llvm-commits] [compiler-rt] r163603 - in /compiler-rt/trunk/lib: asan/asan_rtl.cc sanitizer_common/sanitizer_common.cc sanitizer_common/sanitizer_common.h tsan/rtl/tsan_platform_linux.cc tsan/rtl/tsan_platform_mac.cc tsan/rtl/tsan_rtl.cc tsan/rtl/tsan_rtl.h tsan/rtl/tsan_rtl_report.cc
Alexey Samsonov
samsonov at google.com
Tue Sep 11 02:44:49 PDT 2012
Author: samsonov
Date: Tue Sep 11 04:44:48 2012
New Revision: 163603
URL: http://llvm.org/viewvc/llvm-project?rev=163603&view=rev
Log:
[Sanitizer] Get rid of dependency between sanitizer_common and asan/tsan runtimes: implement tool-specific Die and CheckFailed functions via callbacks
Modified:
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Sep 11 04:44:48 2012
@@ -27,10 +27,9 @@
#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_symbolizer.h"
-namespace __sanitizer {
-using namespace __asan;
+namespace __asan {
-void Die() {
+static void AsanDie() {
static atomic_uint32_t num_calls;
if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
// Don't die twice - run a busy loop.
@@ -49,8 +48,8 @@
Exit(flags()->exitcode);
}
-SANITIZER_INTERFACE_ATTRIBUTE
-void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) {
+static void AsanCheckFailed(const char *file, int line, const char *cond,
+ u64 v1, u64 v2) {
Report("AddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n",
file, line, cond, (uptr)v1, (uptr)v2);
// FIXME: check for infinite recursion without a thread-local counter here.
@@ -58,10 +57,6 @@
ShowStatsAndAbort();
}
-} // namespace __sanitizer
-
-namespace __asan {
-
// -------------------------- Flags ------------------------- {{{1
static const int kDeafultMallocContextSize = 30;
@@ -291,6 +286,9 @@
// Make sure we are not statically linked.
AsanDoesNotSupportStaticLinkage();
+ // Install tool-specific callbacks in sanitizer_common.
+ SetDieCallback(AsanDie);
+ SetCheckFailedCallback(AsanCheckFailed);
SetPrintfAndReportCallback(AppendToErrorMessageBuffer);
// Initialize flags. This must be done early, because most of the
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Tue Sep 11 04:44:48 2012
@@ -16,6 +16,33 @@
namespace __sanitizer {
+static void (*DieCallback)(void);
+void SetDieCallback(void (*callback)(void)) {
+ DieCallback = callback;
+}
+
+void NORETURN Die() {
+ if (DieCallback) {
+ DieCallback();
+ }
+ Exit(1);
+}
+
+static CheckFailedCallbackType CheckFailedCallback;
+void SetCheckFailedCallback(CheckFailedCallbackType callback) {
+ CheckFailedCallback = callback;
+}
+
+void NORETURN CheckFailed(const char *file, int line, const char *cond,
+ u64 v1, u64 v2) {
+ if (CheckFailedCallback) {
+ CheckFailedCallback(file, line, cond, v1, v2);
+ }
+ Report("Sanitizer CHECK failed: %s:%d %s (%zd, %zd)\n", file, line, cond,
+ v1, v2);
+ Die();
+}
+
void RawWrite(const char *buffer) {
static const char *kRawWriteError = "RawWrite can't output requested buffer!";
uptr length = (uptr)internal_strlen(buffer);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Sep 11 04:44:48 2012
@@ -120,11 +120,23 @@
void DumpProcessMap();
void SleepForSeconds(int seconds);
void SleepForMillis(int millis);
-void NORETURN Exit(int exitcode);
-void NORETURN Abort();
int Atexit(void (*function)(void));
void SortArray(uptr *array, uptr size);
+// Exit
+void NORETURN Abort();
+void NORETURN Exit(int exitcode);
+void NORETURN Die();
+void NORETURN SANITIZER_INTERFACE_ATTRIBUTE
+CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2);
+
+// Specific tools may override behavior of "Die" and "CheckFailed" functions
+// to do tool-specific job.
+void SetDieCallback(void (*callback)(void));
+typedef void (*CheckFailedCallbackType)(const char *, int, const char *,
+ u64, u64);
+void SetCheckFailedCallback(CheckFailedCallbackType callback);
+
// Math
INLINE bool IsPowerOfTwo(uptr x) {
return (x & (x - 1)) == 0;
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc Tue Sep 11 04:44:48 2012
@@ -43,14 +43,6 @@
extern "C" int arch_prctl(int code, __sanitizer::uptr *addr);
-namespace __sanitizer {
-
-void Die() {
- _exit(1);
-}
-
-} // namespace __sanitizer
-
namespace __tsan {
#ifndef TSAN_GO
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc Tue Sep 11 04:44:48 2012
@@ -37,14 +37,6 @@
#include <errno.h>
#include <sched.h>
-namespace __sanitizer {
-
-void Die() {
- _exit(1);
-}
-
-} // namespace __sanitizer
-
namespace __tsan {
ScopedInRtl::ScopedInRtl() {
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Tue Sep 11 04:44:48 2012
@@ -165,6 +165,9 @@
if (is_initialized)
return;
is_initialized = true;
+ // Install tool-specific callbacks in sanitizer_common.
+ SetCheckFailedCallback(TsanCheckFailed);
+
ScopedInRtl in_rtl;
#ifndef TSAN_GO
InitializeAllocator();
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Tue Sep 11 04:44:48 2012
@@ -65,6 +65,8 @@
Allocator *allocator();
#endif
+void TsanCheckFailed(const char *file, int line, const char *cond,
+ u64 v1, u64 v2);
void TsanPrintf(const char *format, ...);
// FastState (from most significant bit):
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=163603&r1=163602&r2=163603&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Tue Sep 11 04:44:48 2012
@@ -23,10 +23,10 @@
#include "tsan_mman.h"
#include "tsan_flags.h"
-namespace __sanitizer {
-using namespace __tsan;
+namespace __tsan {
-void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) {
+void TsanCheckFailed(const char *file, int line, const char *cond,
+ u64 v1, u64 v2) {
ScopedInRtl in_rtl;
TsanPrintf("FATAL: ThreadSanitizer CHECK failed: "
"%s:%d \"%s\" (0x%zx, 0x%zx)\n",
@@ -34,10 +34,6 @@
Die();
}
-} // namespace __sanitizer
-
-namespace __tsan {
-
// Can be overriden by an application/test to intercept reports.
#ifdef TSAN_EXTERNAL_HOOKS
bool OnReport(const ReportDesc *rep, bool suppressed);
More information about the llvm-commits
mailing list