Skip to content

Commit c5f7d27

Browse files
committed
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' ```
1 parent 47f55b4 commit c5f7d27

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,18 @@ AS_IF([test "$GCC" = yes], [
17431743
[rb_cv_gcc_atomic_builtins=no])])
17441744
AS_IF([test "$rb_cv_gcc_atomic_builtins" = yes], [
17451745
AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS)
1746+
AC_CACHE_CHECK([for 64bit __atomic builtins], [rb_cv_gcc_atomic_builtins_64], [
1747+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdint.h>
1748+
uint64_t atomic_var;]],
1749+
[[
1750+
__atomic_load_n(&atomic_var, __ATOMIC_RELAXED);
1751+
__atomic_store_n(&atomic_var, 0, __ATOMIC_RELAXED);
1752+
]])],
1753+
[rb_cv_gcc_atomic_builtins_64=yes],
1754+
[rb_cv_gcc_atomic_builtins_64=no])])
1755+
AS_IF([test "$rb_cv_gcc_atomic_builtins_64" = yes], [
1756+
AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS_64)
1757+
])
17461758
])
17471759

17481760
AC_CACHE_CHECK([for __sync builtins], [rb_cv_gcc_sync_builtins], [

ruby_atomic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ rbimpl_atomic_load_relaxed(rb_atomic_t *ptr)
3939
static inline uint64_t
4040
rbimpl_atomic_u64_load_relaxed(const uint64_t *value)
4141
{
42-
#if defined(HAVE_GCC_ATOMIC_BUILTINS)
42+
#if defined(HAVE_GCC_ATOMIC_BUILTINS_64)
4343
return __atomic_load_n(value, __ATOMIC_RELAXED);
4444
#elif defined(_WIN32)
4545
uint64_t val = *value;
@@ -56,7 +56,7 @@ rbimpl_atomic_u64_load_relaxed(const uint64_t *value)
5656
static inline void
5757
rbimpl_atomic_u64_set_relaxed(uint64_t *address, uint64_t value)
5858
{
59-
#if defined(HAVE_GCC_ATOMIC_BUILTINS)
59+
#if defined(HAVE_GCC_ATOMIC_BUILTINS_64)
6060
__atomic_store_n(address, value, __ATOMIC_RELAXED);
6161
#elif defined(_WIN32)
6262
InterlockedExchange64(address, value);

0 commit comments

Comments
 (0)