[asan] Add more dynamic CRT mode tests

Only tests using %clang_cl_asan were using the dynamic CRT before this.
The unit tests and lit tests using %clangxx_asan were using the static
CRT. Many cross-platform tests fail with the dynamic CRT, so I had to
add win32-(static|dynamic)-asan lit features.

Also deletes some redundant tests in TestCases/Windows that started
failing with this switch.

llvm-svn: 285821
This commit is contained in:
Reid Kleckner
2016-11-02 15:39:08 +00:00
parent 2bc03590f6
commit 3501fdcb30
14 changed files with 78 additions and 47 deletions

View File

@@ -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()

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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>

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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"

View File

@@ -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>

View File

@@ -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>

View File

@@ -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;
}

View File

@@ -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";

View File

@@ -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.

View File

@@ -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']