[compiler-rt] r236484 - tsan: add memory access functions that accept pc
Dmitry Vyukov
dvyukov at google.com
Tue May 5 01:09:47 PDT 2015
Author: dvyukov
Date: Tue May 5 03:09:46 2015
New Revision: 236484
URL: http://llvm.org/viewvc/llvm-project?rev=236484&view=rev
Log:
tsan: add memory access functions that accept pc
This is required for Java support, as real PCs don't work for Java.
Added:
compiler-rt/trunk/test/tsan/java_race_pc.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h
compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h
compiler-rt/trunk/test/tsan/java.h
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc?rev=236484&r1=236483&r2=236484&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc Tue May 5 03:09:46 2015
@@ -38,6 +38,16 @@ void __tsan_write16(void *addr) {
MemoryWrite(cur_thread(), CALLERPC, (uptr)addr + 8, kSizeLog8);
}
+void __tsan_read16_pc(void *addr, void *pc) {
+ MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
+ MemoryRead(cur_thread(), (uptr)pc, (uptr)addr + 8, kSizeLog8);
+}
+
+void __tsan_write16_pc(void *addr, void *pc) {
+ MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
+ MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr + 8, kSizeLog8);
+}
+
// __tsan_unaligned_read/write calls are emitted by compiler.
void __tsan_unaligned_read2(const void *addr) {
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h?rev=236484&r1=236483&r2=236484&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h Tue May 5 03:09:46 2015
@@ -51,6 +51,18 @@ SANITIZER_INTERFACE_ATTRIBUTE void __tsa
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_unaligned_write8(void *addr);
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_unaligned_write16(void *addr);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read1_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read2_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read4_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read8_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read16_pc(void *addr, void *pc);
+
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write1_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write2_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write4_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write8_pc(void *addr, void *pc);
+SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write16_pc(void *addr, void *pc);
+
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_vptr_read(void **vptr_p);
SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_vptr_update(void **vptr_p, void *new_val);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h?rev=236484&r1=236483&r2=236484&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h Tue May 5 03:09:46 2015
@@ -50,6 +50,38 @@ void __tsan_write8(void *addr) {
MemoryWrite(cur_thread(), CALLERPC, (uptr)addr, kSizeLog8);
}
+void __tsan_read1_pc(void *addr, void *pc) {
+ MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
+}
+
+void __tsan_read2_pc(void *addr, void *pc) {
+ MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
+}
+
+void __tsan_read4_pc(void *addr, void *pc) {
+ MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
+}
+
+void __tsan_read8_pc(void *addr, void *pc) {
+ MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
+}
+
+void __tsan_write1_pc(void *addr, void *pc) {
+ MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
+}
+
+void __tsan_write2_pc(void *addr, void *pc) {
+ MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
+}
+
+void __tsan_write4_pc(void *addr, void *pc) {
+ MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
+}
+
+void __tsan_write8_pc(void *addr, void *pc) {
+ MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
+}
+
void __tsan_vptr_update(void **vptr_p, void *new_val) {
CHECK_EQ(sizeof(vptr_p), 8);
if (*vptr_p != new_val) {
Modified: compiler-rt/trunk/test/tsan/java.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java.h?rev=236484&r1=236483&r2=236484&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/java.h (original)
+++ compiler-rt/trunk/test/tsan/java.h Tue May 5 03:09:46 2015
@@ -18,4 +18,7 @@ int __tsan_java_mutex_unlock_rec(jptr a
int __tsan_java_acquire(jptr addr);
int __tsan_java_release(jptr addr);
int __tsan_java_release_store(jptr addr);
+
+void __tsan_read1_pc(jptr addr, jptr pc);
+void __tsan_write1_pc(jptr addr, jptr pc);
}
Added: compiler-rt/trunk/test/tsan/java_race_pc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_race_pc.cc?rev=236484&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/java_race_pc.cc (added)
+++ compiler-rt/trunk/test/tsan/java_race_pc.cc Tue May 5 03:09:46 2015
@@ -0,0 +1,36 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "java.h"
+
+void foobar() {
+}
+
+void barbaz() {
+}
+
+void *Thread(void *p) {
+ barrier_wait(&barrier);
+ __tsan_read1_pc((jptr)p, (jptr)foobar + 1);
+ return 0;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ int const kHeapSize = 1024 * 1024;
+ jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+ __tsan_java_init(jheap, kHeapSize);
+ const int kBlockSize = 16;
+ __tsan_java_alloc(jheap, kBlockSize);
+ pthread_t th;
+ pthread_create(&th, 0, Thread, (void*)jheap);
+ __tsan_write1_pc((jptr)jheap, (jptr)barbaz + 1);
+ barrier_wait(&barrier);
+ pthread_join(th, 0);
+ __tsan_java_free(jheap, kBlockSize);
+ fprintf(stderr, "DONE\n");
+ return __tsan_java_fini();
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: #0 foobar
+// CHECK: #0 barbaz
+// CHECK: DONE
More information about the llvm-commits
mailing list