From cd2dd3df15523e2be8d2bbace27641d6ac9fa40d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 22 Feb 2015 22:43:40 +0000 Subject: Import compiler-rt trunk r230183. https://llvm.org/svn/llvm-project/compiler-rt/trunk@230183 --- test/asan/TestCases/Windows/dll_host.cc | 7 ++- .../TestCases/Windows/globals_multiple_dlls.cc | 51 ++++++++++++++++++++++ test/asan/TestCases/Windows/oom.cc | 12 +++++ test/asan/TestCases/Windows/symbols_path.cc | 22 ++++++++++ test/asan/TestCases/dlclose-test.cc | 7 +++ test/asan/TestCases/gc-test.cc | 6 ++- 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 test/asan/TestCases/Windows/globals_multiple_dlls.cc create mode 100644 test/asan/TestCases/Windows/oom.cc create mode 100644 test/asan/TestCases/Windows/symbols_path.cc (limited to 'test/asan/TestCases') diff --git a/test/asan/TestCases/Windows/dll_host.cc b/test/asan/TestCases/Windows/dll_host.cc index d3b4c149d009..71721fe29e88 100644 --- a/test/asan/TestCases/Windows/dll_host.cc +++ b/test/asan/TestCases/Windows/dll_host.cc @@ -6,9 +6,14 @@ // // Get the list of ASan wrappers exported by the main module RTL: // RUN: dumpbin /EXPORTS %t | grep -o "__asan_wrap[^ ]*" | grep -v @ | sort | uniq > %t.exported_wrappers +// FIXME: we should really check the other __asan exports too. +// RUN: dumpbin /EXPORTS %t | grep -o "__sanitizer_[^ ]*" | grep -v @ | sort | uniq >> %t.exported_wrappers // // Get the list of ASan wrappers imported by the DLL RTL: -// RUN: grep INTERCEPT_LIBRARY_FUNCTION %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed "s/.*(\(.*\)).*/__asan_wrap_\1/" | sort | uniq > %t.dll_imports +// [BEWARE: be really careful with the sed commands, as this test can be run +// from different environemnts with different shells and seds] +// RUN: grep INTERCEPT_LIBRARY_FUNCTION %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed -e s/.*(/__asan_wrap_/ | sed -e s/).*// | sort | uniq > %t.dll_imports +// RUN: grep "^INTERFACE_FUNCTION.*sanitizer" %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed -e s/.*(// | sed -e s/).*// | sort | uniq >> %t.dll_imports // // Now make sure the DLL thunk imports everything: // RUN: echo diff --git a/test/asan/TestCases/Windows/globals_multiple_dlls.cc b/test/asan/TestCases/Windows/globals_multiple_dlls.cc new file mode 100644 index 000000000000..634e5782796c --- /dev/null +++ b/test/asan/TestCases/Windows/globals_multiple_dlls.cc @@ -0,0 +1,51 @@ +// Make sure everything works even if the main module doesn't have any stack +// variables, thus doesn't explicitly reference any symbol exported by the +// runtime thunk. +// +// RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll +// RUN: %clang_cl_asan -O0 -DEXE %s -Fe%te.exe +// RUN: env ASAN_OPTIONS=report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s + +#include +#include +#include + +extern "C" { +#if defined(EXE) +int main(int argc, char **argv) { + if (argc != 2) { + printf("Usage: %s [client].dll\n", argv[0]); + return 101; + } + const char *dll_name = argv[1]; + +// CHECK: time to load DLL + printf("time to load DLL\n"); + fflush(0); + +// On DLL load, the "in DLL\n" string is registered: +// CHECK: Added Global{{.*}} size=19 +// CHECK: in DLL(reason=1) + HMODULE dll = LoadLibrary(dll_name); + if (dll == NULL) + return 3; + +// CHECK: in DLL(reason=0) +// CHECK-NEXT: Removed Global{{.*}} size=19 + if (!FreeLibrary(dll)) + return 4; + +// CHECK: bye! + printf("bye!\n"); + fflush(0); +} +#elif defined(DLL) +BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) { + printf("in DLL(reason=%d)\n", (int)reason); + fflush(0); + return TRUE; +} +#else +# error oops! +#endif +} diff --git a/test/asan/TestCases/Windows/oom.cc b/test/asan/TestCases/Windows/oom.cc new file mode 100644 index 000000000000..b24cddf17a97 --- /dev/null +++ b/test/asan/TestCases/Windows/oom.cc @@ -0,0 +1,12 @@ +// RUN: %clang_cl_asan -O0 %s -Fe%t +// RUN: not %run %t 2>&1 | FileCheck %s + +#include + +int main() { + while (true) { + void *ptr = malloc(200 * 1024 * 1024); // 200MB + free(ptr); + } +// CHECK: failed to allocate +} diff --git a/test/asan/TestCases/Windows/symbols_path.cc b/test/asan/TestCases/Windows/symbols_path.cc new file mode 100644 index 000000000000..3c69f8861d78 --- /dev/null +++ b/test/asan/TestCases/Windows/symbols_path.cc @@ -0,0 +1,22 @@ +// Make sure symbolization works even if the path to the .exe file changes. +// RUN: mkdir %t || true +// RUN: %clang_cl_asan -O0 %s -Fe%t/symbols_path.exe +// RUN: not %run %t/symbols_path.exe 2>&1 | FileCheck %s +// RUN: mkdir %t2 || true +// RUN: mv %t/* %t2 +// RUN: not %run %t2/symbols_path.exe 2>&1 | FileCheck %s + +#include + +int main() { + char *buffer = (char*)malloc(42); + buffer[-1] = 42; +// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] +// CHECK: WRITE of size 1 at [[ADDR]] thread T0 +// CHECK-NEXT: {{#0 .* main .*symbols_path.cc}}:[[@LINE-3]] +// CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region +// CHECK: allocated by thread T0 here: +// CHECK-NEXT: {{#0 .* malloc }} +// CHECK-NEXT: {{#1 .* main .*symbols_path.cc}}:[[@LINE-8]] + free(buffer); +} diff --git a/test/asan/TestCases/dlclose-test.cc b/test/asan/TestCases/dlclose-test.cc index 2d31aee5a32f..369abd3127cc 100644 --- a/test/asan/TestCases/dlclose-test.cc +++ b/test/asan/TestCases/dlclose-test.cc @@ -33,6 +33,13 @@ #include +#if defined(__FreeBSD__) +// The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before +// that, it was never implemented. So just define it to zero. +#undef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif + using std::string; typedef int *(fun_t)(); diff --git a/test/asan/TestCases/gc-test.cc b/test/asan/TestCases/gc-test.cc index ffbea85b2650..4ffa51dd22d3 100644 --- a/test/asan/TestCases/gc-test.cc +++ b/test/asan/TestCases/gc-test.cc @@ -1,6 +1,9 @@ // RUN: %clangxx_asan %s -pthread -o %t // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 +// RUN: %clangxx_asan -O3 %s -pthread -o %t +// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 +// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 // REQUIRES: stable-runtime #include @@ -9,6 +12,7 @@ #include static const int kNumThreads = 2; +static const int kLeftRedzoneSize = sizeof(void *) * 4; void *Thread(void *unused) { void *fake_stack = __asan_get_current_fake_stack(); @@ -23,7 +27,7 @@ void *Thread(void *unused) { assert(real_stack); assert((char*)beg <= (char*)&var[0]); assert((char*)end > (char*)&var[0]); - for (int i = -32; i < 15; i++) { + for (int i = -kLeftRedzoneSize; i < 15; i++) { void *beg1, *end1; char *ptr = &var[0] + i; void *real_stack1 = -- cgit v1.2.3