diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2014-10-14 09:32:45 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2014-10-14 09:32:45 +0000 |
commit | ea2f3bffca04ebb3fd91949ae5f0c5b1c6ff015f (patch) | |
tree | e589f8b8a91cb81486fb1bd868063ce3c4171f2c /compiler-rt/test/tsan/dlclose.cc | |
parent | 7c558cf4d6b9a21766f71159463d5a50a133a486 (diff) | |
download | bcm5719-llvm-ea2f3bffca04ebb3fd91949ae5f0c5b1c6ff015f.tar.gz bcm5719-llvm-ea2f3bffca04ebb3fd91949ae5f0c5b1c6ff015f.zip |
tsan: refactor atexit handling
The current handling (manual execution of atexit callbacks)
is overly complex and leads to constant problems due to mutual ordering of callbacks.
Instead simply wrap callbacks into our wrapper to establish
the necessary synchronization.
Fixes issue https://code.google.com/p/thread-sanitizer/issues/detail?id=80
llvm-svn: 219675
Diffstat (limited to 'compiler-rt/test/tsan/dlclose.cc')
-rw-r--r-- | compiler-rt/test/tsan/dlclose.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/dlclose.cc b/compiler-rt/test/tsan/dlclose.cc new file mode 100644 index 00000000000..5325d6f0f8b --- /dev/null +++ b/compiler-rt/test/tsan/dlclose.cc @@ -0,0 +1,56 @@ +// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so +// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s + +// Test case for +// https://code.google.com/p/thread-sanitizer/issues/detail?id=80 + +#ifdef BUILD_SO + +#include <stdio.h> + +extern "C" +void sofunc() { + fprintf(stderr, "HELLO FROM SO\n"); +} + +#else // BUILD_SO + +#include <dlfcn.h> +#include <stdio.h> +#include <stddef.h> +#include <unistd.h> +#include <string> + +void *lib; +void *lib2; + +struct Closer { + ~Closer() { + dlclose(lib); + fprintf(stderr, "CLOSED SO\n"); + } +}; +static Closer c; + +int main(int argc, char *argv[]) { + lib = dlopen((std::string(argv[0]) + std::string("-so.so")).c_str(), + RTLD_NOW|RTLD_NODELETE); + if (lib == 0) { + printf("error in dlopen: %s\n", dlerror()); + return 1; + } + void *f = dlsym(lib, "sofunc"); + if (f == 0) { + printf("error in dlsym: %s\n", dlerror()); + return 1; + } + ((void(*)())f)(); + return 0; +} + +#endif // BUILD_SO + +// CHECK: HELLO FROM SO +// CHECK-NOT: Inconsistency detected by ld.so +// CHECK: CLOSED SO + |