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: hwasan, lsan, ubsan, android
10
11// FIXME: Investigate
12// UNSUPPORTED: target=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
23char buff[10000];
24
25int main(int argc, char *argv[]) {
26 sprintf(s: buff, format: "rm -f %s.so.*", argv[0]);
27 system(command: buff);
28
29 void *prev_handle = 0;
30 for (int i = 0; i < 600; ++i) {
31 sprintf(s: buff, format: "cp %s.so %s.so.%d", argv[0], argv[0], i);
32 system(command: buff);
33
34 sprintf(s: buff, format: "%s.so.%d", argv[0], i);
35 void *handle = dlopen(file: 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: handle, name: "StoreToTLS"))(i);
42 }
43 return 0;
44}
45
46#else // BUILD_DSO
47__thread char huge_thread_local_array[1 << 12];
48
49extern "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

source code of compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp