1*4882a593SmuzhiyunFrom 95e601ce116dd46ea7915c171976b85ea0905d58 Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Lonnie Abelbeck <lonnie@abelbeck.com> 3*4882a593SmuzhiyunDate: Sun, 8 May 2022 14:05:56 -0500 4*4882a593SmuzhiyunSubject: [PATCH] configure.ac: Link with -latomic only if no atomic builtins 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunFollow-up to 561dbda, a check of GCC atomic builtins needs to be done 7*4882a593Smuzhiyunfirst. 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunI'm no autoconf guru, but using this: 10*4882a593Smuzhiyunhttps://github.com/mesa3d/mesa/blob/0df485c285b73c34ba9062f0c27e55c3c702930d/configure.ac#L469 11*4882a593Smuzhiyunas inspiration, I created a pre-check before calling AC_SEARCH_LIBS(...) 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunFixes #1135 14*4882a593SmuzhiyunCloses #1139 15*4882a593SmuzhiyunUpstream-Status: Backport [https://github.com/kraj/libusb/commit/95e601ce116dd46ea7915c171976b85ea0905d58] 16*4882a593SmuzhiyunSigned-off-by: Khem Raj <raj.khem@gmail.com> 17*4882a593Smuzhiyun--- 18*4882a593Smuzhiyun configure.ac | 16 +++++++++++++++- 19*4882a593Smuzhiyun libusb/version_nano.h | 2 +- 20*4882a593Smuzhiyun 2 files changed, 16 insertions(+), 2 deletions(-) 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun--- a/configure.ac 23*4882a593Smuzhiyun+++ b/configure.ac 24*4882a593Smuzhiyun@@ -153,7 +153,21 @@ if test "x$platform" = xposix; then 25*4882a593Smuzhiyun AC_SEARCH_LIBS([pthread_create], [pthread], 26*4882a593Smuzhiyun [test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])], 27*4882a593Smuzhiyun [], []) 28*4882a593Smuzhiyun- AC_SEARCH_LIBS([__atomic_fetch_add_4], [atomic]) 29*4882a593Smuzhiyun+ dnl Check for new-style atomic builtins. We first check without linking to -latomic. 30*4882a593Smuzhiyun+ AC_MSG_CHECKING(whether __atomic_load_n is supported) 31*4882a593Smuzhiyun+ AC_LINK_IFELSE([AC_LANG_SOURCE([[ 32*4882a593Smuzhiyun+ #include <stdint.h> 33*4882a593Smuzhiyun+ int main() { 34*4882a593Smuzhiyun+ struct { 35*4882a593Smuzhiyun+ uint64_t *v; 36*4882a593Smuzhiyun+ } x; 37*4882a593Smuzhiyun+ return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) & 38*4882a593Smuzhiyun+ (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL); 39*4882a593Smuzhiyun+ }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=yes, GCC_ATOMIC_BUILTINS_SUPPORTED=no) 40*4882a593Smuzhiyun+ AC_MSG_RESULT($GCC_ATOMIC_BUILTINS_SUPPORTED) 41*4882a593Smuzhiyun+ if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != xyes; then 42*4882a593Smuzhiyun+ AC_SEARCH_LIBS([__atomic_fetch_add_4], [atomic]) 43*4882a593Smuzhiyun+ fi 44*4882a593Smuzhiyun elif test "x$platform" = xwindows; then 45*4882a593Smuzhiyun AC_DEFINE([PLATFORM_WINDOWS], [1], [Define to 1 if compiling for a Windows platform.]) 46*4882a593Smuzhiyun else 47