Skip to content

Commit cf4aa68

Browse files
spacemonkeydeliversEccoTheDolphin
authored andcommitted
[RISCV][ASAN] mark asan as supported for RISCV64 and enable tests
[11/11] patch series to port ASAN for riscv64 These changes allow using ASAN on RISCV64 architecture. The majority of existing tests are passing. With few exceptions (see below). Tests we run on qemu and on "HiFive Unleashed" board. Tests run: ``` Asan-riscv64-inline-Test - pass Asan-riscv64-inline-Noinst-Test - pass Asan-riscv64-calls-Noinst-Test - pass Asan-riscv64-calls-Test - pass ``` Lit tests: ``` RISCV64LinuxConfig (282 supported, few failures) RISCV64LinuxDynamicConfig (289 supported, few failures) ``` Lit failures: ``` TestCases/malloc_context_size.cpp - asan works, but backtrace misses some calls TestCases/Linux/malloc_delete_mismatch.cpp - asan works, but backtrace misses some calls TestCases/Linux/static_tls.cpp - "Can't guess glibc version" (under debugging) TestCases/asan_and_llvm_coverage_test.cpp - missing libclang_rt.profile-riscv64.a ``` These failures are under debugging currently and shall be addressed in a subsequent commits. Depends On D87581 Reviewed By: eugenis, vitalybuka Differential Revision: https://reviews.llvm.org/D87582
1 parent a58b20e commit cf4aa68

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

compiler-rt/cmake/config-ix.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ endif()
294294

295295
set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64}
296296
${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
297-
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
297+
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
298298
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9})
299299
set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64})
300300
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})

compiler-rt/lib/asan/scripts/asan_symbolize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def fix_filename(file_name):
4949

5050
def is_valid_arch(s):
5151
return s in ["i386", "x86_64", "x86_64h", "arm", "armv6", "armv7", "armv7s",
52-
"armv7k", "arm64", "powerpc64", "powerpc64le", "s390x", "s390"]
52+
"armv7k", "arm64", "powerpc64", "powerpc64le", "s390x", "s390",
53+
"riscv64"]
5354

5455
def guess_arch(addr):
5556
# Guess which arch we're running. 10 = len('0x') + 8 hex digits.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ NOINLINE void SigLongJmpFunc1(sigjmp_buf buf) {
621621
siglongjmp(buf, 1);
622622
}
623623

624-
#if !defined(__ANDROID__) && !defined(__arm__) && \
625-
!defined(__aarch64__) && !defined(__mips__) && \
626-
!defined(__mips64) && !defined(__s390__)
624+
#if !defined(__ANDROID__) && !defined(__arm__) && !defined(__aarch64__) && \
625+
!defined(__mips__) && !defined(__mips64) && !defined(__s390__) && \
626+
!defined(__riscv)
627627
NOINLINE void BuiltinLongJmpFunc1(jmp_buf buf) {
628628
// create three red zones for these two stack objects.
629629
int a;
@@ -648,6 +648,7 @@ TEST(AddressSanitizer, BuiltinLongJmpTest) {
648648
#endif // !defined(__ANDROID__) && !defined(__arm__) &&
649649
// !defined(__aarch64__) && !defined(__mips__)
650650
// !defined(__mips64) && !defined(__s390__)
651+
// !defined(__riscv)
651652

652653
TEST(AddressSanitizer, UnderscopeLongJmpTest) {
653654
static jmp_buf buf;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(CompilerRTCompile)
33
clang_compiler_add_cxx_check()
44

55
# FIXME: use SANITIZER_COMMON_SUPPORTED_ARCH here
6-
filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)
6+
filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el riscv64)
77
if(APPLE)
88
darwin_filter_host_archs(SANITIZER_UNITTEST_SUPPORTED_ARCH SANITIZER_UNITTEST_SUPPORTED_ARCH)
99
endif()

compiler-rt/test/asan/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND
1414
endif()
1515

1616
macro(get_bits_for_arch arch bits)
17-
if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9")
17+
if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9|riscv64")
1818
set(${bits} 64)
1919
elseif (${arch} MATCHES "i386|arm|mips|mipsel|sparc")
2020
set(${bits} 32)

compiler-rt/test/asan/TestCases/Linux/ptrace.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ typedef _user_fpregs_struct fpregs_struct;
6666
#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.psw.addr))
6767
#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (unsigned long) (__fpregs.fpc))
6868
#define ARCH_IOVEC_FOR_GETREGSET
69+
70+
#elif defined(__riscv) && (__riscv_xlen == 64)
71+
#include <asm/ptrace.h>
72+
typedef user_regs_struct regs_struct;
73+
typedef __riscv_q_ext_state fpregs_struct;
74+
#define PRINT_REG_PC(__regs) printf("%lx\n", (unsigned long)(__regs.pc))
75+
#define PRINT_REG_FP(__fpregs) printf("%lx\n", (unsigned long)(__fpregs.fcsr))
76+
#define ARCH_IOVEC_FOR_GETREGSET
6977
#endif
7078

7179

compiler-rt/test/asan/TestCases/Linux/vfork.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// https://github.com/google/sanitizers/issues/925
22
// RUN: %clang_asan -O0 %s -o %t && %run %t 2>&1
33

4-
// REQUIRES: aarch64-target-arch || x86_64-target-arch || i386-target-arch || arm-target-arch
4+
// REQUIRES: aarch64-target-arch || x86_64-target-arch || i386-target-arch || arm-target-arch || riscv64-target-arch
55

66
#include <assert.h>
77
#include <sys/types.h>

0 commit comments

Comments
 (0)