1 // Test that we don't crash accessing DTLS from malloc hook.
3 // RUN: %clang %s -o %t
4 // RUN: %clang %s -DBUILD_SO -fPIC -o %t-so.so -shared
5 // RUN: %run %t 2>&1 | FileCheck %s
9 // No allocator and hooks.
19 typedef long *(*get_t
)();
21 void *Thread(void *unused
) { return GetTls(); }
23 __thread
long recursive_hook
;
25 // CHECK: __sanitizer_malloc_hook:
26 void __sanitizer_malloc_hook(const volatile void *ptr
, size_t sz
)
27 __attribute__((disable_sanitizer_instrumentation
)) {
29 if (recursive_hook
== 1 && GetTls
)
30 fprintf(stderr
, "__sanitizer_malloc_hook: %p\n", GetTls());
34 int main(int argc
, char *argv
[]) {
36 snprintf(path
, sizeof(path
), "%s-so.so", argv
[0]);
39 void *handle
= dlopen(path
, RTLD_LAZY
);
41 fprintf(stderr
, "%s\n", dlerror());
43 GetTls
= (get_t
)dlsym(handle
, "GetTls");
44 assert(dlerror() == 0);
47 pthread_create(&t
, 0, Thread
, 0);
49 pthread_create(&t
, 0, Thread
, 0);
54 __thread
long huge_thread_local_array
[1 << 17];
55 long *GetTls() { return &huge_thread_local_array
[0]; }