| 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 |
// Fails because AArch64 uses TLSDESC instead of __tls_get_addr. |
| 17 |
// UNSUPPORTED: aarch64-target-arch |
| 18 |
|
| 19 |
#ifndef BUILD_SO |
| 20 |
# include <assert.h> |
| 21 |
# include <dlfcn.h> |
| 22 |
# include <pthread.h> |
| 23 |
# include <stdio.h> |
| 24 |
# include <stdlib.h> |
| 25 |
|
| 26 |
// CHECK-COUNT-2: __sanitizer_get_dtls_size: |
| 27 |
size_t __sanitizer_get_dtls_size(const void *ptr) |
| 28 |
__attribute__((disable_sanitizer_instrumentation)) { |
| 29 |
fprintf(stderr, "__sanitizer_get_dtls_size: %p\n", ptr); |
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
typedef long *(*get_t)(); |
| 34 |
get_t GetTls; |
| 35 |
void *Thread(void *unused) { return GetTls(); } |
| 36 |
|
| 37 |
int main(int argc, char *argv[]) { |
| 38 |
char path[4096]; |
| 39 |
snprintf(path, sizeof(path), "%s-so.so", argv[0]); |
| 40 |
int i; |
| 41 |
|
| 42 |
void *handle = dlopen(path, RTLD_LAZY); |
| 43 |
if (!handle) |
| 44 |
fprintf(stderr, "%s\n", dlerror()); |
| 45 |
assert(handle != 0); |
| 46 |
GetTls = (get_t)dlsym(handle, "GetTls"); |
| 47 |
assert(dlerror() == 0); |
| 48 |
|
| 49 |
pthread_t t; |
| 50 |
pthread_create(&t, 0, Thread, 0); |
| 51 |
pthread_join(t, 0); |
| 52 |
pthread_create(&t, 0, Thread, 0); |
| 53 |
pthread_join(t, 0); |
| 54 |
return 0; |
| 55 |
} |
| 56 |
#else // BUILD_SO |
| 57 |
__thread long huge_thread_local_array[1 << 17]; |
| 58 |
long *GetTls() { return &huge_thread_local_array[0]; } |
| 59 |
#endif |