[compiler-rt] r285821 - [asan] Add more dynamic CRT mode tests

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 2 08:39:09 PDT 2016


Author: rnk
Date: Wed Nov  2 10:39:08 2016
New Revision: 285821

URL: http://llvm.org/viewvc/llvm-project?rev=285821&view=rev
Log:
[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.

Removed:
    compiler-rt/trunk/test/asan/TestCases/Windows/default_options.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/on_error_callback.cc
Modified:
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/asan/tests/asan_str_test.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/free_hook_realloc.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc
    compiler-rt/trunk/test/asan/TestCases/debug_report.cc
    compiler-rt/trunk/test/asan/TestCases/default_options.cc
    compiler-rt/trunk/test/asan/TestCases/interception_failure_test.cc
    compiler-rt/trunk/test/asan/TestCases/on_error_callback.cc
    compiler-rt/trunk/test/asan/TestCases/speculative_load.cc
    compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc
    compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc
    compiler-rt/trunk/test/asan/lit.cfg

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Wed Nov  2 10:39:08 2016
@@ -222,6 +222,23 @@ macro(add_asan_tests_for_arch_and_kind a
                  ${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 a
 
     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()
 

Modified: compiler-rt/trunk/lib/asan/tests/asan_str_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_str_test.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_str_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_str_test.cc Wed Nov  2 10:39:08 2016
@@ -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;

Removed: compiler-rt/trunk/test/asan/TestCases/Windows/default_options.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/default_options.cc?rev=285820&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/default_options.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/default_options.cc (removed)
@@ -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;
-}

Modified: compiler-rt/trunk/test/asan/TestCases/Windows/free_hook_realloc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/free_hook_realloc.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/free_hook_realloc.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/free_hook_realloc.cc Wed Nov  2 10:39:08 2016
@@ -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>

Removed: compiler-rt/trunk/test/asan/TestCases/Windows/on_error_callback.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/on_error_callback.cc?rev=285820&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/on_error_callback.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/on_error_callback.cc (removed)
@@ -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
-}

Modified: compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc Wed Nov  2 10:39:08 2016
@@ -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);

Modified: compiler-rt/trunk/test/asan/TestCases/debug_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/debug_report.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/debug_report.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/debug_report.cc Wed Nov  2 10:39:08 2016
@@ -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);

Modified: compiler-rt/trunk/test/asan/TestCases/default_options.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/default_options.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/default_options.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/default_options.cc Wed Nov  2 10:39:08 2016
@@ -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"

Modified: compiler-rt/trunk/test/asan/TestCases/interception_failure_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/interception_failure_test.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/interception_failure_test.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/interception_failure_test.cc Wed Nov  2 10:39:08 2016
@@ -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>
 

Modified: compiler-rt/trunk/test/asan/TestCases/on_error_callback.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/on_error_callback.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/on_error_callback.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/on_error_callback.cc Wed Nov  2 10:39:08 2016
@@ -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>
 

Modified: compiler-rt/trunk/test/asan/TestCases/speculative_load.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/speculative_load.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/speculative_load.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/speculative_load.cc Wed Nov  2 10:39:08 2016
@@ -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;
   }

Modified: compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc Wed Nov  2 10:39:08 2016
@@ -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";

Modified: compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/use-after-scope-loop-bug.cc Wed Nov  2 10:39:08 2016
@@ -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.

Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=285821&r1=285820&r2=285821&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Wed Nov  2 10:39:08 2016
@@ -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']
 




More information about the llvm-commits mailing list