1 // REQUIRES: asan-64-bits
2 // Regression test: __tls_get_addr interceptor must recognize static TLS.
3 //
4 // RUN: %clangxx_asan -DSHARED %s -shared -o %t-so.so -fPIC
5 // RUN: %clangxx_asan %s -ldl -pthread -o %t %t-so.so
6 // RUN: %env_asan_opts=verbosity=2 %run %t 2>&1 | FileCheck %s
7 
8 // CHECK: before
9 // CHECK: __tls_get_addr: static tls
10 // CHECK: after
11 
12 // XFAIL: aarch64
13 // binutils 2.26 has a change that causes this test to fail on powerpc64.
14 // UNSUPPORTED: powerpc64
15 
16 #ifndef SHARED
17 #include <stdio.h>
18 
19 unsigned *f();
main(int argc,char * argv[])20 int main(int argc, char *argv[]) {
21   fprintf(stderr, "before\n");
22   f();
23   fprintf(stderr, "after\n");
24   return 0;
25 }
26 #else  // SHARED
27 static __thread unsigned ThreadLocal;
f()28 unsigned *f() {
29   return &ThreadLocal;
30 }
31 #endif
32