summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2013-04-08 17:46:34 +0000
committerAlexander Potapenko <glider@google.com>2013-04-08 17:46:34 +0000
commit32efd25b939432d1c5b365fbb0438c3644a546f1 (patch)
tree7e642832aae424df6bbcdee1564b02389f0e5e59 /compiler-rt/lib/tsan
parent6bec4f9af34ae25db26b791482f4aaaeddb7e887 (diff)
downloadbcm5719-llvm-32efd25b939432d1c5b365fbb0438c3644a546f1.tar.gz
bcm5719-llvm-32efd25b939432d1c5b365fbb0438c3644a546f1.zip
[libsymbolized] If we can't find an address in the list of shared libraries, try to reload it.
Add a regression test for the case where such behavior helps TSan: 1. race is reported in the main module 2. new shared library is loaded 3. race is reported in the shared library llvm-svn: 179032
Diffstat (limited to 'compiler-rt/lib/tsan')
-rw-r--r--compiler-rt/lib/tsan/lit_tests/SharedLibs/lit.local.cfg4
-rw-r--r--compiler-rt/lib/tsan/lit_tests/SharedLibs/load_shared_lib-so.cc22
-rw-r--r--compiler-rt/lib/tsan/lit_tests/load_shared_lib.cc44
3 files changed, 70 insertions, 0 deletions
diff --git a/compiler-rt/lib/tsan/lit_tests/SharedLibs/lit.local.cfg b/compiler-rt/lib/tsan/lit_tests/SharedLibs/lit.local.cfg
new file mode 100644
index 00000000000..b3677c17a0f
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/SharedLibs/lit.local.cfg
@@ -0,0 +1,4 @@
+# Sources in this directory are compiled as shared libraries and used by
+# tests in parent directory.
+
+config.suffixes = []
diff --git a/compiler-rt/lib/tsan/lit_tests/SharedLibs/load_shared_lib-so.cc b/compiler-rt/lib/tsan/lit_tests/SharedLibs/load_shared_lib-so.cc
new file mode 100644
index 00000000000..d05aa6a40d1
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/SharedLibs/load_shared_lib-so.cc
@@ -0,0 +1,22 @@
+//===----------- load_shared_lib-so.cc --------------------------*- C++ -*-===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stddef.h>
+
+int GLOB_SHARED = 0;
+
+extern "C"
+void *write_from_so(void *unused) {
+ GLOB_SHARED++;
+ return NULL;
+}
diff --git a/compiler-rt/lib/tsan/lit_tests/load_shared_lib.cc b/compiler-rt/lib/tsan/lit_tests/load_shared_lib.cc
new file mode 100644
index 00000000000..598b4ca3109
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/load_shared_lib.cc
@@ -0,0 +1,44 @@
+// Check that if the list of shared libraries changes between the two race
+// reports, the second report occurring in a new shared library is still
+// symbolized correctly.
+
+// RUN: %clangxx_tsan -O1 %p/SharedLibs/load_shared_lib-so.cc \
+// RUN: -fPIC -shared -o %t-so.so
+// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
+
+#include <dlfcn.h>
+#include <pthread.h>
+#include <stdio.h>
+
+#include <string>
+
+int GLOB = 0;
+
+void *write_glob(void *unused) {
+ GLOB++;
+ return NULL;
+}
+
+void race_two_threads(void *(*access_callback)(void *)) {
+ pthread_t t1, t2;
+ pthread_create(&t1, NULL, access_callback, NULL);
+ pthread_create(&t2, NULL, access_callback, NULL);
+ pthread_join(t1, NULL);
+ pthread_join(t2, NULL);
+}
+
+int main(int argc, char *argv[]) {
+ std::string path = std::string(argv[0]) + std::string("-so.so");
+ race_two_threads(write_glob);
+ // CHECK: write_glob
+ void *lib = dlopen(path.c_str(), RTLD_NOW);
+ if (!lib) {
+ printf("error in dlopen(): %s\n", dlerror());
+ return 1;
+ }
+ void *(*write_from_so)(void *);
+ *(void **)&write_from_so = dlsym(lib, "write_from_so");
+ race_two_threads(write_from_so);
+ // CHECK: write_from_so
+ return 0;
+}
OpenPOWER on IntegriCloud