[compiler-rt] [WIP][ASan][test] Enable ASan tests on SPARC (PR #107405)

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 04:37:41 PDT 2024


https://github.com/rorth updated https://github.com/llvm/llvm-project/pull/107405

>From c2483aec5f96940f279f8cef2f4fddd6b20ddd04 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Thu, 5 Sep 2024 15:58:32 +0200
Subject: [PATCH 1/2] [ASan][test] Enable ASan tests on SPARC

With PR #107223 and PR #107403, ASan testing can be enabled on SPARC.  This
patch does so, 32-bit only on Solaris (there is no 64-bit support even in
GCC), and both 32 and 64-bit on Linux (although GCC only support 32-bit
here).

Apart from the obvious CMake changes, this patch includes a couple of
testcase adjustments necessary for SPARC:
- In `asan_oob_test.cpp`, the `OOB_int` subtest needs to be disabled: it
  performs unaligned accesses that cannot work on a strict-alignment target
  like SPARC.
- `asan_test.cpp` needs to disable subtests that depend on support for
  `__builtin_setjmp` and `__builtin_longjmp`.
- `zero_page_pc.cpp` reports `0x5` as the faulting address on access to
  `0x4`.  I don't really know why, but it's consistent between Solaris and
  Linux.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.

Solaris results are not too bad (36 `FAIL`s) while the Linux ones are quite
bad, in particular because quite a number of tests just hang.

For those reasons, I'm just posting the patch for reference in case someone
else wants to try this on Linux.
---
 compiler-rt/lib/asan/tests/CMakeLists.txt        | 2 +-
 compiler-rt/lib/asan/tests/asan_oob_test.cpp     | 9 ++++++++-
 compiler-rt/lib/asan/tests/asan_test.cpp         | 2 +-
 compiler-rt/test/asan/CMakeLists.txt             | 2 +-
 compiler-rt/test/asan/TestCases/zero_page_pc.cpp | 2 +-
 compiler-rt/test/sanitizer_common/CMakeLists.txt | 4 +---
 compiler-rt/test/ubsan/CMakeLists.txt            | 6 +++---
 7 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt
index b489bb99aeff3a..f103243e2549df 100644
--- a/compiler-rt/lib/asan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/asan/tests/CMakeLists.txt
@@ -243,8 +243,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
   if(APPLE)
     darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
   endif()
-  list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
   if(OS_NAME MATCHES "SunOS")
+    list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
     list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
   endif()
 
diff --git a/compiler-rt/lib/asan/tests/asan_oob_test.cpp b/compiler-rt/lib/asan/tests/asan_oob_test.cpp
index 56f573c1fc4820..ce4c90c23e84b6 100644
--- a/compiler-rt/lib/asan/tests/asan_oob_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_oob_test.cpp
@@ -11,6 +11,13 @@
 //===----------------------------------------------------------------------===//
 #include "asan_test_utils.h"
 
+#ifdef __sparc__
+// Tests using unaligned accesses cannot work on strict-alignment targets.
+#define SKIP_ON_STRICT_ALIGNMENT(x) DISABLED_##x
+#else
+#define SKIP_ON_STRICT_ALIGNMENT(x) x
+#endif
+
 NOINLINE void asan_write_sized_aligned(uint8_t *p, size_t size) {
   EXPECT_EQ(0U, ((uintptr_t)p % size));
   if      (size == 1) asan_write((uint8_t*)p);
@@ -79,7 +86,7 @@ TEST(AddressSanitizer, OOB_char) {
   OOBTest<U1>();
 }
 
-TEST(AddressSanitizer, OOB_int) {
+TEST(AddressSanitizer, SKIP_ON_STRICT_ALIGNMENT(OOB_int)) {
   OOBTest<U4>();
 }
 
diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp
index 827c2ae3a9cdc8..09d71569f89bba 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_test.cpp
@@ -631,7 +631,7 @@ NOINLINE void SigLongJmpFunc1(sigjmp_buf buf) {
 
 #if !defined(__ANDROID__) && !defined(__arm__) && !defined(__aarch64__) && \
     !defined(__mips__) && !defined(__mips64) && !defined(__s390__) &&      \
-    !defined(__riscv) && !defined(__loongarch__)
+    !defined(__riscv) && !defined(__loongarch__) && !defined(__sparc__)
 NOINLINE void BuiltinLongJmpFunc1(jmp_buf buf) {
   // create three red zones for these two stack objects.
   int a;
diff --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt
index fb9e81bbe8082d..423491e54a37a3 100644
--- a/compiler-rt/test/asan/CMakeLists.txt
+++ b/compiler-rt/test/asan/CMakeLists.txt
@@ -36,8 +36,8 @@ set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
 if(APPLE)
   darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
 endif()
-list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
 if(OS_NAME MATCHES "SunOS")
+  list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
   list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
 endif()
 
diff --git a/compiler-rt/test/asan/TestCases/zero_page_pc.cpp b/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
index 9a395ecdf37c82..a7d00ce9b69886 100644
--- a/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
+++ b/compiler-rt/test/asan/TestCases/zero_page_pc.cpp
@@ -19,6 +19,6 @@ int main() {
   // the compiler is free to choose the order. As a result, the address is
   // either 0x4, 0xc or 0x14. The pc is still in main() because it has not
   // actually made the call when the faulting access occurs.
-  // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[4c]}}
+  // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[45c]}}
   return 0;
 }
diff --git a/compiler-rt/test/sanitizer_common/CMakeLists.txt b/compiler-rt/test/sanitizer_common/CMakeLists.txt
index fa06b82acebd94..cad94df136a73c 100644
--- a/compiler-rt/test/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/test/sanitizer_common/CMakeLists.txt
@@ -58,10 +58,8 @@ foreach(tool ${SUPPORTED_TOOLS})
   if(APPLE)
     darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
   endif()
-  if(${tool} STREQUAL "asan")
-    list(REMOVE_ITEM TEST_ARCH sparc sparcv9)
-  endif()
   if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan")
+    list(REMOVE_ITEM TEST_ARCH sparcv9)
     list(REMOVE_ITEM TEST_ARCH x86_64)
   endif()
 
diff --git a/compiler-rt/test/ubsan/CMakeLists.txt b/compiler-rt/test/ubsan/CMakeLists.txt
index d95f9ad649ebf8..4fda2e9ec27af1 100644
--- a/compiler-rt/test/ubsan/CMakeLists.txt
+++ b/compiler-rt/test/ubsan/CMakeLists.txt
@@ -51,10 +51,10 @@ foreach(arch ${UBSAN_TEST_ARCH})
   if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
     # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
     # Disable ubsan with AddressSanitizer tests for Windows 64-bit,
-    # 64-bit Solaris/x86, and SPARC.
+    # 64-bit Solaris/SPARC and Solaris/x86.
     if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
-       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
-       (NOT ${arch} MATCHES sparc))
+       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES sparcv9)) AND
+       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)))
       add_ubsan_testsuites("AddressSanitizer" asan ${arch})
     endif()
   endif()

>From 7b8142d20ed27dbd6d4d6771eaf0a0b5cb18ebed Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Fri, 13 Sep 2024 13:37:10 +0200
Subject: [PATCH 2/2] Actual Linux/sparc64 testing found that hundreds of
 `sparcv9` test `FAIL`. In hindsight this is no wonder: while
 `compiler-rt/lib/asan/asan_mapping_sparc64.h` has support for the
 Linux/sparc64 VA hole, ``` commit 9df0754b8dbeeb597a22bb0418eb0ee04ce88b56
 Author: Vitaly Buka <vitalybuka at google.com> Date:   Tue Mar 12 21:02:24 2019
 +0000

    AddressSanitizer: 64-bit SPARC/Linux port
```
there's nothing corresponding in `clang`.  Also, `gcc` disables 64-bit ASan
on Linux/sparc64, too.

So this patch disables `sparcv9` ASan testing in general.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`
---
 compiler-rt/lib/asan/tests/CMakeLists.txt        | 2 +-
 compiler-rt/test/asan/CMakeLists.txt             | 2 +-
 compiler-rt/test/sanitizer_common/CMakeLists.txt | 4 +++-
 compiler-rt/test/ubsan/CMakeLists.txt            | 6 +++---
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt
index f103243e2549df..491ed53d5671f2 100644
--- a/compiler-rt/lib/asan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/asan/tests/CMakeLists.txt
@@ -243,8 +243,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
   if(APPLE)
     darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
   endif()
+  list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
   if(OS_NAME MATCHES "SunOS")
-    list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
     list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
   endif()
 
diff --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt
index 423491e54a37a3..414a6cc9496edb 100644
--- a/compiler-rt/test/asan/CMakeLists.txt
+++ b/compiler-rt/test/asan/CMakeLists.txt
@@ -36,8 +36,8 @@ set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
 if(APPLE)
   darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
 endif()
+list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
 if(OS_NAME MATCHES "SunOS")
-  list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
   list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
 endif()
 
diff --git a/compiler-rt/test/sanitizer_common/CMakeLists.txt b/compiler-rt/test/sanitizer_common/CMakeLists.txt
index cad94df136a73c..615666676f57ac 100644
--- a/compiler-rt/test/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/test/sanitizer_common/CMakeLists.txt
@@ -58,8 +58,10 @@ foreach(tool ${SUPPORTED_TOOLS})
   if(APPLE)
     darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
   endif()
-  if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan")
+  if(${tool} STREQUAL "asan")
     list(REMOVE_ITEM TEST_ARCH sparcv9)
+  endif()
+  if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan")
     list(REMOVE_ITEM TEST_ARCH x86_64)
   endif()
 
diff --git a/compiler-rt/test/ubsan/CMakeLists.txt b/compiler-rt/test/ubsan/CMakeLists.txt
index 4fda2e9ec27af1..9b7fbe3c8f9260 100644
--- a/compiler-rt/test/ubsan/CMakeLists.txt
+++ b/compiler-rt/test/ubsan/CMakeLists.txt
@@ -51,10 +51,10 @@ foreach(arch ${UBSAN_TEST_ARCH})
   if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
     # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
     # Disable ubsan with AddressSanitizer tests for Windows 64-bit,
-    # 64-bit Solaris/SPARC and Solaris/x86.
+    # 64-bit Solaris/x86 and 64-bit SPARC.
     if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
-       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES sparcv9)) AND
-       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)))
+       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
+       (NOT ${arch} MATCHES sparcv9))
       add_ubsan_testsuites("AddressSanitizer" asan ${arch})
     endif()
   endif()



More information about the llvm-commits mailing list