1 // Build a library with origin tracking and an executable w/o origin tracking. 2 // Test that origin tracking is enabled at runtime. 3 // RUN: %clangxx_lsan -O0 %s -DBUILD_SO -fPIC -shared -o %t-so.so 4 // RUN: %clangxx_lsan -O0 %s -ldl -o %t && not %run %t 2>&1 | FileCheck %s 5 // RUN: %clangxx_lsan -O0 %s -ldl -o %t -DSUPPRESS_LEAK && %run %t 2>&1 6 7 #ifdef BUILD_SO 8 9 # include <stdlib.h> 10 11 extern "C" { 12 void *my_alloc(unsigned sz) { return malloc(sz); } 13 } // extern "C" 14 15 #else // BUILD_SO 16 17 # include <assert.h> 18 # include <dlfcn.h> 19 # include <stdlib.h> 20 # include <string> 21 22 # ifdef SUPPRESS_LEAK 23 extern "C" const char *__lsan_default_suppressions() { 24 return "leak:^<unknown module>$"; 25 } 26 # endif 27 28 void *p; 29 int main(int argc, char **argv) { 30 31 std::string path = std::string(argv[0]) + "-so.so"; 32 33 dlerror(); 34 35 void *handle = dlopen(path.c_str(), RTLD_LAZY); 36 assert(handle != 0); 37 typedef void *(*fn)(unsigned sz); 38 fn my_alloc = (fn)dlsym(handle, "my_alloc"); 39 40 p = my_alloc(1); 41 p = my_alloc(2); 42 p = my_alloc(3); 43 44 dlclose(handle); 45 return 0; 46 } 47 48 #endif // BUILD_SO 49 50 // CHECK: Direct leak 51