1 // RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t.so
2 // RUN: %clangxx --std=c++11 %s -o %t
3 // RUN: %env_tool_opts=verbosity=2 %run %t 2>&1 | FileCheck %s
4
5 // Does not call __tls_get_addr
6 // UNSUPPORTED: i386-linux
7
8 // Do not intercept __tls_get_addr
9 // UNSUPPORTED: lsan, ubsan, android
10
11 // FIXME: Investigate
12 // UNSUPPORTED: powerpc64
13
14 #include <string.h>
15
16 #ifndef BUILD_DSO
17
18 #include <assert.h>
19 #include <dlfcn.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 char buff[10000];
24
main(int argc,char * argv[])25 int main(int argc, char *argv[]) {
26 sprintf(buff, "rm -f %s.so.*", argv[0]);
27 system(buff);
28
29 void *prev_handle = 0;
30 for (int i = 0; i < 600; ++i) {
31 sprintf(buff, "cp %s.so %s.so.%d", argv[0], argv[0], i);
32 system(buff);
33
34 sprintf(buff, "%s.so.%d", argv[0], i);
35 void *handle = dlopen(buff, RTLD_LAZY);
36 assert(handle != 0);
37 assert(handle != prev_handle);
38 prev_handle = handle;
39
40 typedef void (*FnType)(char c);
41 ((FnType)dlsym(handle, "StoreToTLS"))(i);
42 }
43 return 0;
44 }
45
46 #else // BUILD_DSO
47 __thread char huge_thread_local_array[1 << 12];
48
StoreToTLS(char c)49 extern "C" void StoreToTLS(char c) {
50 memset(huge_thread_local_array, c, sizeof(huge_thread_local_array));
51 }
52 #endif // BUILD_DSO
53
54 // CHECK: DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
55 // CHECK: DTLS_NextBlock [[DTLS]] 0
56 // CHECK: DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
57 // CHECK: DTLS_NextBlock [[DTLS]] 1
58