brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 8f9b0b4 Raw
50 lines · cpp
1// Test that ASan doesn't deadlock in __interceptor_pthread_create called2// from dlopened shared library constructor. The deadlock happens only in shared3// ASan runtime with recent Glibc (2.23 fits) when __interceptor_pthread_create4// grabs global Glibc's GL(dl_load_lock) and waits for tls_get_addr_tail that5// also tries to acquire it.6//7// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-so.so8// RUN: %clangxx_asan %s -o %t9// RUN: %run %t 2>&110 11// dlopen() can not be intercepted on Android12// UNSUPPORTED: android13// REQUIRES: x86-target-arch14 15#ifdef BUILD_SO16 17#include <stdio.h>18#include <pthread.h>19#include <unistd.h>20 21void *threadFn(void *) {22  fprintf(stderr, "thread started\n");23  while (true) {24    usleep(100000);25  }26  return 0;27}28 29void __attribute__((constructor)) startPolling() {30  fprintf(stderr, "initializing library\n");31  pthread_t t;32  pthread_create(&t, 0, &threadFn, 0);33  fprintf(stderr, "done\n");34}35 36#else37 38#include <dlfcn.h>39#include <stdlib.h>40#include <string>41 42int main(int argc, char **argv) {43  std::string path = std::string(argv[0]) + "-so.so";44  void *handle = dlopen(path.c_str(), RTLD_LAZY);45  if (!handle)46    abort();47  return 0;48}49#endif50