1*673dc3d4SNico Weber // Check that when launching with DYLD_INSERT_LIBRARIES, we properly remove
2*673dc3d4SNico Weber // the ASan dylib from the environment variable (both when using an absolute
3*673dc3d4SNico Weber // or relative path) and also that the other dylibs are left untouched.
4*673dc3d4SNico Weber 
5*673dc3d4SNico Weber // UNSUPPORTED: ios
6*673dc3d4SNico Weber 
7*673dc3d4SNico Weber // RUN: rm -rf %t && mkdir -p %t
8*673dc3d4SNico Weber // RUN: cp `%clang_asan -print-file-name=lib`/darwin/libclang_rt.asan_osx_dynamic.dylib \
9*673dc3d4SNico Weber // RUN:   %t/libclang_rt.asan_osx_dynamic.dylib
10*673dc3d4SNico Weber 
11*673dc3d4SNico Weber // RUN: %clangxx_asan %s -o %t/a.out
12*673dc3d4SNico Weber // RUN: %clangxx -DSHARED_LIB %s \
13*673dc3d4SNico Weber // RUN:     -dynamiclib -o %t/dummy-so.dylib
14*673dc3d4SNico Weber 
15*673dc3d4SNico Weber // RUN: ( cd %t && \
16*673dc3d4SNico Weber // RUN:   DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
17*673dc3d4SNico Weber // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
18*673dc3d4SNico Weber 
19*673dc3d4SNico Weber // RUN: ( cd %t && \
20*673dc3d4SNico Weber // RUN:   DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
21*673dc3d4SNico Weber // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
22*673dc3d4SNico Weber 
23*673dc3d4SNico Weber // RUN: ( cd %t && \
24*673dc3d4SNico Weber // RUN:   %env_asan_opts=strip_env=0 \
25*673dc3d4SNico Weber // RUN:   DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
26*673dc3d4SNico Weber // RUN:   %run ./a.out 2>&1 ) | FileCheck %s --check-prefix=CHECK-KEEP || exit 1
27*673dc3d4SNico Weber 
28*673dc3d4SNico Weber // RUN: ( cd %t && \
29*673dc3d4SNico Weber // RUN:   DYLD_INSERT_LIBRARIES=%t/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
30*673dc3d4SNico Weber // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
31*673dc3d4SNico Weber 
32*673dc3d4SNico Weber #if !defined(SHARED_LIB)
33*673dc3d4SNico Weber #include <stdio.h>
34*673dc3d4SNico Weber #include <stdlib.h>
35*673dc3d4SNico Weber 
main()36*673dc3d4SNico Weber int main() {
37*673dc3d4SNico Weber   const char kEnvName[] = "DYLD_INSERT_LIBRARIES";
38*673dc3d4SNico Weber   printf("%s=%s\n", kEnvName, getenv(kEnvName));
39*673dc3d4SNico Weber   // CHECK: {{DYLD_INSERT_LIBRARIES=dummy-so.dylib}}
40*673dc3d4SNico Weber   // CHECK-KEEP: {{DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib}}
41*673dc3d4SNico Weber   return 0;
42*673dc3d4SNico Weber }
43*673dc3d4SNico Weber #else  // SHARED_LIB
foo()44*673dc3d4SNico Weber void foo() {}
45*673dc3d4SNico Weber #endif  // SHARED_LIB
46