1 | // RUN: %clang -g %s -o %t |
2 | // RUN: %clang -g %s -DBUILD_SO -fPIC -o %t-so.so -shared |
3 | // RUN: %run %t 2>&1 | FileCheck %s |
4 | |
5 | // REQUIRES: glibc |
6 | |
7 | // `__tls_get_addr` is somehow not invoked. |
8 | // XFAIL: i386-linux |
9 | |
10 | // These don't intercept __tls_get_addr. |
11 | // XFAIL: lsan,hwasan,ubsan |
12 | |
13 | // FIXME: Fails for unknown reasons. |
14 | // UNSUPPORTED: powerpc64le-target-arch |
15 | |
16 | #ifndef BUILD_SO |
17 | # include <assert.h> |
18 | # include <dlfcn.h> |
19 | # include <pthread.h> |
20 | # include <stdio.h> |
21 | # include <stdlib.h> |
22 | |
23 | // CHECK-COUNT-2: __sanitizer_get_dtls_size: |
24 | size_t __sanitizer_get_dtls_size(const void *ptr) |
25 | __attribute__((disable_sanitizer_instrumentation)) { |
26 | fprintf(stderr, format: "__sanitizer_get_dtls_size: %p\n" , ptr); |
27 | return 0; |
28 | } |
29 | |
30 | typedef long *(*get_t)(); |
31 | get_t GetTls; |
32 | void *Thread(void *unused) { return GetTls(); } |
33 | |
34 | int main(int argc, char *argv[]) { |
35 | char path[4096]; |
36 | snprintf(s: path, maxlen: sizeof(path), format: "%s-so.so" , argv[0]); |
37 | int i; |
38 | |
39 | void *handle = dlopen(file: path, RTLD_LAZY); |
40 | if (!handle) |
41 | fprintf(stderr, format: "%s\n" , dlerror()); |
42 | assert(handle != 0); |
43 | GetTls = (get_t)dlsym(handle: handle, name: "GetTls" ); |
44 | assert(dlerror() == 0); |
45 | |
46 | pthread_t t; |
47 | pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0); |
48 | pthread_join(th: t, thread_return: 0); |
49 | pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0); |
50 | pthread_join(th: t, thread_return: 0); |
51 | return 0; |
52 | } |
53 | #else // BUILD_SO |
54 | __thread long huge_thread_local_array[1 << 17]; |
55 | long *GetTls() { return &huge_thread_local_array[0]; } |
56 | #endif |
57 | |