blob: 1a93fe6617e183c5f4dc520fa6dd6b92c34f82d9 [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so
2// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3
4// If we mention TSAN_OPTIONS, the test won't run from test_output.sh script.
5
6// Test case for
7// https://code.google.com/p/thread-sanitizer/issues/detail?id=80
8
9#ifdef BUILD_SO
10
11#include <stdio.h>
12
13extern "C"
14void sofunc() {
15 fprintf(stderr, "HELLO FROM SO\n");
16}
17
18#else // BUILD_SO
19
20#include <dlfcn.h>
21#include <stdio.h>
22#include <stddef.h>
23#include <unistd.h>
24#include <string>
25
26void *lib;
27void *lib2;
28
29struct Closer {
30 ~Closer() {
31 dlclose(lib);
32 fprintf(stderr, "CLOSED SO\n");
33 }
34};
35static Closer c;
36
37int main(int argc, char *argv[]) {
38 lib = dlopen((std::string(argv[0]) + std::string("-so.so")).c_str(),
39 RTLD_NOW|RTLD_NODELETE);
40 if (lib == 0) {
41 printf("error in dlopen: %s\n", dlerror());
42 return 1;
43 }
44 void *f = dlsym(lib, "sofunc");
45 if (f == 0) {
46 printf("error in dlsym: %s\n", dlerror());
47 return 1;
48 }
49 ((void(*)())f)();
50 return 0;
51}
52
53#endif // BUILD_SO
54
55// CHECK: HELLO FROM SO
56// CHECK-NOT: Inconsistency detected by ld.so
57// CHECK: CLOSED SO
58