summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2012-07-16 13:02:40 +0000
committerDmitry Vyukov <dvyukov@google.com>2012-07-16 13:02:40 +0000
commitc40c00767ca3e883dca536b21c4ad4ae504131ec (patch)
treea621768a1bb41b497a1ba2eddaf448df1d7f325e /compiler-rt/lib/tsan
parentf2f82550fddb088ab7c1821135ee06050264760a (diff)
downloadbcm5719-llvm-c40c00767ca3e883dca536b21c4ad4ae504131ec.tar.gz
bcm5719-llvm-c40c00767ca3e883dca536b21c4ad4ae504131ec.zip
tsan: port Go runtime to Darwin
llvm-svn: 160266
Diffstat (limited to 'compiler-rt/lib/tsan')
-rwxr-xr-xcompiler-rt/lib/tsan/go/buildgo.sh29
-rw-r--r--compiler-rt/lib/tsan/go/tsan_go.cc8
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_platform.h8
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc108
4 files changed, 141 insertions, 12 deletions
diff --git a/compiler-rt/lib/tsan/go/buildgo.sh b/compiler-rt/lib/tsan/go/buildgo.sh
index 5382af2fbbc..0741790dc29 100755
--- a/compiler-rt/lib/tsan/go/buildgo.sh
+++ b/compiler-rt/lib/tsan/go/buildgo.sh
@@ -1,13 +1,21 @@
#!/bin/bash
set -e
+if [ "`uname -a | grep Linux`" != "" ]; then
+ LINUX=1
+elif [ "`uname -a | grep Darwin`" != "" ]; then
+ MAC=1
+else
+ echo Unknown platform
+ exit 1
+fi
+
SRCS="
tsan_go.cc
../rtl/tsan_clock.cc
../rtl/tsan_flags.cc
../rtl/tsan_md5.cc
../rtl/tsan_mutex.cc
- ../rtl/tsan_platform_linux.cc
../rtl/tsan_printf.cc
../rtl/tsan_report.cc
../rtl/tsan_rtl.cc
@@ -21,12 +29,23 @@ SRCS="
../../sanitizer_common/sanitizer_common.cc
../../sanitizer_common/sanitizer_flags.cc
../../sanitizer_common/sanitizer_libc.cc
- ../../sanitizer_common/sanitizer_linux.cc
../../sanitizer_common/sanitizer_posix.cc
../../sanitizer_common/sanitizer_printf.cc
../../sanitizer_common/sanitizer_symbolizer.cc
"
+if [ "$LINUX" != "" ]; then
+ SRCS+="
+ ../rtl/tsan_platform_linux.cc
+ ../../sanitizer_common/sanitizer_linux.cc
+ "
+elif [ "$MAC" != "" ]; then
+ SRCS+="
+ ../rtl/tsan_platform_mac.cc
+ ../../sanitizer_common/sanitizer_mac.cc
+ "
+fi
+
#ASMS="../rtl/tsan_rtl_amd64.S"
rm -f gotsan.cc
@@ -34,13 +53,17 @@ for F in $SRCS; do
cat $F >> gotsan.cc
done
-FLAGS=" -I../rtl -I../.. -I../../sanitizer_common -fPIC -g -Wall -Werror -ffreestanding -fno-exceptions -DTSAN_GO -DSANITIZER_GO -DTSAN_SHADOW_COUNT=4"
+FLAGS=" -I../rtl -I../.. -I../../sanitizer_common -fPIC -g -Wall -Werror -fno-exceptions -DTSAN_GO -DSANITIZER_GO -DTSAN_SHADOW_COUNT=4"
if [ "$DEBUG" == "" ]; then
FLAGS+=" -DTSAN_DEBUG=0 -O3 -fomit-frame-pointer"
else
FLAGS+=" -DTSAN_DEBUG=1 -g"
fi
+if [ "$LINUX" != "" ]; then
+ FLAGS+=" -ffreestanding"
+fi
+
echo gcc gotsan.cc -S -o tmp.s $FLAGS $CFLAGS
gcc gotsan.cc -S -o tmp.s $FLAGS $CFLAGS
cat tmp.s $ASMS > gotsan.s
diff --git a/compiler-rt/lib/tsan/go/tsan_go.cc b/compiler-rt/lib/tsan/go/tsan_go.cc
index 11f14dac2c9..13cc569fbd0 100644
--- a/compiler-rt/lib/tsan/go/tsan_go.cc
+++ b/compiler-rt/lib/tsan/go/tsan_go.cc
@@ -39,7 +39,7 @@ void internal_start_thread(void(*func)(void*), void *arg) {
extern "C" int goCallbackCommentPc(uptr pc, char **img, char **rtn,
char **filename, int *lineno);
-extern "C" void __libc_free(void *p);
+extern "C" void free(void *p);
ReportStack *SymbolizeCode(uptr addr) {
ReportStack *s = NewReportStackEntry(addr);
@@ -52,9 +52,9 @@ ReportStack *SymbolizeCode(uptr addr) {
s->file = internal_strdup(filename);
s->line = lineno;
s->col = 0;
- __libc_free(img);
- __libc_free(rtn);
- __libc_free(filename);
+ free(img);
+ free(rtn);
+ free(filename);
}
return s;
}
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h b/compiler-rt/lib/tsan/rtl/tsan_platform.h
index 30137982ef4..b557fa1caec 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform.h
@@ -12,9 +12,8 @@
// Platform-specific code.
//===----------------------------------------------------------------------===//
-#ifndef TSAN_LINUX_H
-#define TSAN_LINUX_H
-#ifdef __linux__
+#ifndef TSAN_PLATFORM_H
+#define TSAN_PLATFORM_H
#include "tsan_rtl.h"
@@ -99,5 +98,4 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
# error "Only 64-bit is supported"
#endif
-#endif // __linux__
-#endif // TSAN_LINUX_H
+#endif // TSAN_PLATFORM_H
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
new file mode 100644
index 00000000000..e56304c4152
--- /dev/null
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
@@ -0,0 +1,108 @@
+//===-- tsan_platform_mac.cc ----------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of ThreadSanitizer (TSan), a race detector.
+//
+// Linux-specific code.
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_libc.h"
+#include "sanitizer_common/sanitizer_procmaps.h"
+#include "tsan_platform.h"
+#include "tsan_rtl.h"
+#include "tsan_flags.h"
+
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sched.h>
+
+namespace __sanitizer {
+
+void Die() {
+ _exit(1);
+}
+
+} // namespace __sanitizer
+
+namespace __tsan {
+
+ScopedInRtl::ScopedInRtl() {
+}
+
+ScopedInRtl::~ScopedInRtl() {
+}
+
+uptr GetShadowMemoryConsumption() {
+ return 0;
+}
+
+void FlushShadowMemory() {
+}
+
+void InitializeShadowMemory() {
+ uptr shadow = (uptr)MmapFixedNoReserve(kLinuxShadowBeg,
+ kLinuxShadowEnd - kLinuxShadowBeg);
+ if (shadow != kLinuxShadowBeg) {
+ TsanPrintf("FATAL: ThreadSanitizer can not mmap the shadow memory\n");
+ TsanPrintf("FATAL: Make sure to compile with -fPIE and "
+ "to link with -pie.\n");
+ Die();
+ }
+ DPrintf("kLinuxShadow %zx-%zx (%zuGB)\n",
+ kLinuxShadowBeg, kLinuxShadowEnd,
+ (kLinuxShadowEnd - kLinuxShadowBeg) >> 30);
+ DPrintf("kLinuxAppMem %zx-%zx (%zuGB)\n",
+ kLinuxAppMemBeg, kLinuxAppMemEnd,
+ (kLinuxAppMemEnd - kLinuxAppMemBeg) >> 30);
+}
+
+const char *InitializePlatform() {
+ void *p = 0;
+ if (sizeof(p) == 8) {
+ // Disable core dumps, dumping of 16TB usually takes a bit long.
+ // The following magic is to prevent clang from replacing it with memset.
+ volatile rlimit lim;
+ lim.rlim_cur = 0;
+ lim.rlim_max = 0;
+ setrlimit(RLIMIT_CORE, (rlimit*)&lim);
+ }
+
+ return getenv("TSAN_OPTIONS");
+}
+
+void FinalizePlatform() {
+ fflush(0);
+}
+
+uptr GetTlsSize() {
+ return 0;
+}
+
+void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
+ uptr *tls_addr, uptr *tls_size) {
+ *stk_addr = 0;
+ *stk_size = 0;
+ *tls_addr = 0;
+ *tls_size = 0;
+}
+
+} // namespace __tsan
OpenPOWER on IntegriCloud