diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h --- a/compiler-rt/lib/asan/asan_allocator.h +++ b/compiler-rt/lib/asan/asan_allocator.h @@ -15,10 +15,11 @@ #define ASAN_ALLOCATOR_H #include "asan_flags.h" -#include "asan_internal.h" #include "asan_interceptors.h" +#include "asan_internal.h" #include "sanitizer_common/sanitizer_allocator.h" #include "sanitizer_common/sanitizer_list.h" +#include "sanitizer_common/sanitizer_platform.h" namespace __asan { @@ -132,7 +133,7 @@ const uptr kAllocatorSpace = ~(uptr)0; const uptr kAllocatorSize = 0x2000000000ULL; // 128G. typedef VeryCompactSizeClassMap SizeClassMap; -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) const uptr kAllocatorSpace = ~(uptr)0; const uptr kAllocatorSize = 0x2000000000ULL; // 128G. typedef VeryDenseSizeClassMap SizeClassMap; diff --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h --- a/compiler-rt/lib/asan/asan_interceptors.h +++ b/compiler-rt/lib/asan/asan_interceptors.h @@ -13,9 +13,10 @@ #ifndef ASAN_INTERCEPTORS_H #define ASAN_INTERCEPTORS_H -#include "asan_internal.h" #include "asan_interceptors_memintrinsics.h" +#include "asan_internal.h" #include "interception/interception.h" +#include "sanitizer_common/sanitizer_platform.h" #include "sanitizer_common/sanitizer_platform_interceptors.h" namespace __asan { @@ -113,7 +114,7 @@ #if SANITIZER_LINUX && \ (defined(__arm__) || defined(__aarch64__) || defined(__i386__) || \ - defined(__x86_64__) || (defined(__riscv) && (__riscv_xlen == 64))) + defined(__x86_64__) || defined(SANITIZER_RISCV64)) # define ASAN_INTERCEPT_VFORK 1 #else # define ASAN_INTERCEPT_VFORK 0 diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h --- a/compiler-rt/lib/asan/asan_mapping.h +++ b/compiler-rt/lib/asan/asan_mapping.h @@ -223,7 +223,7 @@ # define SHADOW_OFFSET __asan_shadow_memory_dynamic_address # elif SANITIZER_MAC && defined(__aarch64__) # define SHADOW_OFFSET __asan_shadow_memory_dynamic_address -#elif (defined(__riscv) && (__riscv_xlen == 64)) +# elif defined(SANITIZER_RISCV64) # define SHADOW_OFFSET kRiscv64_ShadowOffset64 # elif defined(__aarch64__) # define SHADOW_OFFSET kAArch64_ShadowOffset64 diff --git a/compiler-rt/lib/asan/asan_shadow_setup.cpp b/compiler-rt/lib/asan/asan_shadow_setup.cpp --- a/compiler-rt/lib/asan/asan_shadow_setup.cpp +++ b/compiler-rt/lib/asan/asan_shadow_setup.cpp @@ -45,7 +45,7 @@ static void MaybeReportLinuxPIEBug() { #if SANITIZER_LINUX && (defined(__x86_64__) || defined(__aarch64__) || \ - (defined(__riscv) && (__riscv_xlen == 64))) + defined(SANITIZER_RISCV64)) Report("This might be related to ELF_ET_DYN_BASE change in Linux 4.12.\n"); Report( "See https://github.com/google/sanitizers/issues/856 for possible " diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc @@ -2297,7 +2297,7 @@ #if !SANITIZER_ANDROID && \ (defined(__i386) || defined(__x86_64) || defined(__mips64) || \ defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \ - (defined(__riscv) && (__riscv_xlen == 64))) + defined(SANITIZER_RISCV64)) if (data) { if (request == ptrace_setregs) { PRE_READ((void *)data, struct_user_regs_struct_sz); @@ -2319,7 +2319,7 @@ #if !SANITIZER_ANDROID && \ (defined(__i386) || defined(__x86_64) || defined(__mips64) || \ defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \ - (defined(__riscv) && (__riscv_xlen == 64))) + defined(SANITIZER_RISCV64)) if (res >= 0 && data) { // Note that this is different from the interceptor in // sanitizer_common_interceptors.inc. diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h @@ -62,7 +62,7 @@ void internal_sigdelset(__sanitizer_sigset_t *set, int signum); #if defined(__x86_64__) || defined(__mips__) || defined(__aarch64__) || \ defined(__powerpc64__) || defined(__s390__) || defined(__i386__) || \ - defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 64)) + defined(__arm__) || defined(SANITIZER_RISCV64) uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, int *parent_tidptr, void *newtls, int *child_tidptr); #endif diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -154,7 +154,7 @@ #if SANITIZER_LINUX && defined(__x86_64__) #include "sanitizer_syscall_linux_x86_64.inc" -#elif SANITIZER_LINUX && (defined(__riscv) && (__riscv_xlen == 64)) +#elif SANITIZER_LINUX && defined(SANITIZER_RISCV64) #include "sanitizer_syscall_linux_riscv64.inc" #elif SANITIZER_LINUX && defined(__aarch64__) #include "sanitizer_syscall_linux_aarch64.inc" @@ -712,8 +712,7 @@ }; #else struct linux_dirent { -#if SANITIZER_X32 || defined(__aarch64__) || \ - (defined(__riscv) && (__riscv_xlen == 64)) +#if SANITIZER_X32 || defined(__aarch64__) || defined(SANITIZER_RISCV64) u64 d_ino; u64 d_off; #else @@ -721,7 +720,7 @@ unsigned long d_off; #endif unsigned short d_reclen; -#if defined(__aarch64__) || (defined(__riscv) && (__riscv_xlen == 64)) +#if defined(__aarch64__) || defined(SANITIZER_RISCV64) unsigned char d_type; #endif char d_name[256]; @@ -1070,7 +1069,7 @@ // This should (does) work for both PowerPC64 Endian modes. // Similarly, aarch64 has multiple address space layouts: 39, 42 and 47-bit. return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1; -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) return (1ULL << 38) - 1; # elif defined(__mips64) return (1ULL << 40) - 1; // 0x000000ffffffffffUL; @@ -1366,7 +1365,7 @@ : "memory", "$29" ); return res; } -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, int *parent_tidptr, void *newtls, int *child_tidptr) { long long res; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -267,7 +267,7 @@ #if (defined(__x86_64__) || defined(__i386__) || defined(__mips__) || \ defined(__aarch64__) || defined(__powerpc64__) || defined(__s390__) || \ - defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 64))) && \ + defined(__arm__) || defined(SANITIZER_RISCV64)) && \ SANITIZER_LINUX && !SANITIZER_ANDROID // sizeof(struct pthread) from glibc. static atomic_uintptr_t thread_descriptor_size; @@ -307,8 +307,8 @@ #elif defined(__mips__) // TODO(sagarthakur): add more values as per different glibc versions. val = FIRST_32_SECOND_64(1152, 1776); -#elif (defined(__riscv) && (__riscv_xlen == 64)) - val = 1772; // valid for GLIBC 2.29 +#elif defined(SANITIZER_RISCV64) + val = 1772; // valid for GLIBC 2.29 #elif defined(__aarch64__) // The sizeof (struct pthread) is the same from GLIBC 2.17 to 2.22. val = 1776; @@ -329,8 +329,7 @@ return kThreadSelfOffset; } -#if defined(__mips__) || defined(__powerpc64__) || \ - (defined(__riscv) && (__riscv_xlen == 64)) +#if defined(__mips__) || defined(__powerpc64__) || defined(SANITIZER_RISCV64) // TlsPreTcbSize includes size of struct pthread_descr and size of tcb // head structure. It lies before the static tls blocks. static uptr TlsPreTcbSize() { @@ -338,7 +337,7 @@ const uptr kTcbHead = 16; // sizeof (tcbhead_t) # elif defined(__powerpc64__) const uptr kTcbHead = 88; // sizeof (tcbhead_t) -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) const uptr kTcbHead = 16; // sizeof (tcbhead_t) # endif const uptr kTlsAlign = 16; @@ -369,15 +368,13 @@ # elif defined(__aarch64__) || defined(__arm__) descr_addr = reinterpret_cast(__builtin_thread_pointer()) - ThreadDescriptorSize(); -#elif (defined(__riscv) && (__riscv_xlen == 64)) - +#elif defined(SANITIZER_RISCV64) uptr tcb_end; asm volatile("mv %0, tp;\n" : "=r"(tcb_end)); // https://github.com/riscv/riscv-elf-psabi-doc/issues/53 const uptr kTlsTcbOffset = 0x800; descr_addr = reinterpret_cast(tcb_end - kTlsTcbOffset - TlsPreTcbSize()); - # elif defined(__s390__) descr_addr = reinterpret_cast(__builtin_thread_pointer()); # elif defined(__powerpc64__) @@ -448,7 +445,7 @@ *addr -= *size; *addr += ThreadDescriptorSize(); #elif defined(__mips__) || defined(__aarch64__) || defined(__powerpc64__) || \ - defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 64)) + defined(__arm__) || defined(SANITIZER_RISCV64) *addr = ThreadSelf(); *size = GetTlsSize(); # else @@ -505,8 +502,7 @@ uptr addr, size; GetTls(&addr, &size); return size; -#elif defined(__mips__) || defined(__powerpc64__) || \ - (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(__mips__) || defined(__powerpc64__) || defined(SANITIZER_RISCV64) return RoundUpTo(g_tls_size + TlsPreTcbSize(), 16); #else return g_tls_size; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -132,6 +132,12 @@ # define SANITIZER_X32 0 #endif +#if (defined(__riscv) && (__riscv_xlen == 64)) +# define SANITIZER_RISCV64 1 +#else +# define SANITIZER_RISCV64 0 +#endif + #if defined(__i386__) || defined(_M_IX86) # define SANITIZER_I386 1 #else @@ -239,8 +245,8 @@ // will still work but will consume more memory for TwoLevelByteMap. #if defined(__mips__) # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40) -#elif (defined(__riscv) && (__riscv_xlen == 64)) -#define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 38) +#elif defined(SANITIZER_RISCV64) +# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 38) #elif defined(__aarch64__) # if SANITIZER_MAC // Darwin iOS/ARM64 has a 36-bit VMA, 64GiB VM diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -15,6 +15,7 @@ #include "sanitizer_glibc_version.h" #include "sanitizer_internal_defs.h" +#include "sanitizer_platform.h" #if SANITIZER_POSIX # define SI_POSIX 1 @@ -281,7 +282,7 @@ #if SI_LINUX_NOT_ANDROID && \ (defined(__i386) || defined(__x86_64) || defined(__mips64) || \ defined(__powerpc64__) || defined(__aarch64__) || defined(__arm__) || \ - defined(__s390__) || (defined(__riscv) && (__riscv_xlen == 64))) + defined(__s390__) || defined(SANITIZER_RISCV64)) #define SANITIZER_INTERCEPT_PTRACE 1 #else #define SANITIZER_INTERCEPT_PTRACE 0 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -99,7 +99,7 @@ const unsigned struct___old_kernel_stat_sz = 0; const unsigned struct_kernel_stat_sz = 64; const unsigned struct_kernel_stat64_sz = 104; -#elif defined(__riscv) && __riscv_xlen == 64 +#elif defined(SANITIZER_RISCV64) const unsigned struct_kernel_stat_sz = 128; const unsigned struct_kernel_stat64_sz = 104; #endif @@ -804,7 +804,7 @@ #if SANITIZER_LINUX && !SANITIZER_ANDROID && \ (defined(__i386) || defined(__x86_64) || defined(__mips64) || \ defined(__powerpc64__) || defined(__aarch64__) || defined(__arm__) || \ - defined(__s390__) || (defined(__riscv) && (__riscv_xlen == 64))) + defined(__s390__) || defined(SANITIZER_RISCV64)) extern unsigned struct_user_regs_struct_sz; extern unsigned struct_user_fpregs_struct_sz; extern unsigned struct_user_fpxregs_struct_sz; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -91,7 +91,7 @@ # include # include #if defined(__mips64) || defined(__aarch64__) || defined(__arm__) || \ - (defined(__riscv) && (__riscv_xlen == 64)) + defined(SANITIZER_RISCV64) # include # ifdef __arm__ typedef struct user_fpregs elf_fpregset_t; @@ -230,9 +230,9 @@ #if SANITIZER_LINUX && !SANITIZER_ANDROID // Use pre-computed size of struct ustat to avoid which // has been removed from glibc 2.28. -#if defined(__aarch64__) || defined(__s390x__) || defined (__mips64) \ - || defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) \ - || defined(__x86_64__) || (defined(__riscv) && __riscv_xlen == 64) +#if defined(__aarch64__) || defined(__s390x__) || defined(__mips64) || \ + defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) || \ + defined(__x86_64__) || defined(SANITIZER_RISCV64) #define SIZEOF_STRUCT_USTAT 32 #elif defined(__arm__) || defined(__i386__) || defined(__mips__) \ || defined(__powerpc__) || defined(__s390__) || defined(__sparc__) @@ -307,11 +307,11 @@ #if SANITIZER_LINUX && !SANITIZER_ANDROID && \ (defined(__i386) || defined(__x86_64) || defined(__mips64) || \ defined(__powerpc64__) || defined(__aarch64__) || defined(__arm__) || \ - defined(__s390__) || (defined(__riscv) && (__riscv_xlen == 64))) + defined(__s390__) || defined(SANITIZER_RISCV64)) #if defined(__mips64) || defined(__powerpc64__) || defined(__arm__) unsigned struct_user_regs_struct_sz = sizeof(struct pt_regs); unsigned struct_user_fpregs_struct_sz = sizeof(elf_fpregset_t); -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) unsigned struct_user_regs_struct_sz = sizeof(struct user_regs_struct); unsigned struct_user_fpregs_struct_sz = sizeof(struct __riscv_q_ext_state); #elif defined(__aarch64__) @@ -326,7 +326,7 @@ #endif // __mips64 || __powerpc64__ || __aarch64__ #if defined(__x86_64) || defined(__mips64) || defined(__powerpc64__) || \ defined(__aarch64__) || defined(__arm__) || defined(__s390__) || \ - (defined(__riscv) && (__riscv_xlen == 64)) + defined(SANITIZER_RISCV64) unsigned struct_user_fpxregs_struct_sz = 0; #else unsigned struct_user_fpxregs_struct_sz = sizeof(struct user_fpxregs_struct); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -13,6 +13,7 @@ #define SANITIZER_STACKTRACE_H #include "sanitizer_internal_defs.h" +#include "sanitizer_platform.h" namespace __sanitizer { @@ -85,7 +86,7 @@ return pc - 4; #elif defined(__sparc__) || defined(__mips__) return pc - 8; -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) // RV-64 has variable instruciton length... // C extentions gives us 2-byte instructoins // RV-64 has 4-byte instructions diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp @@ -10,9 +10,11 @@ // run-time libraries. //===----------------------------------------------------------------------===// +#include "sanitizer_stacktrace.h" + #include "sanitizer_common.h" #include "sanitizer_flags.h" -#include "sanitizer_stacktrace.h" +#include "sanitizer_platform.h" namespace __sanitizer { @@ -21,7 +23,7 @@ return pc + 8; #elif defined(__powerpc__) || defined(__arm__) || defined(__aarch64__) return pc + 4; -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) // Current check order is 4 -> 2 -> 6 -> 8 u8 InsnByte = *(u8 *)(pc); if (((InsnByte & 0x3) == 0x3) && ((InsnByte & 0x1c) != 0x1c)) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp @@ -16,7 +16,7 @@ #if SANITIZER_LINUX && \ (defined(__x86_64__) || defined(__mips__) || defined(__aarch64__) || \ defined(__powerpc64__) || defined(__s390__) || defined(__i386__) || \ - defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 64))) + defined(__arm__) || defined(SANITIZER_RISCV64)) #include "sanitizer_stoptheworld.h" @@ -31,8 +31,7 @@ #include // for pid_t #include // for iovec #include // for NT_PRSTATUS -#if (defined(__aarch64__) || (defined(__riscv) && (__riscv_xlen == 64))) && \ - !SANITIZER_ANDROID +#if (defined(__aarch64__) || defined(SANITIZER_RISCV64)) && !SANITIZER_ANDROID // GLIBC 2.20+ sys/user does not include asm/ptrace.h # include #endif @@ -504,7 +503,7 @@ #define REG_SP sp #define ARCH_IOVEC_FOR_GETREGSET -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) typedef struct user_regs_struct regs_struct; #define REG_SP sp #define ARCH_IOVEC_FOR_GETREGSET diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp @@ -12,6 +12,7 @@ #include "sanitizer_allocator_internal.h" #include "sanitizer_internal_defs.h" +#include "sanitizer_platform.h" #include "sanitizer_symbolizer_internal.h" namespace __sanitizer { @@ -258,7 +259,7 @@ const char* const kSymbolizerArch = "--default-arch=x86_64"; #elif defined(__i386__) const char* const kSymbolizerArch = "--default-arch=i386"; -#elif (defined(__riscv) && (__riscv_xlen == 64)) +#elif defined(SANITIZER_RISCV64) const char *const kSymbolizerArch = "--default-arch=riscv64"; #elif defined(__aarch64__) const char* const kSymbolizerArch = "--default-arch=arm64";