Skip to content

Commit 4de4221

Browse files
committed
build: Check for std::atomic::exchange rather than std::atomic_exchange
Our usage of std::atomic is with it's own exchange function, not std::atomic_exchange. So we should be looking specifically for that function. Additionally, -pthread and -lpthread have an effect on whether -latomic will be needed, so the atomics check needs to use these flags as well. This will make the flags in use better match what is actually used when linking. This removes the need for -latomic for riscv builds, which resolves a guix cross architecture reproducibility issue.
1 parent c92eb6c commit 4de4221

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

build-aux/m4/l_atomic.m4

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ m4_define([_CHECK_ATOMIC_testbody], [[
1818
1919
int main() {
2020
std::atomic<bool> lock{true};
21-
std::atomic_exchange(&lock, false);
21+
lock.exchange(false);
2222
2323
std::atomic<std::chrono::seconds> t{0s};
2424
t.store(2s);
@@ -34,6 +34,8 @@ m4_define([_CHECK_ATOMIC_testbody], [[
3434
AC_DEFUN([CHECK_ATOMIC], [
3535
3636
AC_LANG_PUSH(C++)
37+
TEMP_CXXFLAGS="$CXXFLAGS"
38+
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
3739
3840
AC_MSG_CHECKING([whether std::atomic can be used without link library])
3941
@@ -51,5 +53,6 @@ AC_DEFUN([CHECK_ATOMIC], [
5153
])
5254
])
5355
56+
CXXFLAGS="$TEMP_CXXFLAGS"
5457
AC_LANG_POP
5558
])

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ else
8787
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
8888
fi
8989

90-
dnl Check if -latomic is required for <std::atomic>
91-
CHECK_ATOMIC
92-
9390
dnl check if additional link flags are required for std::filesystem
9491
CHECK_FILESYSTEM
9592

@@ -887,6 +884,9 @@ AC_C_BIGENDIAN
887884
dnl Check for pthread compile/link requirements
888885
AX_PTHREAD
889886

887+
dnl Check if -latomic is required for <std::atomic>
888+
CHECK_ATOMIC
889+
890890
dnl The following macro will add the necessary defines to bitcoin-config.h, but
891891
dnl they also need to be passed down to any subprojects. Pull the results out of
892892
dnl the cache and add them to CPPFLAGS.

0 commit comments

Comments
 (0)