Home | History | Annotate | Download | only in Darwin
      1 // Check that when launching with DYLD_INSERT_LIBRARIES, we properly remove
      2 // the ASan dylib from the environment variable (both when using an absolute
      3 // or relative path) and also that the other dylibs are left untouched.
      4 
      5 // RUN: mkdir -p %T/dyld_insert_libraries_remove
      6 // RUN: cp `%clang_asan %s -fsanitize=address -### 2>&1 \
      7 // RUN:   | grep "libclang_rt.asan_osx_dynamic.dylib" \
      8 // RUN:   | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/'` \
      9 // RUN:   %T/dyld_insert_libraries_remove/libclang_rt.asan_osx_dynamic.dylib
     10 
     11 // RUN: %clangxx_asan %s -o %T/dyld_insert_libraries_remove/a.out
     12 // RUN: %clangxx -DSHARED_LIB %s \
     13 // RUN:     -dynamiclib -o %T/dyld_insert_libraries_remove/dummy-so.dylib
     14 
     15 // RUN: ( cd %T/dyld_insert_libraries_remove && \
     16 // RUN:   DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
     17 // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
     18 
     19 // RUN: ( cd %T/dyld_insert_libraries_remove && \
     20 // RUN:   DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
     21 // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
     22 
     23 // RUN: ( cd %T/dyld_insert_libraries_remove && \
     24 // RUN:   DYLD_INSERT_LIBRARIES=%T/dyld_insert_libraries_remove/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
     25 // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
     26 
     27 #if !defined(SHARED_LIB)
     28 #include <stdio.h>
     29 #include <stdlib.h>
     30 
     31 int main() {
     32   const char kEnvName[] = "DYLD_INSERT_LIBRARIES";
     33   printf("%s=%s\n", kEnvName, getenv(kEnvName));
     34   // CHECK: {{DYLD_INSERT_LIBRARIES=dummy-so.dylib}}
     35   return 0;
     36 }
     37 #else  // SHARED_LIB
     38 void foo() {}
     39 #endif  // SHARED_LIB
     40