Debian Codegraph @

compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp

raw
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=3 %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: hwasan, lsan, ubsan, android
10
11 // FIXME: Investigate
12 // UNSUPPORTED: target=powerpc64{{.*}}
13
14 // Fails because AArch64 uses TLSDESC instead of __tls_get_addr.
15 // UNSUPPORTED: aarch64-target-arch
16
17 #include <string.h>
18
19 #ifndef BUILD_DSO
20
21 #include <assert.h>
22 #include <dlfcn.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 char buff[10000];
27
28 int main(int argc, char *argv[]) {
29 sprintf(buff, "rm -f %s.so.*", argv[0]);
30 system(buff);
31
32 void *prev_handle = 0;
33 for (int i = 0; i < 600; ++i) {
34 sprintf(buff, "cp %s.so %s.so.%d", argv[0], argv[0], i);
35 system(buff);
36
37 sprintf(buff, "%s.so.%d", argv[0], i);
38 void *handle = dlopen(buff, RTLD_LAZY);
39 assert(handle != 0);
40 assert(handle != prev_handle);
41 prev_handle = handle;
42
43 typedef void (*FnType)(char c);
44 ((FnType)dlsym(handle, "StoreToTLS"))(i);
45 }
46 return 0;
47 }
48
49 #else // BUILD_DSO
50 __thread char huge_thread_local_array[1 << 12];
51
52 extern "C" void StoreToTLS(char c) {
53 memset(huge_thread_local_array, c, sizeof(huge_thread_local_array));
54 }
55 #endif // BUILD_DSO
56
57 // CHECK: DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
58 // CHECK: DTLS_NextBlock [[DTLS]] 0
59 // CHECK: DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
60 // CHECK: DTLS_NextBlock [[DTLS]] 1