diff --git a/compiler-rt/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc b/compiler-rt/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc new file mode 100644 index 000000000000..f2b9dd4eda9b --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc @@ -0,0 +1,30 @@ +// Check that memset() call from a shared library gets intercepted. + +// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \ +// RUN: -shared -o %T/libinterception-in-shared-lib-test.so \ +// RUN: -fPIC +// TODO(glider): figure out how to set rpath in a more portable way and unite +// this test with ../Linux/interception-in-shared-lib-test.cc. +// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable-path -L%T -linterception-in-shared-lib-test && \ +// RUN: not %t 2>&1 | FileCheck %s + +#include +#include + +#if defined(SHARED_LIB) +extern "C" +void my_memset(void *p, size_t sz) { + memset(p, 0, sz); +} +#else +extern "C" void my_memset(void *p, size_t sz); + +int main(int argc, char *argv[]) { + char buf[10]; + my_memset(buf, 11); + // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}} + // CHECK: {{WRITE of size 11 at 0x.* thread T0}} + // CHECK: {{ #0 0x.* in my_memset .*interception-in-shared-lib-test.cc:17}} + return 0; +} +#endif diff --git a/compiler-rt/test/asan/TestCases/interception-in-shared-lib-test.cc b/compiler-rt/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc similarity index 60% rename from compiler-rt/test/asan/TestCases/interception-in-shared-lib-test.cc rename to compiler-rt/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc index 1aa71ffc159a..f632e8e0e776 100644 --- a/compiler-rt/test/asan/TestCases/interception-in-shared-lib-test.cc +++ b/compiler-rt/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc @@ -1,14 +1,22 @@ // Check that memset() call from a shared library gets intercepted. -// RUN: %clangxx_asan -O0 %p/SharedLibs/shared-lib-test-so.cc \ +// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \ // RUN: -shared -o %T/libinterception-in-shared-lib-test.so \ // RUN: -fPIC +// TODO(glider): figure out how to set rpath in a more portable way and unite +// this test with ../Darwin/interception-in-shared-lib-test.cc. // RUN: %clangxx_asan -O0 %s -o %t -Wl,-R,\$ORIGIN -L%T -linterception-in-shared-lib-test && \ // RUN: not %t 2>&1 | FileCheck %s #include #include +#if defined(SHARED_LIB) +extern "C" +void my_memset(void *p, size_t sz) { + memset(p, 0, sz); +} +#else extern "C" void my_memset(void *p, size_t sz); int main(int argc, char *argv[]) { @@ -16,6 +24,7 @@ int main(int argc, char *argv[]) { my_memset(buf, 11); // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}} // CHECK: {{WRITE of size 11 at 0x.* thread T0}} - // CHECK: {{ #0 0x.* in my_memset .*shared-lib-test-so.cc:31}} + // CHECK: {{ #0 0x.* in my_memset .*interception-in-shared-lib-test.cc:17}} return 0; } +#endif diff --git a/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc b/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc index 6aedc93be349..8ae352f6a208 100644 --- a/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc +++ b/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc @@ -25,8 +25,3 @@ extern "C" void inc2(int *a, int index) { a[index]++; } - -extern "C" -void my_memset(void *p, size_t sz) { - memset(p, 0, sz); -}