Check for 64bit atomic operations

May not be supported on some 32bit architectures.

```
/usr/lib/gcc-cross/m68k-linux-gnu/14/../../../../m68k-linux-gnu/bin/ld: ../../libruby-static.a(vm.o): in function `rbimpl_atomic_u64_set_relaxed':
/home/ubuntu/build/ruby/master/m68k-linux/../src/ruby_atomic.h:60:(.text+0x2468): undefined reference to `__atomic_store_8'
/usr/lib/gcc-cross/m68k-linux-gnu/14/../../../../m68k-linux-gnu/bin/ld: ../../libruby-static.a(vm.o): in function `rbimpl_atomic_u64_load_relaxed':
/home/ubuntu/build/ruby/master/m68k-linux/../src/ruby_atomic.h:43:(.text+0x2950):
undefined reference to `__atomic_load_8'
```
This commit is contained in:
Nobuyoshi Nakada 2025-06-04 13:35:39 +09:00
parent 47f55b4b44
commit c5f7d274d7
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2025-06-04 07:38:11 +00:00
2 changed files with 14 additions and 2 deletions

View File

@ -1743,6 +1743,18 @@ AS_IF([test "$GCC" = yes], [
[rb_cv_gcc_atomic_builtins=no])]) [rb_cv_gcc_atomic_builtins=no])])
AS_IF([test "$rb_cv_gcc_atomic_builtins" = yes], [ AS_IF([test "$rb_cv_gcc_atomic_builtins" = yes], [
AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS) AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS)
AC_CACHE_CHECK([for 64bit __atomic builtins], [rb_cv_gcc_atomic_builtins_64], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdint.h>
uint64_t atomic_var;]],
[[
__atomic_load_n(&atomic_var, __ATOMIC_RELAXED);
__atomic_store_n(&atomic_var, 0, __ATOMIC_RELAXED);
]])],
[rb_cv_gcc_atomic_builtins_64=yes],
[rb_cv_gcc_atomic_builtins_64=no])])
AS_IF([test "$rb_cv_gcc_atomic_builtins_64" = yes], [
AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS_64)
])
]) ])
AC_CACHE_CHECK([for __sync builtins], [rb_cv_gcc_sync_builtins], [ AC_CACHE_CHECK([for __sync builtins], [rb_cv_gcc_sync_builtins], [

View File

@ -39,7 +39,7 @@ rbimpl_atomic_load_relaxed(rb_atomic_t *ptr)
static inline uint64_t static inline uint64_t
rbimpl_atomic_u64_load_relaxed(const uint64_t *value) rbimpl_atomic_u64_load_relaxed(const uint64_t *value)
{ {
#if defined(HAVE_GCC_ATOMIC_BUILTINS) #if defined(HAVE_GCC_ATOMIC_BUILTINS_64)
return __atomic_load_n(value, __ATOMIC_RELAXED); return __atomic_load_n(value, __ATOMIC_RELAXED);
#elif defined(_WIN32) #elif defined(_WIN32)
uint64_t val = *value; uint64_t val = *value;
@ -56,7 +56,7 @@ rbimpl_atomic_u64_load_relaxed(const uint64_t *value)
static inline void static inline void
rbimpl_atomic_u64_set_relaxed(uint64_t *address, uint64_t value) rbimpl_atomic_u64_set_relaxed(uint64_t *address, uint64_t value)
{ {
#if defined(HAVE_GCC_ATOMIC_BUILTINS) #if defined(HAVE_GCC_ATOMIC_BUILTINS_64)
__atomic_store_n(address, value, __ATOMIC_RELAXED); __atomic_store_n(address, value, __ATOMIC_RELAXED);
#elif defined(_WIN32) #elif defined(_WIN32)
InterlockedExchange64(address, value); InterlockedExchange64(address, value);