From aca72b326ae584851e5d755ff0b5fdb89e05c2e7 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 26 Nov 2024 09:37:28 +1100 Subject: [PATCH] MDEV-34815 SIGILL error when executing mariadbd compiled for RISC-V with Clang RISC-V and Clang produce rdcycle for __builtin_readcyclecounter. Since Linux kernel 6.6 this is a privileged instruction not available to userspace programs. The use of __builtin_readcyclecounter is excluded from RISCV falling back to the rdtime/rdtimeh instructions provided in MDEV-33435. Thanks Alexander Richardson for noting it should be linux only in the code and noting FreeBSD RISC-V permits rdcycle. Author: BINSZ on JIRA --- include/my_rdtsc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/my_rdtsc.h b/include/my_rdtsc.h index 45e91d228f1..70be851dac0 100644 --- a/include/my_rdtsc.h +++ b/include/my_rdtsc.h @@ -97,7 +97,7 @@ C_MODE_START /** A cycle timer. - On clang we use __builtin_readcyclecounter(), except for AARCH64. + On clang we use __builtin_readcyclecounter(), except for AARCH64 and RISC-V. On other compilers: On IA-32 and AMD64, we use the RDTSC instruction. @@ -152,7 +152,7 @@ C_MODE_START */ static inline ulonglong my_timer_cycles(void) { -# if __has_builtin(__builtin_readcyclecounter) && !defined (__aarch64__) +# if __has_builtin(__builtin_readcyclecounter) && !defined (__aarch64__) && !(defined(__linux__) && defined(__riscv)) #define MY_TIMER_ROUTINE_CYCLES MY_TIMER_ROUTINE_AARCH64 return __builtin_readcyclecounter(); # elif defined _M_IX86 || defined _M_X64 || defined __i386__ || defined __x86_64__