Skip to content

Commit c2483ae

Browse files
committed
[ASan][test] Enable ASan tests on SPARC
With PR llvm#107223 and PR llvm#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.
1 parent 0797c18 commit c2483ae

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

compiler-rt/lib/asan/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
243243
if(APPLE)
244244
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
245245
endif()
246-
list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
247246
if(OS_NAME MATCHES "SunOS")
247+
list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
248248
list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
249249
endif()
250250

compiler-rt/lib/asan/tests/asan_oob_test.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
//===----------------------------------------------------------------------===//
1212
#include "asan_test_utils.h"
1313

14+
#ifdef __sparc__
15+
// Tests using unaligned accesses cannot work on strict-alignment targets.
16+
#define SKIP_ON_STRICT_ALIGNMENT(x) DISABLED_##x
17+
#else
18+
#define SKIP_ON_STRICT_ALIGNMENT(x) x
19+
#endif
20+
1421
NOINLINE void asan_write_sized_aligned(uint8_t *p, size_t size) {
1522
EXPECT_EQ(0U, ((uintptr_t)p % size));
1623
if (size == 1) asan_write((uint8_t*)p);
@@ -79,7 +86,7 @@ TEST(AddressSanitizer, OOB_char) {
7986
OOBTest<U1>();
8087
}
8188

82-
TEST(AddressSanitizer, OOB_int) {
89+
TEST(AddressSanitizer, SKIP_ON_STRICT_ALIGNMENT(OOB_int)) {
8390
OOBTest<U4>();
8491
}
8592

compiler-rt/lib/asan/tests/asan_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ NOINLINE void SigLongJmpFunc1(sigjmp_buf buf) {
631631

632632
#if !defined(__ANDROID__) && !defined(__arm__) && !defined(__aarch64__) && \
633633
!defined(__mips__) && !defined(__mips64) && !defined(__s390__) && \
634-
!defined(__riscv) && !defined(__loongarch__)
634+
!defined(__riscv) && !defined(__loongarch__) && !defined(__sparc__)
635635
NOINLINE void BuiltinLongJmpFunc1(jmp_buf buf) {
636636
// create three red zones for these two stack objects.
637637
int a;

compiler-rt/test/asan/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
3636
if(APPLE)
3737
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
3838
endif()
39-
list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
4039
if(OS_NAME MATCHES "SunOS")
40+
list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)
4141
list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
4242
endif()
4343

compiler-rt/test/asan/TestCases/zero_page_pc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ int main() {
1919
// the compiler is free to choose the order. As a result, the address is
2020
// either 0x4, 0xc or 0x14. The pc is still in main() because it has not
2121
// actually made the call when the faulting access occurs.
22-
// CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[4c]}}
22+
// CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[45c]}}
2323
return 0;
2424
}

compiler-rt/test/sanitizer_common/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ foreach(tool ${SUPPORTED_TOOLS})
5858
if(APPLE)
5959
darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
6060
endif()
61-
if(${tool} STREQUAL "asan")
62-
list(REMOVE_ITEM TEST_ARCH sparc sparcv9)
63-
endif()
6461
if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan")
62+
list(REMOVE_ITEM TEST_ARCH sparcv9)
6563
list(REMOVE_ITEM TEST_ARCH x86_64)
6664
endif()
6765

compiler-rt/test/ubsan/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ foreach(arch ${UBSAN_TEST_ARCH})
5151
if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
5252
# TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
5353
# Disable ubsan with AddressSanitizer tests for Windows 64-bit,
54-
# 64-bit Solaris/x86, and SPARC.
54+
# 64-bit Solaris/SPARC and Solaris/x86.
5555
if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
56-
(NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
57-
(NOT ${arch} MATCHES sparc))
56+
(NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES sparcv9)) AND
57+
(NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)))
5858
add_ubsan_testsuites("AddressSanitizer" asan ${arch})
5959
endif()
6060
endif()

0 commit comments

Comments
 (0)