Home | History | Annotate | Download | only in TestCases
      1 // Test that dynamically allocated TLS space is included in the root set.
      2 // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0"
      3 // RUN: %clangxx %p/SharedLibs/huge_tls_lib_so.cc -fPIC -shared -o %t-so.so
      4 // RUN: %clangxx_lsan %s -o %t
      5 // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %t 2>&1 | FileCheck %s
      6 // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %t 2>&1
      7 // RUN: LSAN_OPTIONS="" %t 2>&1
      8 
      9 #include <assert.h>
     10 #include <dlfcn.h>
     11 #include <stdio.h>
     12 #include <stdlib.h>
     13 #include <string>
     14 
     15 int main(int argc, char *argv[]) {
     16   std::string path = std::string(argv[0]) + "-so.so";
     17 
     18   void *handle = dlopen(path.c_str(), RTLD_LAZY);
     19   assert(handle != 0);
     20   typedef void **(* store_t)(void *p);
     21   store_t StoreToTLS = (store_t)dlsym(handle, "StoreToTLS");
     22   assert(dlerror() == 0);
     23 
     24   void *p = malloc(1337);
     25   void **p_in_tls = StoreToTLS(p);
     26   assert(*p_in_tls == p);
     27   fprintf(stderr, "Test alloc: %p.\n", p);
     28   return 0;
     29 }
     30 // CHECK: Test alloc: [[ADDR:.*]].
     31 // CHECK: leaked 1337 byte object at [[ADDR]]
     32 // CHECK: LeakSanitizer: detected memory leaks
     33 // CHECK: SUMMARY: LeakSanitizer:
     34