From 5888a47914f44ffaf102fcb7afd3500706fe753f Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Tue, 28 Mar 2023 17:03:10 +0800 Subject: [PATCH] [asan][test] Fix tests or mark XFAIL for MinGW target After this change, `check-asan-dynamic` should pass on x86_64 MinGW target, using the llvm-mingw toolchain. The following is a list of issues fixed: * `asan_str_test.cpp`: Exclude unintercepted functions on MinGW. * `asan_test.cpp`: Work around regex limitation of gtest on Windows, which only affects MinGW target because `long double` has different size to `double`. * `TestCases/Windows/report_after_syminitialize.cpp`: Added build command specifically for MinGW. * Other tests: Mark XFAIL for various reasons. Some of them need further investigation. Differential Revision: https://reviews.llvm.org/D147059 --- compiler-rt/lib/asan/tests/asan_str_test.cpp | 16 ++++++++++++---- compiler-rt/lib/asan/tests/asan_test.cpp | 8 ++++++++ .../lib/sanitizer_common/tests/sanitizer_test_utils.h | 4 ++-- .../test/asan/TestCases/Windows/coverage-basic.cpp | 4 ++++ .../TestCases/Windows/report_after_syminitialize.cpp | 12 +++++++++++- compiler-rt/test/asan/TestCases/atexit_stats.cpp | 3 +++ compiler-rt/test/asan/TestCases/atoll_strict.c | 2 +- compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp | 4 ++++ compiler-rt/test/asan/TestCases/global-location.cpp | 3 +++ compiler-rt/test/asan/TestCases/heavy_uar_test.cpp | 4 ++++ compiler-rt/test/asan/TestCases/init-order-atexit.cpp | 3 +++ compiler-rt/test/asan/TestCases/printf-2.c | 2 +- compiler-rt/test/asan/TestCases/printf-3.c | 2 +- compiler-rt/test/asan/TestCases/printf-5.c | 2 +- compiler-rt/test/asan/TestCases/strcasestr-1.c | 2 +- compiler-rt/test/asan/TestCases/strcasestr-2.c | 2 +- compiler-rt/test/asan/TestCases/strcasestr_strict.c | 2 +- compiler-rt/test/asan/TestCases/strncasecmp_strict.c | 2 +- compiler-rt/test/asan/TestCases/strtoll_strict.c | 2 +- compiler-rt/test/asan/TestCases/time_interceptor.cpp | 4 ++-- 20 files changed, 65 insertions(+), 18 deletions(-) diff --git a/compiler-rt/lib/asan/tests/asan_str_test.cpp b/compiler-rt/lib/asan/tests/asan_str_test.cpp index 1bf6c35..8b1c1dc 100644 --- a/compiler-rt/lib/asan/tests/asan_str_test.cpp +++ b/compiler-rt/lib/asan/tests/asan_str_test.cpp @@ -110,8 +110,16 @@ TEST(AddressSanitizer, WcsLenTest) { } #endif +// This test fails on MinGW-w64 because it still ships a static copy of strnlen +// despite it being available from UCRT. +#if defined(__MINGW32__) +# define MAYBE_StrNLenOOBTest DISABLED_StrNLenOOBTest +#else +# define MAYBE_StrNLenOOBTest StrNLenOOBTest +#endif + #if SANITIZER_TEST_HAS_STRNLEN -TEST(AddressSanitizer, StrNLenOOBTest) { +TEST(AddressSanitizer, MAYBE_StrNLenOOBTest) { size_t size = Ident(123); char *str = MallocAndMemsetString(size); // Normal strnlen calls. @@ -132,10 +140,10 @@ TEST(AddressSanitizer, StrNLenOOBTest) { // 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 +#if (defined(_MSC_VER) && defined(_DLL)) || defined(__MINGW32__) +# define MAYBE_StrDupOOBTest DISABLED_StrDupOOBTest #else -#define MAYBE_StrDupOOBTest StrDupOOBTest +# define MAYBE_StrDupOOBTest StrDupOOBTest #endif TEST(AddressSanitizer, MAYBE_StrDupOOBTest) { diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp index 40b335d..827c2ae 100644 --- a/compiler-rt/lib/asan/tests/asan_test.cpp +++ b/compiler-rt/lib/asan/tests/asan_test.cpp @@ -203,8 +203,16 @@ TEST(AddressSanitizer, UAF_char) { TEST(AddressSanitizer, UAF_long_double) { if (sizeof(long double) == sizeof(double)) return; long double *p = Ident(new long double[10]); +#if defined(_WIN32) + // https://google.github.io/googletest/advanced.html#regular-expression-syntax + // GoogleTest's regular expression engine on Windows does not support `[]` + // brackets. + EXPECT_DEATH(Ident(p)[12] = 0, "WRITE of size 10"); + EXPECT_DEATH(Ident(p)[0] = Ident(p)[12], "READ of size 10"); +#else EXPECT_DEATH(Ident(p)[12] = 0, "WRITE of size 1[026]"); EXPECT_DEATH(Ident(p)[0] = Ident(p)[12], "READ of size 1[026]"); +#endif delete [] Ident(p); } diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h b/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h index 016ce9e..5fd94a0 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h @@ -127,8 +127,8 @@ static inline uint32_t my_rand() { # define SANITIZER_TEST_HAS_PRINTF_L 0 #endif -#if !defined(_MSC_VER) -# define SANITIZER_TEST_HAS_STRNDUP 1 +#if !defined(_WIN32) +# define SANITIZER_TEST_HAS_STRNDUP 1 #else # define SANITIZER_TEST_HAS_STRNDUP 0 #endif diff --git a/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp b/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp index 163247e..96262ca 100644 --- a/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp @@ -4,6 +4,10 @@ // RUN: %env_asan_opts=coverage=1 %run ./test.exe // // RUN: %sancov print *.sancov | FileCheck %s + +// FIXME: Investigate failure on MinGW. +// XFAIL: target={{.*-windows-gnu}} + #include void foo() { fputs("FOO", stderr); } diff --git a/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp b/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp index 8169663..45bb6f3 100644 --- a/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp @@ -1,4 +1,14 @@ -// RUN: %clangxx_asan -O0 %s -o %t +// This test works on both MSVC and MinGW targets, but they require different +// build commands. By default we use DWARF debug info on MinGW and dbghelp does +// not support it, so we need to specify extra flags to get the compiler to +// generate PDB debug info. + +// The first build command is intended for MSVC target, which fails on MinGW. +// The second build command contains the flags required to get PDB debug info +// on a MinGW build, which fails on MSVC. + +// RUN: %clangxx_asan -O0 %s -o %t \ +// RUN: || %clangxx_asan -gcodeview -gcolumn-info -Wl,--pdb= -O0 %s -o %t -ldbghelp // RUN: %env_asan_opts=external_symbolizer_path=non-existent\\\\asdf not %run %t 2>&1 | FileCheck %s #include diff --git a/compiler-rt/test/asan/TestCases/atexit_stats.cpp b/compiler-rt/test/asan/TestCases/atexit_stats.cpp index c8d97da..1774385 100644 --- a/compiler-rt/test/asan/TestCases/atexit_stats.cpp +++ b/compiler-rt/test/asan/TestCases/atexit_stats.cpp @@ -6,6 +6,9 @@ // https://code.google.com/p/address-sanitizer/issues/detail?id=263 // UNSUPPORTED: android +// FIXME: Investigate failure on MinGW. +// XFAIL: target={{.*-windows-gnu}} + #include #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) #include diff --git a/compiler-rt/test/asan/TestCases/atoll_strict.c b/compiler-rt/test/asan/TestCases/atoll_strict.c index f0cf0c6..431ec6b 100644 --- a/compiler-rt/test/asan/TestCases/atoll_strict.c +++ b/compiler-rt/test/asan/TestCases/atoll_strict.c @@ -11,7 +11,7 @@ // RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3 // FIXME: Needs Windows interceptor. -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #include #include diff --git a/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp b/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp index 46bb6a2..721eecc 100644 --- a/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp +++ b/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp @@ -2,6 +2,10 @@ // Test the frexpl() interceptor. +// FIXME: MinGW-w64 implements `frexpl()` as a static import, so the dynamic +// interceptor seems to not work. +// XFAIL: target={{.*-windows-gnu}} + #include #include #include diff --git a/compiler-rt/test/asan/TestCases/global-location.cpp b/compiler-rt/test/asan/TestCases/global-location.cpp index b0e996a..7aa6941 100644 --- a/compiler-rt/test/asan/TestCases/global-location.cpp +++ b/compiler-rt/test/asan/TestCases/global-location.cpp @@ -7,6 +7,9 @@ // COFF doesn't support debuginfo for globals. For the non-debuginfo tests, see global-location-nodebug.cpp. // XFAIL: target={{.*windows-msvc.*}} +// FIXME: Investigate failure on MinGW +// XFAIL: target={{.*-windows-gnu}} + // atos doesn't show source line numbers for global variables. // UNSUPPORTED: darwin diff --git a/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp b/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp index f1bd0f0..718f9b9 100644 --- a/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp +++ b/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp @@ -4,6 +4,10 @@ // RUN: %clangxx_asan -O2 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s // XFAIL: target={{.*windows-msvc.*}} +// FIXME: Investigate failure on MinGW. MinGW ASAN produces a different report: +// stack-overflow on address +// XFAIL: target={{.*-windows-gnu}} + // FIXME: Fix this test under GCC. // REQUIRES: Clang diff --git a/compiler-rt/test/asan/TestCases/init-order-atexit.cpp b/compiler-rt/test/asan/TestCases/init-order-atexit.cpp index 57bddd4..6877076 100644 --- a/compiler-rt/test/asan/TestCases/init-order-atexit.cpp +++ b/compiler-rt/test/asan/TestCases/init-order-atexit.cpp @@ -7,6 +7,9 @@ // RUN: %clangxx_asan -O0 %s %p/Helpers/init-order-atexit-extra.cpp -o %t // RUN: %env_asan_opts=strict_init_order=true not %run %t 2>&1 | FileCheck %s +// FIXME: Investigate failure on MinGW +// XFAIL: target={{.*-windows-gnu}} + #include #include diff --git a/compiler-rt/test/asan/TestCases/printf-2.c b/compiler-rt/test/asan/TestCases/printf-2.c index 7fcf4305..3ea263d 100644 --- a/compiler-rt/test/asan/TestCases/printf-2.c +++ b/compiler-rt/test/asan/TestCases/printf-2.c @@ -6,7 +6,7 @@ // RUN: %env_asan_opts=replace_str=0:intercept_strlen=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s // FIXME: printf is not intercepted on Windows yet. -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #include #include diff --git a/compiler-rt/test/asan/TestCases/printf-3.c b/compiler-rt/test/asan/TestCases/printf-3.c index 805210c..a8ce02e 100644 --- a/compiler-rt/test/asan/TestCases/printf-3.c +++ b/compiler-rt/test/asan/TestCases/printf-3.c @@ -4,7 +4,7 @@ // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s // FIXME: printf is not intercepted on Windows yet. -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} // New Bionic rejects %n // https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336 diff --git a/compiler-rt/test/asan/TestCases/printf-5.c b/compiler-rt/test/asan/TestCases/printf-5.c index 564de39..eef5223 100644 --- a/compiler-rt/test/asan/TestCases/printf-5.c +++ b/compiler-rt/test/asan/TestCases/printf-5.c @@ -5,7 +5,7 @@ // RUN: %env_asan_opts=replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s // FIXME: printf is not intercepted on Windows yet. -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #include #include diff --git a/compiler-rt/test/asan/TestCases/strcasestr-1.c b/compiler-rt/test/asan/TestCases/strcasestr-1.c index 8be4b75..9fa4a2b 100644 --- a/compiler-rt/test/asan/TestCases/strcasestr-1.c +++ b/compiler-rt/test/asan/TestCases/strcasestr-1.c @@ -6,7 +6,7 @@ // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1 // There's no interceptor for strcasestr on Windows -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #define _GNU_SOURCE #include diff --git a/compiler-rt/test/asan/TestCases/strcasestr-2.c b/compiler-rt/test/asan/TestCases/strcasestr-2.c index eabe402..920d11e 100644 --- a/compiler-rt/test/asan/TestCases/strcasestr-2.c +++ b/compiler-rt/test/asan/TestCases/strcasestr-2.c @@ -6,7 +6,7 @@ // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false:intercept_strlen=false %run %t 2>&1 // There's no interceptor for strcasestr on Windows -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #define _GNU_SOURCE #include diff --git a/compiler-rt/test/asan/TestCases/strcasestr_strict.c b/compiler-rt/test/asan/TestCases/strcasestr_strict.c index a6d1087..16efae7 100644 --- a/compiler-rt/test/asan/TestCases/strcasestr_strict.c +++ b/compiler-rt/test/asan/TestCases/strcasestr_strict.c @@ -4,7 +4,7 @@ // RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s // There's no interceptor for strcasestr on Windows -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #define _GNU_SOURCE #include diff --git a/compiler-rt/test/asan/TestCases/strncasecmp_strict.c b/compiler-rt/test/asan/TestCases/strncasecmp_strict.c index 24261be..a0bd338 100644 --- a/compiler-rt/test/asan/TestCases/strncasecmp_strict.c +++ b/compiler-rt/test/asan/TestCases/strncasecmp_strict.c @@ -14,7 +14,7 @@ // RUN: %env_asan_opts=strict_string_checks=false %run %t i 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t i 2>&1 | FileCheck %s -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #include #include diff --git a/compiler-rt/test/asan/TestCases/strtoll_strict.c b/compiler-rt/test/asan/TestCases/strtoll_strict.c index 88e6651..097412e 100644 --- a/compiler-rt/test/asan/TestCases/strtoll_strict.c +++ b/compiler-rt/test/asan/TestCases/strtoll_strict.c @@ -24,7 +24,7 @@ // FIXME: Enable strtoll interceptor. // REQUIRES: shadow-scale-3 -// XFAIL: target={{.*windows-msvc.*}} +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #include #include diff --git a/compiler-rt/test/asan/TestCases/time_interceptor.cpp b/compiler-rt/test/asan/TestCases/time_interceptor.cpp index 47acdd5..0c5e3fe 100644 --- a/compiler-rt/test/asan/TestCases/time_interceptor.cpp +++ b/compiler-rt/test/asan/TestCases/time_interceptor.cpp @@ -2,8 +2,8 @@ // Test the time() interceptor. -// There's no interceptor for time() on Windows yet. -// XFAIL: target={{.*windows-msvc.*}} +// FIXME: There's no interceptor for time() on Windows yet. +// XFAIL: target={{.*windows-(msvc.*|gnu)}} #include #include -- 2.7.4