From 7c4ee7ec3514dc2a8c40981b6d19a069e3b3bf58 Mon Sep 17 00:00:00 2001
From: Alexandre Janniaux <ajanni@videolabs.io>
Date: Wed, 9 Jun 2021 15:56:01 +0200
Subject: [PATCH] securetransport: use __builtin_available tagging

The SSL*ALPNProtocols were introduced in recent OS version, and dynamic
lookup (using ld64 option -Wl,-U) was used to make it work during
link-time and potentially not have the function available.

However, -Wl,-U is not compatible with bitcode support, whereas
availability targeting is, and availability targeting provides more
information about when it's not supported.

MacOSX 10.13.4 is the minimal version target in cURL too. The
SSL*ALPNProtocols functions are documented as supported since 10.13 but
they were not included in the initial 10.13 releases.
---
 modules/misc/securetransport.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/modules/misc/securetransport.c b/modules/misc/securetransport.c
index 228b8129b7ae..e4bb5cb9cbce 100644
--- a/modules/misc/securetransport.c
+++ b/modules/misc/securetransport.c
@@ -441,12 +441,11 @@ static int st_Handshake (vlc_tls_t *session,
     (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED  >= 110000) || \
     (TARGET_OS_TV     && __TV_OS_VERSION_MAX_ALLOWED      >= 110000) || \
     (TARGET_OS_WATCH  && __WATCH_OS_VERSION_MAX_ALLOWED   >= 40000)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
 
     /* Handle ALPN data */
     if (alp != NULL) {
-        if (SSLCopyALPNProtocols != NULL) {
+        if (__builtin_available(iOS 11, macOS 10.13.4, tvOS 11, watchOS 4, *))
+        {
             CFArrayRef alpnArray = NULL;
             OSStatus res = SSLCopyALPNProtocols(sys->p_context, &alpnArray);
             if (res == noErr && alpnArray) {
@@ -462,7 +461,6 @@ static int st_Handshake (vlc_tls_t *session,
         }
     }
 
-#pragma clang diagnostic pop
 #else
 
     /* No ALPN support */
@@ -745,12 +743,11 @@ static vlc_tls_t *st_ClientSessionOpen(vlc_tls_client_t *crd, vlc_tls_t *sock,
     (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED  >= 110000) || \
     (TARGET_OS_TV     && __TV_OS_VERSION_MAX_ALLOWED      >= 110000) || \
     (TARGET_OS_WATCH  && __WATCH_OS_VERSION_MAX_ALLOWED   >= 40000)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
 
     /* Handle ALPN */
     if (alpn != NULL) {
-        if (SSLSetALPNProtocols != NULL) {
+        if (__builtin_available(iOS 11, macOS 10.13.4, tvOS 11, watchOS 4, *))
+        {
             CFMutableArrayRef alpnValues = alpnToCFArray(alpn);
 
             if (alpnValues == NULL) {
@@ -768,7 +765,6 @@ static vlc_tls_t *st_ClientSessionOpen(vlc_tls_client_t *crd, vlc_tls_t *sock,
         }
     }
 
-#pragma clang diagnostic pop
 #else
 
     /* No ALPN support */
-- 
GitLab