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
This commit is contained in:
Daniel Black 2024-11-26 09:37:28 +11:00
parent 3d23adb766
commit aca72b326a

View file

@ -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__