]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl-functions.m4: check whether atomics can link rather than just compile
authorDaniel Katz <katzdm@gmail.com>
Thu, 21 Jul 2022 00:20:42 +0000 (20:20 -0400)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 21 Jul 2022 14:30:19 +0000 (16:30 +0200)
Some build toolchains support C11 atomics (i.e., _Atomic types), but
will not link the associated atomics runtime unless a flag is passed. In
such an environment, linking an application with libcurl.a can fail due
to undefined symbols for atomic load/store functions.

I encountered this behavior when upgrading curl to 7.84.0 and attempting
to build with Solaris Studio 12.6. Solaris provides the flag
-xatomic=[gcc | studio], allowing users to link to one of two atomics
runtime implementations. However, if the user does not provide this
flag, then neither runtime is linked. This led to builds failing in CI.

Closes #9190

m4/curl-functions.m4

index 1459f3d26f0a2b7411e843dafa4acf536f17d846..8d2824740eca12661f76960fce484c67893336c4 100644 (file)
@@ -5905,11 +5905,12 @@ dnl
 AC_DEFUN([CURL_ATOMIC],[
   AC_CHECK_HEADERS(stdatomic.h, [
     AC_MSG_CHECKING([if _Atomic is available])
-    AC_COMPILE_IFELSE([
+    AC_LINK_IFELSE([
       AC_LANG_PROGRAM([[
         $curl_includes_unistd
       ]],[[
         _Atomic int i = 0;
+        i = 4;  // Force an atomic-write operation.
       ]])
     ],[
       AC_MSG_RESULT([yes])