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// UNSUPPORTED: ios
6
7// RUN: rm -rf %t && mkdir -p %t
8// RUN: cp `%clang_asan -print-file-name=lib`/darwin/libclang_rt.asan_osx_dynamic.dylib \
9// RUN: %t/libclang_rt.asan_osx_dynamic.dylib
10
11// RUN: %clangxx_asan %s -o %t/a.out
12// RUN: %clangxx -DSHARED_LIB %s \
13// RUN: -dynamiclib -o %t/dummy-so.dylib
14
15// RUN: ( cd %t && \
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 && \
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 && \
24// RUN: %env_asan_opts=strip_env=0 \
25// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
26// RUN: %run ./a.out 2>&1 ) | FileCheck %s --check-prefix=CHECK-KEEP || exit 1
27
28// RUN: ( cd %t && \
29// RUN: DYLD_INSERT_LIBRARIES=%t/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
30// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1
31
32#if !defined(SHARED_LIB)
33#include <stdio.h>
34#include <stdlib.h>
35
36int main() {
37 const char kEnvName[] = "DYLD_INSERT_LIBRARIES";
38 printf(format: "%s=%s\n", kEnvName, getenv(name: kEnvName));
39 // CHECK: {{DYLD_INSERT_LIBRARIES=dummy-so.dylib}}
40 // CHECK-KEEP: {{DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib}}
41 return 0;
42}
43#else // SHARED_LIB
44void foo() {}
45#endif // SHARED_LIB
46

source code of compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp