diff options
-rw-r--r-- | lib/asan/tests/CMakeLists.txt | 19 | ||||
-rw-r--r-- | lib/asan/tests/asan_str_test.cc | 10 | ||||
-rw-r--r-- | test/asan/TestCases/Windows/default_options.cc | 18 | ||||
-rw-r--r-- | test/asan/TestCases/Windows/free_hook_realloc.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/Windows/on_error_callback.cc | 20 | ||||
-rw-r--r-- | test/asan/TestCases/Windows/report_after_syminitialize.cc | 2 | ||||
-rw-r--r-- | test/asan/TestCases/debug_report.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/default_options.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/interception_failure_test.cc | 8 | ||||
-rw-r--r-- | test/asan/TestCases/on_error_callback.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/speculative_load.cc | 4 | ||||
-rw-r--r-- | test/asan/TestCases/strdup_oob_test.cc | 4 | ||||
-rw-r--r-- | test/asan/TestCases/use-after-scope-loop-bug.cc | 2 | ||||
-rw-r--r-- | test/asan/lit.cfg | 26 |
14 files changed, 78 insertions, 47 deletions
diff --git a/lib/asan/tests/CMakeLists.txt b/lib/asan/tests/CMakeLists.txt index 94febc0c7..3e56763a8 100644 --- a/lib/asan/tests/CMakeLists.txt +++ b/lib/asan/tests/CMakeLists.txt @@ -222,6 +222,23 @@ macro(add_asan_tests_for_arch_and_kind arch kind) ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -ObjC ${ARGN}) endif() + if (MSVC) + # With the MSVC CRT, the choice between static and dynamic CRT is made at + # compile time with a macro. Simulate the effect of passing /MD to clang-cl. + set(ASAN_INST_DYNAMIC_TEST_OBJECTS) + foreach(src ${ASAN_INST_TEST_SOURCES}) + asan_compile(ASAN_INST_DYNAMIC_TEST_OBJECTS ${src} ${arch} ${kind} + ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -D_MT -D_DLL ${ARGN}) + endforeach() + # Clang links the static CRT by default. Override that to use the dynamic + # CRT. + set(ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS + ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS} + -Wl,-nodefaultlib:libcmt,-defaultlib:msvcrt,-defaultlib:oldnames) + else() + set(ASAN_INST_DYNAMIC_TEST_OBJECTS ${ASAN_INST_TEST_OBJECTS}) + endif() + # Create the 'default' folder where ASAN tests are produced. if(CMAKE_CONFIGURATION_TYPES) foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) @@ -247,7 +264,7 @@ macro(add_asan_tests_for_arch_and_kind arch kind) add_asan_test(AsanDynamicUnitTests "Asan-${arch}${kind}-Dynamic-Test" ${arch} ${kind} SUBDIR "dynamic" - OBJECTS ${ASAN_INST_TEST_OBJECTS} + OBJECTS ${ASAN_INST_DYNAMIC_TEST_OBJECTS} LINKFLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS}) endif() diff --git a/lib/asan/tests/asan_str_test.cc b/lib/asan/tests/asan_str_test.cc index 0b86702c4..c790088f8 100644 --- a/lib/asan/tests/asan_str_test.cc +++ b/lib/asan/tests/asan_str_test.cc @@ -127,7 +127,15 @@ TEST(AddressSanitizer, StrNLenOOBTest) { } #endif // SANITIZER_TEST_HAS_STRNLEN -TEST(AddressSanitizer, StrDupOOBTest) { +// This test fails with the WinASan dynamic runtime because we fail to intercept +// strdup. +#if defined(_MSC_VER) && defined(_DLL) +#define MAYBE_StrDupOOBTest DISABLED_StrDupOOBTest +#else +#define MAYBE_StrDupOOBTest StrDupOOBTest +#endif + +TEST(AddressSanitizer, MAYBE_StrDupOOBTest) { size_t size = Ident(42); char *str = MallocAndMemsetString(size); char *new_str; diff --git a/test/asan/TestCases/Windows/default_options.cc b/test/asan/TestCases/Windows/default_options.cc deleted file mode 100644 index 6e0a28f33..000000000 --- a/test/asan/TestCases/Windows/default_options.cc +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %clangxx_asan -O2 %s -o %t -// RUN: %run %t 2>&1 | FileCheck %s - -// FIXME: merge this with the common default_options test when we can run common -// tests on Windows. - -const char *kAsanDefaultOptions="verbosity=1 help=1"; - -extern "C" -__attribute__((no_sanitize_address)) -const char *__asan_default_options() { - // CHECK: Available flags for AddressSanitizer: - return kAsanDefaultOptions; -} - -int main() { - return 0; -} diff --git a/test/asan/TestCases/Windows/free_hook_realloc.cc b/test/asan/TestCases/Windows/free_hook_realloc.cc index 297218bf8..11e8c9975 100644 --- a/test/asan/TestCases/Windows/free_hook_realloc.cc +++ b/test/asan/TestCases/Windows/free_hook_realloc.cc @@ -5,6 +5,9 @@ // FIXME: merge this with the common free_hook_realloc test when we can run // common tests on Windows. +// FIXME: Doesn't work with DLLs +// XFAIL: win32-dynamic-asan + #include <stdlib.h> #include <io.h> #include <sanitizer/allocator_interface.h> diff --git a/test/asan/TestCases/Windows/on_error_callback.cc b/test/asan/TestCases/Windows/on_error_callback.cc deleted file mode 100644 index 9e690a342..000000000 --- a/test/asan/TestCases/Windows/on_error_callback.cc +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s - -// FIXME: merge this with the common on_error_callback test when we can run -// common tests on Windows. - -#include <stdio.h> -#include <stdlib.h> - -extern "C" -void __asan_on_error() { - fprintf(stderr, "__asan_on_error called"); - fflush(0); -} - -int main() { - char *x = (char*)malloc(10 * sizeof(char)); - free(x); - return x[5]; - // CHECK: __asan_on_error called -} diff --git a/test/asan/TestCases/Windows/report_after_syminitialize.cc b/test/asan/TestCases/Windows/report_after_syminitialize.cc index c5ac6023c..eec502974 100644 --- a/test/asan/TestCases/Windows/report_after_syminitialize.cc +++ b/test/asan/TestCases/Windows/report_after_syminitialize.cc @@ -4,6 +4,8 @@ #include <windows.h> #include <dbghelp.h> +#pragma comment(lib, "dbghelp") + int main() { // Make sure the RTL recovers from "no options enabled" dbghelp setup. SymSetOptions(0); diff --git a/test/asan/TestCases/debug_report.cc b/test/asan/TestCases/debug_report.cc index 124ae5d76..34bc06eba 100644 --- a/test/asan/TestCases/debug_report.cc +++ b/test/asan/TestCases/debug_report.cc @@ -6,6 +6,9 @@ #include <stdio.h> #include <stdlib.h> +// FIXME: Doesn't work with DLLs +// XFAIL: win32-dynamic-asan + int main() { // Disable stderr buffering. Needed on Windows. setvbuf(stderr, NULL, _IONBF, 0); diff --git a/test/asan/TestCases/default_options.cc b/test/asan/TestCases/default_options.cc index a3aa6637e..27af76d7f 100644 --- a/test/asan/TestCases/default_options.cc +++ b/test/asan/TestCases/default_options.cc @@ -1,6 +1,9 @@ // RUN: %clangxx_asan -O2 %s -o %t // RUN: %run %t 2>&1 | FileCheck %s +// FIXME: Doesn't work with DLLs +// XFAIL: win32-dynamic-asan + const char *kAsanDefaultOptions="verbosity=1 help=1"; extern "C" diff --git a/test/asan/TestCases/interception_failure_test.cc b/test/asan/TestCases/interception_failure_test.cc index 63d874667..b20c9f1fe 100644 --- a/test/asan/TestCases/interception_failure_test.cc +++ b/test/asan/TestCases/interception_failure_test.cc @@ -5,8 +5,12 @@ // RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -O2 %s -o %t && %run %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s -// On Windows, defining strtoll results in linker errors. -// XFAIL: freebsd,win32 +// XFAIL: freebsd + +// On Windows, defining strtoll in a static build results in linker errors, but +// it works with the dynamic runtime. +// XFAIL: win32-static-asan + #include <stdlib.h> #include <stdio.h> diff --git a/test/asan/TestCases/on_error_callback.cc b/test/asan/TestCases/on_error_callback.cc index 88a4d2dca..f37d1eb7f 100644 --- a/test/asan/TestCases/on_error_callback.cc +++ b/test/asan/TestCases/on_error_callback.cc @@ -1,5 +1,8 @@ // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// FIXME: Doesn't work with DLLs +// XFAIL: win32-dynamic-asan + #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/speculative_load.cc b/test/asan/TestCases/speculative_load.cc index 2409d7a5e..fdf70eb39 100644 --- a/test/asan/TestCases/speculative_load.cc +++ b/test/asan/TestCases/speculative_load.cc @@ -27,6 +27,10 @@ struct S { __asan_poison_memory_region(_data._s._ch, 23); } + ~S() { + __asan_unpoison_memory_region(_data._s._ch, 23); + } + bool is_long() const { return _data._s._size & 1; } diff --git a/test/asan/TestCases/strdup_oob_test.cc b/test/asan/TestCases/strdup_oob_test.cc index 492555ad1..60c5ef12a 100644 --- a/test/asan/TestCases/strdup_oob_test.cc +++ b/test/asan/TestCases/strdup_oob_test.cc @@ -9,6 +9,10 @@ // Unwind problem on arm: "main" is missing from the allocation stack trace. // UNSUPPORTED: armv7l-unknown-linux-gnueabihf +// FIXME: We fail to intercept strdup with the dynamic WinASan RTL, so it's not +// in the stack trace. +// XFAIL: win32-dynamic-asan + #include <string.h> char kString[] = "foo"; diff --git a/test/asan/TestCases/use-after-scope-loop-bug.cc b/test/asan/TestCases/use-after-scope-loop-bug.cc index 4f483f204..d4b12eca9 100644 --- a/test/asan/TestCases/use-after-scope-loop-bug.cc +++ b/test/asan/TestCases/use-after-scope-loop-bug.cc @@ -1,7 +1,7 @@ // RUN: %clangxx_asan -O1 -fsanitize-address-use-after-scope %s -o %t && \ // RUN: not %run %t 2>&1 | FileCheck %s -int *p; +volatile int *p; int main() { // Variable goes in and out of scope. diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg index 455a58ce3..75032d6b9 100644 --- a/test/asan/lit.cfg +++ b/test/asan/lit.cfg @@ -83,14 +83,26 @@ if config.target_arch == 's390x': clang_asan_static_cflags.append("-mbackchain") clang_asan_static_cxxflags = config.cxx_mode_flags + clang_asan_static_cflags +asan_dynamic_flags = [] if config.asan_dynamic: - clang_asan_cflags = clang_asan_static_cflags + ['-shared-libasan'] - clang_asan_cxxflags = clang_asan_static_cxxflags + ['-shared-libasan'] + asan_dynamic_flags = ["-shared-libasan"] + # On Windows, we need to simulate "clang-cl /MD" on the clang driver side. + if platform.system() == 'Windows': + asan_dynamic_flags += ["-D_MT", "-D_DLL", "-Wl,-nodefaultlib:libcmt,-defaultlib:msvcrt,-defaultlib:oldnames"] config.available_features.add("asan-dynamic-runtime") else: - clang_asan_cflags = clang_asan_static_cflags - clang_asan_cxxflags = clang_asan_static_cxxflags config.available_features.add("asan-static-runtime") +clang_asan_cflags = clang_asan_static_cflags + asan_dynamic_flags +clang_asan_cxxflags = clang_asan_static_cxxflags + asan_dynamic_flags + +# Add win32-(static|dynamic)-asan features to mark tests as passing or failing +# in those modes. lit doesn't support logical feature test combinations. +if platform.system() == 'Windows': + if config.asan_dynamic: + win_runtime_feature = "win32-dynamic-asan" + else: + win_runtime_feature = "win32-static-asan" + config.available_features.add(win_runtime_feature) asan_lit_source_dir = get_required_attr(config, "asan_lit_source_dir") if config.android == "1": @@ -205,6 +217,12 @@ if config.compiler_id == 'GNU': libasan_dir = os.path.join(gcc_dir, "..", "lib" + config.bits) push_dynamic_library_lookup_path(config, libasan_dir) +# Add the RT libdir to PATH directly so that we can successfully run the gtest +# binary to list its tests. +if config.host_os == 'Windows' and config.asan_dynamic: + os.environ['PATH'] = os.path.pathsep.join([config.compiler_rt_libdir, + os.environ.get('PATH', '')]) + # Default test suffixes. config.suffixes = ['.c', '.cc', '.cpp'] |