curl-functions.m4: check whether atomics can link rather than just compile

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
This commit is contained in:
Daniel Katz 2022-07-20 20:20:42 -04:00 committed by Daniel Stenberg
parent 6657602f50
commit e7511f853a
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View 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])