[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
This commit is contained in:
Alexey Baturo 2020-10-04 16:51:04 +03:00 committed by apink
parent a58b20e5a4
commit cf4aa68388
7 changed files with 18 additions and 8 deletions

View File

@ -294,7 +294,7 @@ endif()
set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64}
${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9})
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9})
set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64})
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})

View File

@ -49,7 +49,8 @@ def fix_filename(file_name):
def is_valid_arch(s):
return s in ["i386", "x86_64", "x86_64h", "arm", "armv6", "armv7", "armv7s",
"armv7k", "arm64", "powerpc64", "powerpc64le", "s390x", "s390"]
"armv7k", "arm64", "powerpc64", "powerpc64le", "s390x", "s390",
"riscv64"]
def guess_arch(addr):
# Guess which arch we're running. 10 = len('0x') + 8 hex digits.

View File

@ -621,9 +621,9 @@ NOINLINE void SigLongJmpFunc1(sigjmp_buf buf) {
siglongjmp(buf, 1);
}
#if !defined(__ANDROID__) && !defined(__arm__) && \
!defined(__aarch64__) && !defined(__mips__) && \
!defined(__mips64) && !defined(__s390__)
#if !defined(__ANDROID__) && !defined(__arm__) && !defined(__aarch64__) && \
!defined(__mips__) && !defined(__mips64) && !defined(__s390__) && \
!defined(__riscv)
NOINLINE void BuiltinLongJmpFunc1(jmp_buf buf) {
// create three red zones for these two stack objects.
int a;
@ -648,6 +648,7 @@ TEST(AddressSanitizer, BuiltinLongJmpTest) {
#endif // !defined(__ANDROID__) && !defined(__arm__) &&
// !defined(__aarch64__) && !defined(__mips__)
// !defined(__mips64) && !defined(__s390__)
// !defined(__riscv)
TEST(AddressSanitizer, UnderscopeLongJmpTest) {
static jmp_buf buf;

View File

@ -3,7 +3,7 @@ include(CompilerRTCompile)
clang_compiler_add_cxx_check()
# FIXME: use SANITIZER_COMMON_SUPPORTED_ARCH here
filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)
filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el riscv64)
if(APPLE)
darwin_filter_host_archs(SANITIZER_UNITTEST_SUPPORTED_ARCH SANITIZER_UNITTEST_SUPPORTED_ARCH)
endif()

View File

@ -14,7 +14,7 @@ if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND
endif()
macro(get_bits_for_arch arch bits)
if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9")
if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9|riscv64")
set(${bits} 64)
elseif (${arch} MATCHES "i386|arm|mips|mipsel|sparc")
set(${bits} 32)

View File

@ -66,6 +66,14 @@ typedef _user_fpregs_struct fpregs_struct;
#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.psw.addr))
#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (unsigned long) (__fpregs.fpc))
#define ARCH_IOVEC_FOR_GETREGSET
#elif defined(__riscv) && (__riscv_xlen == 64)
#include <asm/ptrace.h>
typedef user_regs_struct regs_struct;
typedef __riscv_q_ext_state fpregs_struct;
#define PRINT_REG_PC(__regs) printf("%lx\n", (unsigned long)(__regs.pc))
#define PRINT_REG_FP(__fpregs) printf("%lx\n", (unsigned long)(__fpregs.fcsr))
#define ARCH_IOVEC_FOR_GETREGSET
#endif

View File

@ -1,7 +1,7 @@
// https://github.com/google/sanitizers/issues/925
// RUN: %clang_asan -O0 %s -o %t && %run %t 2>&1
// REQUIRES: aarch64-target-arch || x86_64-target-arch || i386-target-arch || arm-target-arch
// REQUIRES: aarch64-target-arch || x86_64-target-arch || i386-target-arch || arm-target-arch || riscv64-target-arch
#include <assert.h>
#include <sys/types.h>