Skip to content

Commit 870d849

Browse files
authored
configure: check for __builtin_available() availability (#1788)
This change does two things: 1. It un-breaks the build in Xcode 9.0. (Xcode 9.0 is currently failing trying to compile connectx() in lib/connect.c.) 2. It finally weak-links the connectx() function, and falls back on connect() when run on older operating systems.
1 parent ca9630f commit 870d849

3 files changed

Lines changed: 46 additions & 10 deletions

File tree

acinclude.m4

100644100755
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,3 +3243,29 @@ AC_DEFUN([CURL_MAC_CFLAGS], [
32433243
fi
32443244
32453245
])
3246+
3247+
3248+
dnl CURL_SUPPORTS_BUILTIN_AVAILABLE
3249+
dnl
3250+
dnl Check to see if the compiler supports __builtin_available. This built-in
3251+
dnl compiler function first appeared in Apple LLVM 9.0.0. It's so new that, at
3252+
dnl the time this macro was written, the function was not yet documented. Its
3253+
dnl purpose is to return true if the code is running under a certain OS version
3254+
dnl or later.
3255+
3256+
AC_DEFUN([CURL_SUPPORTS_BUILTIN_AVAILABLE], [
3257+
AC_MSG_CHECKING([to see if the compiler supports __builtin_available()])
3258+
AC_COMPILE_IFELSE([
3259+
AC_LANG_PROGRAM([[
3260+
#include <stdlib.h>
3261+
]],[[
3262+
if (__builtin_available(macOS 10.8, iOS 5.0, *)) {}
3263+
]])
3264+
],[
3265+
AC_MSG_RESULT([yes])
3266+
AC_DEFINE_UNQUOTED(HAVE_BUILTIN_AVAILABLE, 1,
3267+
[Define to 1 if you have the __builtin_available function.])
3268+
],[
3269+
AC_MSG_RESULT([no])
3270+
])
3271+
])

configure.ac

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ esac
354354
CURL_CHECK_WIN32_LARGEFILE
355355

356356
CURL_MAC_CFLAGS
357+
CURL_SUPPORTS_BUILTIN_AVAILABLE
357358

358359
dnl ************************************************************
359360
dnl switch off particular protocols

lib/connect.c

100644100755
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,16 +1059,25 @@ static CURLcode singleipconnect(struct connectdata *conn,
10591059
if(!isconnected && (conn->socktype == SOCK_STREAM)) {
10601060
if(conn->bits.tcp_fastopen) {
10611061
#if defined(CONNECT_DATA_IDEMPOTENT) /* OS X */
1062-
sa_endpoints_t endpoints;
1063-
endpoints.sae_srcif = 0;
1064-
endpoints.sae_srcaddr = NULL;
1065-
endpoints.sae_srcaddrlen = 0;
1066-
endpoints.sae_dstaddr = &addr.sa_addr;
1067-
endpoints.sae_dstaddrlen = addr.addrlen;
1068-
1069-
rc = connectx(sockfd, &endpoints, SAE_ASSOCID_ANY,
1070-
CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT,
1071-
NULL, 0, NULL, NULL);
1062+
#ifdef HAVE_BUILTIN_AVAILABLE
1063+
if(__builtin_available(macOS 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *)) {
1064+
#endif /* HAVE_BUILTIN_AVAILABLE */
1065+
sa_endpoints_t endpoints;
1066+
endpoints.sae_srcif = 0;
1067+
endpoints.sae_srcaddr = NULL;
1068+
endpoints.sae_srcaddrlen = 0;
1069+
endpoints.sae_dstaddr = &addr.sa_addr;
1070+
endpoints.sae_dstaddrlen = addr.addrlen;
1071+
1072+
rc = connectx(sockfd, &endpoints, SAE_ASSOCID_ANY,
1073+
CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT,
1074+
NULL, 0, NULL, NULL);
1075+
#ifdef HAVE_BUILTIN_AVAILABLE
1076+
}
1077+
else {
1078+
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
1079+
}
1080+
#endif /* HAVE_BUILTIN_AVAILABLE */
10721081
#elif defined(MSG_FASTOPEN) /* Linux */
10731082
if(conn->given->flags & PROTOPT_SSL)
10741083
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);

0 commit comments

Comments
 (0)