RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-20 Thread Daniel Stenberg

On Thu, 20 Oct 2016, Martin Storsjö wrote:

What might need to be adjusted though, is the fact that one also can use 
-mios-version-min instead of -miphoneos-version-min. (And for the other 
newlings, there's also -mtvos-version-min and -mwatchos-version-min.)



What about the attached patch for that?


Seems reasonable, yes. Merged!

--

 / daniel.haxx.se---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-20 Thread Martin Storsjö

On Thu, 20 Oct 2016, Daniel Stenberg wrote:


On Thu, 20 Oct 2016, Martin Storsjö wrote:

So to expand the fix to "just work" in most cases, perhaps we should add 
-miphoneos-version-min=6.0, which should be ancient enough for any current 
usage.


Sound logic, but it seems we need to pick one of them because if we use both 
I get:


clang: error: invalid argument '-mmacosx-version-min=10.5' not allowed with 
'-miphoneos-version-min=6.0'


Hmm, ok. I guess it's better to leave it as is then. If the 
-mmacosx-version-min parameter is set while building with an iOS SDK, you 
get a warning like this:


clang: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX'

So that will at least give another clue to iOS builders that they might 
need to set something if they didn't already.



What might need to be adjusted though, is the fact that one also can use 
-mios-version-min instead of -miphoneos-version-min. (And for the other 
newlings, there's also -mtvos-version-min and -mwatchos-version-min.)


What about the attached patch for that?

// Martin
From d1c163c06b90c62d3ca525324fe255220d7b2c1a Mon Sep 17 00:00:00 2001
From: Martin Storsjo 
Date: Thu, 20 Oct 2016 13:16:10 +0300
Subject: [PATCH] configure: Check for other variants of the -m*os*-version-min
 flags

In addition to -miphoneos-version-min, the same version can be set
using -mios-version-min. And for WatchOS and TvOS, there's
-mwatchos-version-min and -mtvos-version-min.
---
 acinclude.m4 | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index ea97400..95a73e5 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -3203,8 +3203,9 @@ TEST EINVAL TEST
 
 dnl CURL_MAC_CFLAGS
 dnl
-dnl Check if -mmacosx-version-min or -miphoneos-version-min are set manually,
-dnl otherwise do. And set -Werror=partial-availability.
+dnl Check if -mmacosx-version-min, -miphoneos-version-min or any
+dnl similar are set manually, otherwise do. And set
+dnl -Werror=partial-availability.
 dnl
 
 AC_DEFUN([CURL_MAC_CFLAGS], [
@@ -3222,8 +3223,7 @@ AC_DEFUN([CURL_MAC_CFLAGS], [
   if test "$tst_cflags" = "yes"; then
 AC_MSG_CHECKING([for *version-min in CFLAGS])
 min=""
-if test -z "$(echo $CFLAGS | grep mmacosx-version-min)" -a
-   test -z "$(echo $CFLAGS | grep miphoneos-version-min)"; then
+if test -z "$(echo $CFLAGS | grep m.*os.*-version-min)"; then
   min="-mmacosx-version-min=10.5"
   CFLAGS="$CFLAGS $min"
 fi
-- 
2.8.4 (Apple Git-73)

---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-20 Thread Daniel Stenberg

On Thu, 20 Oct 2016, Martin Storsjö wrote:

So to expand the fix to "just work" in most cases, perhaps we should add 
-miphoneos-version-min=6.0, which should be ancient enough for any current 
usage.


Sound logic, but it seems we need to pick one of them because if we use both I 
get:


clang: error: invalid argument '-mmacosx-version-min=10.5' not allowed with 
'-miphoneos-version-min=6.0'


--

 / daniel.haxx.se---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-20 Thread Martin Storsjö

On Thu, 20 Oct 2016, Daniel Stenberg wrote:

I pushed commit 4f8d0b6f02aa just now with this patch, slighlty edited but 
using the same logic.


Great - the commit looks good.

Expanding on this, I'm wondering if we should manually add 
-miphoneos-version-min as well; IIRC the -mmacosx-version-min is ignored 
when actually targeting iOS and vice versa. The original report (as read 
nicely summarized in the github issue you referred to) seemed to be about 
iOS, and I'm not sure if Peter had set any minimum version there either.


So to expand the fix to "just work" in most cases, perhaps we should add 
-miphoneos-version-min=6.0, which should be ancient enough for any current 
usage.


// Martin
---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-20 Thread Daniel Stenberg

On Thu, 20 Oct 2016, Martin Storsjö wrote:

Yes, this seems sensible, and it's good to that it explicitly says what it 
did in the log, leaving a hint for users cross-building for iOS that they 
also might want to set it somehow unless they already do.


Thanks!

I pushed commit 4f8d0b6f02aa just now with this patch, slighlty edited but 
using the same logic.


--

 / daniel.haxx.se---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-20 Thread Martin Storsjö

On Wed, 19 Oct 2016, Daniel Stenberg wrote:


On Wed, 19 Oct 2016, Martin Storsjö wrote:

Anyway, as for a concrete fix, I guess we should look for whether the user 
has specified -mmacosx-version-min or -miphoneos-version-min in some way, 
and if not, add them with a default version. -Werror=partial-availability 
should probably be safe to add in any case.


See attached patch. Thoughts?

I tested this approach on my mac and it works fine for me on a plain build 
without the -mmacosx-version-min or -miphoneos-version-min options set.


You think this approach is decent?


Yes, this seems sensible, and it's good to that it explicitly says what it 
did in the log, leaving a hint for users cross-building for iOS that they 
also might want to set it somehow unless they already do.


If someone already has got a cross setup where they are building for iOS 
it might be good to check whether this correctly notices their 
-miphoneos-version-min (I don't know what all ways people might use to set 
it in the autoconf builds), but it seems correct at least. And if they set 
it in a too creative way which configure doesn't see, they can probably 
change to pass it to configure.


// Martin---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-19 Thread Daniel Stenberg

On Wed, 19 Oct 2016, Martin Storsjö wrote:

Anyway, as for a concrete fix, I guess we should look for whether the user 
has specified -mmacosx-version-min or -miphoneos-version-min in some way, 
and if not, add them with a default version. -Werror=partial-availability 
should probably be safe to add in any case.


See attached patch. Thoughts?

I tested this approach on my mac and it works fine for me on a plain build 
without the -mmacosx-version-min or -miphoneos-version-min options set.


You think this approach is decent?

--

 / daniel.haxx.seFrom 6a63dbeb9d47bd60db28f9c0e839a83ec322fdfb Mon Sep 17 00:00:00 2001
From: Daniel Stenberg 
Date: Wed, 19 Oct 2016 14:36:32 +0200
Subject: [PATCH] configure: set min version flags for builds on mac

---
 acinclude.m4 | 40 +++-
 configure.ac |  2 ++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 312efcb..ed3270f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -3,11 +3,11 @@
 #  Project ___| | | |  _ \| |
 # / __| | | | |_) | |
 #| (__| |_| |  _ <| |___
 # \___|\___/|_| \_\_|
 #
-# Copyright (C) 1998 - 2015, Daniel Stenberg, , et al.
+# Copyright (C) 1998 - 2016, Daniel Stenberg, , et al.
 #
 # This software is licensed as described in the file COPYING, which
 # you should have received as part of this distribution. The terms
 # are also available at https://curl.haxx.se/docs/copyright.html.
 #
@@ -3197,5 +3197,43 @@ TEST EINVAL TEST
   else
 # without -P
 CPPPFLAG=""
   fi
 ])
+
+
+dnl CURL_MAC_CFLAGS
+dnl
+dnl Check if -mmacosx-version-min or -miphoneos-version-min are set manually,
+dnl otherwise do. And set -Werror=partial-availability.
+dnl
+
+AC_DEFUN([CURL_MAC_CFLAGS], [
+
+  tst_cflags="no"
+  case $host_os in
+darwin*)
+  tst_cflags="yes"
+  ;;
+  esac
+
+  AC_MSG_CHECKING([for good-to-use Mac CFLAGS])
+  AC_MSG_RESULT([$tst_cflags]);
+
+  if test "$tst_cflags" = "yes"; then
+AC_MSG_CHECKING([for *version-min in CFLAGS])
+min=""
+if test -z "`echo $CFLAGS | grep mmacosx-version-min`"; then
+  if test -z "`echo $CFLAGS | grep miphoneos-version-min`"; then
+min="-mmacosx-version-min=10.5"
+CFLAGS="$CFLAGS $min"
+  fi
+fi
+if test -z "$min"; then
+  AC_MSG_RESULT([set by user])
+else
+  AC_MSG_RESULT([$min set])
+fi
+CFLAGS="$CFLAGS -Werror=partial-availability"
+  fi
+
+])
diff --git a/configure.ac b/configure.ac
index 0626b38..83cfbff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -355,10 +355,12 @@ case X-"$curl_cv_native_windows" in
 curl_cv_header_winber_h="no"
 ;;
 esac
 CURL_CHECK_WIN32_LARGEFILE
 
+CURL_MAC_CFLAGS
+
 dnl 
 dnl switch off particular protocols
 dnl
 AC_MSG_CHECKING([whether to support http])
 AC_ARG_ENABLE(http,
-- 
2.6.3

---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-19 Thread Martin Storsjö

On Tue, 11 Oct 2016, Daniel Stenberg wrote:


On Fri, 16 Sep 2016, Martin Storsjö wrote:

-Werror=partial-availability is probably safe to add by default (if the 
compiler supports it), since it matches how configure checks are used - if 
a function is available and can be linked, we're free to use it.


But then we also need to make sure the user sets a sensible 
-mmacosx-version-min or -miphoneos-version-min, which hasn't been quite 
necessary so far. Or do OSX users generally set those whenever building 
things?


I would expect that people building curl mostly just use what configure 
generates for them.


Should configure warn if they aren't set - or set a sensible default low 
version if it isn't? Given the number of current and legacy systems that 
one can build it for, picking a sensible default is a bit tricky.


I really can't tell how to do this as I know next to nothing about how 
macOS/iOS versions differ and change between releases.


If nobody else speaks up, make an educated guess that seems to work for you 
and then we move forward and adjust accordingly if people find problems with 
the current set?


I would really appreciate some help on fixing this configure issue. I think 
it would be a pity to keep releasing curl without having this issue sorted 
out. Even if the blame for this is totally not ours.


Well technically, it's probably not ours, but more in the difference 
between how autoconf/configure tests in general check for features, vs the 
fact that xcode is more like a cross compiler with a target SDK which 
might not be the exact same as you're running on (and they only ship the 
latest version, expecting you to use flags like these to select the 
target).



Anyway, as for a concrete fix, I guess we should look for whether the user 
has specified -mmacosx-version-min or -miphoneos-version-min in some way, 
and if not, add them with a default version. -Werror=partial-availability 
should probably be safe to add in any case.


The second question is what to pick for the default; a common 
lowest-possible version, say 10.5 or something such, or should we try to 
detect the version of the running system? The latter is a bit hard if 
targeting iOS, where you can't inspect the intended target system (but in 
those cases, it's probably a much higher probability that the user has set 
this flag already).


I don't think setting the minimum to 10.5 would bother anybody; I don't 
think that people on 10.12 will be bothered by the fact that it doesn't 
use clock_gettime even though it is available on their system, and I'm not 
sure if there's any other system function that has been introduced 
inbetween that would matter (like poll, which is disabled anyway).


// Martin---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-10-16 Thread Daniel Stenberg

On Fri, 16 Sep 2016, Martin Storsjö wrote:

-Werror=partial-availability is probably safe to add by default (if the 
compiler supports it), since it matches how configure checks are used - if a 
function is available and can be linked, we're free to use it.


But then we also need to make sure the user sets a sensible 
-mmacosx-version-min or -miphoneos-version-min, which hasn't been quite 
necessary so far. Or do OSX users generally set those whenever building 
things?


I would expect that people building curl mostly just use what configure 
generates for them.


Should configure warn if they aren't set - or set a sensible default low 
version if it isn't? Given the number of current and legacy systems that one 
can build it for, picking a sensible default is a bit tricky.


I really can't tell how to do this as I know next to nothing about how 
macOS/iOS versions differ and change between releases.


If nobody else speaks up, make an educated guess that seems to work for you 
and then we move forward and adjust accordingly if people find problems with 
the current set?


I would really appreciate some help on fixing this configure issue. I think it 
would be a pity to keep releasing curl without having this issue sorted out. 
Even if the blame for this is totally not ours.


--

 / daniel.haxx.se---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-09-16 Thread Martin Storsjö

On Fri, 16 Sep 2016, Daniel Stenberg wrote:


On Fri, 16 Sep 2016, Peter White (jawhite2) wrote:

Just as a confirmation, this did affect OSX when I tested it, causing a 
crash for the same reason. The partial-availability flag also fixes it for 
OSX.


This sounds like something we should try to automate and incorporate into the 
configure script for the sake of other iOS and macOS users, shouldn't we?


Yes, ideally.

-Werror=partial-availability is probably safe to add by default (if the 
compiler supports it), since it matches how configure checks are used - if 
a function is available and can be linked, we're free to use it.


But then we also need to make sure the user sets a sensible 
-mmacosx-version-min or -miphoneos-version-min, which hasn't been quite 
necessary so far. Or do OSX users generally set those whenever building 
things? Should configure warn if they aren't set - or set a sensible 
default low version if it isn't? Given the number of current and legacy 
systems that one can build it for, picking a sensible default is a bit 
tricky.


// Martin - one of the videolan funny hat guys from last Friday :P

---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-09-16 Thread Daniel Stenberg

On Fri, 16 Sep 2016, Peter White (jawhite2) wrote:

Just as a confirmation, this did affect OSX when I tested it, causing a 
crash for the same reason. The partial-availability flag also fixes it for 
OSX.


This sounds like something we should try to automate and incorporate into the 
configure script for the sake of other iOS and macOS users, shouldn't we?


--

 / daniel.haxx.se
---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

RE: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-09-16 Thread Peter White (jawhite2)
>There's actually one other thing you can do - I haven't tested it with curl's 
>configure script, but I did test it with libav's (non-autoconf
>based) configure script today:
>
>In addition to the -miphoneos-version-min or -mmacosx-version-min option, add 
>-Werror=partial-availability. This makes it an error to refer to symbols that 
>don't exist in the baseline platform version chosen, which should hopefully be 
>enough for the configure test to fail, to make it not use this function.
>
>// Martin

Thanks Martin. That flag did indeed fail the clock_gettime configure test, and 
much better than my workaound for setting "curl_func_clock_gettime" to no!

Just as a confirmation, this did affect OSX when I tested it, causing a crash 
for the same reason. The partial-availability flag also fixes it for OSX.

Thanks to all for your help,
Peter

---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

Re: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-09-15 Thread Martin Storsjö

On Thu, 15 Sep 2016, Justin Ehlert wrote:




On Sep 14, 2016, at 3:00 PM, Craig A. Berry  wrote:


On Sep 14, 2016, at 01:23 PM, "Peter White (jawhite2)"  
wrote:


Hi there,

On macOS Sierra (v10.12) and iOS 10, the function clock_gettime has been 
introduced in the Darwin kernel. When building libcurl on macOS 10.12 with 
Xcode 8 and iOS10 SDK, the configure script will return yes for “monotonic 
clock_gettime” (around Line 20434 of configure).

However, when using libcurl in an application on an earlier version of iOS, 
this will cause a run time crash due to a missing symbol for clock_gettime.

No crash occurs on an iPhone 6 running iOS10, but on an iPad running iOS9.3.5, 
a crash occurs due to a missing symbol for clock_gettime.

OS: macOS Sierra (v10.12). Darwin kernel version 16.0.0
Libcurl version build: v7.49.1
Building libcurl for iOS 9.0 with Xcode 8 GM seed.

Configure output with Xcode 8 (on macOS 10.12)
==
configure:20433: checking for monotonic clock_gettime
configure:20466: 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
 -c -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/
 -miphoneos-version-min=9.0 -arch armv7 -mthumb -DNDEBUG -isystem 
/Volumes/local/JenkinsSlave/trunk/dependencies/openssl/include -Qunused-arguments -Os  
conftest.c >&5
configure:20466: $? = 0
configure:20468: result: yes
==


Since you are specifying  -miphoneos-version-min=9.0 it really shouldn't be 
able to see functions that don't exist on that version.  Check time.h and see 
if Apple forgot to put a version check around the prototype for clock_gettime().



Configure output with Xcode 7 (on OSX 10.11)
==
configure:20466: 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
 -c -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/
 -miphoneos-version-min=9.0 -arch armv7 -mthumb -isystem 
/Volumes/local/JenkinsSlave/trunk/dependencies/openssl/include -Qunused-arguments -Os  
conftest.c >&5
conftest.c:72:15: warning: implicit declaration of function 'clock_gettime' is 
invalid in C99 [-Wimplicit-function-declaration]
(void)clock_gettime(CLOCK_MONOTONIC, &ts);
  ^
conftest.c:72:29: error: use of undeclared identifier 'CLOCK_MONOTONIC'
(void)clock_gettime(CLOCK_MONOTONIC, &ts);
^
1 warning and 1 error generated.
configure:20466: $? = 1
=

I changed “curl_func_clock_gettime” to “no” in configure as a quick workaround 
and the libcurl binary didn’t cause any issues in either iOS9 or iOS10.

Although not tested yet, I believe the same issue would occur when building 
libcurl on macOS 10.12 and using that binary on OSX 10.11 or lower.

Best,
Peter
---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html

---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html


This is actually fairly nasty (and does affect OSX as well as iOS)

Apple did in fact declare the function with the appropriate availability, 
however they did so in a weakly linked manner. This means that even if you 
specify -miphoneos-version-min=9.0 or -mmacosx-version-min=10.11, clock_gettime 
will still be declared at compile time. The only point that you can know if the 
function is available is by checking if clock_gettime == null at runtime.

See: 
https://opensource.apple.com/source/xnu/xnu-3247.1.106/EXTERNAL_HEADERS/Availability.h
And: http://clang.llvm.org/docs/AttributeReference.html#availability


There's actually one other thing you can do - I haven't tested it with 
curl's configure script, but I did test it with libav's (non-autoconf 
based) configure script today:


In addition to the -miphoneos-version-min or -mmacosx-version-min option, 
add -Werror=partial-availability. This makes it an error to refer to 
symbols that don't exist in the baseline platform version chosen, which 
should hopefully be enough for the configure test to fail, to make it not 
use this function.


// Martin---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

Re: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-09-15 Thread Justin Ehlert

> On Sep 14, 2016, at 3:00 PM, Craig A. Berry  wrote:
> 
> 
> On Sep 14, 2016, at 01:23 PM, "Peter White (jawhite2)"  
> wrote:
> 
>> Hi there,
>> 
>> On macOS Sierra (v10.12) and iOS 10, the function clock_gettime has been 
>> introduced in the Darwin kernel. When building libcurl on macOS 10.12 with 
>> Xcode 8 and iOS10 SDK, the configure script will return yes for “monotonic 
>> clock_gettime” (around Line 20434 of configure).
>> 
>> However, when using libcurl in an application on an earlier version of iOS, 
>> this will cause a run time crash due to a missing symbol for clock_gettime.
>> 
>> No crash occurs on an iPhone 6 running iOS10, but on an iPad running 
>> iOS9.3.5, a crash occurs due to a missing symbol for clock_gettime.
>> 
>> OS: macOS Sierra (v10.12). Darwin kernel version 16.0.0
>> Libcurl version build: v7.49.1
>> Building libcurl for iOS 9.0 with Xcode 8 GM seed.
>> 
>> Configure output with Xcode 8 (on macOS 10.12)
>> ==
>> configure:20433: checking for monotonic clock_gettime
>> configure:20466: 
>> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
>>  -c -isysroot 
>> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/
>>  -miphoneos-version-min=9.0 -arch armv7 -mthumb -DNDEBUG -isystem 
>> /Volumes/local/JenkinsSlave/trunk/dependencies/openssl/include 
>> -Qunused-arguments -Os  conftest.c >&5
>> configure:20466: $? = 0
>> configure:20468: result: yes
>> ==
> 
> Since you are specifying  -miphoneos-version-min=9.0 it really shouldn't be 
> able to see functions that don't exist on that version.  Check time.h and see 
> if Apple forgot to put a version check around the prototype for 
> clock_gettime().
> 
>> 
>> Configure output with Xcode 7 (on OSX 10.11)
>> ==
>> configure:20466: 
>> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
>>  -c -isysroot 
>> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/
>>  -miphoneos-version-min=9.0 -arch armv7 -mthumb -isystem 
>> /Volumes/local/JenkinsSlave/trunk/dependencies/openssl/include 
>> -Qunused-arguments -Os  conftest.c >&5
>> conftest.c:72:15: warning: implicit declaration of function 'clock_gettime' 
>> is invalid in C99 [-Wimplicit-function-declaration]
>> (void)clock_gettime(CLOCK_MONOTONIC, &ts);
>>   ^
>> conftest.c:72:29: error: use of undeclared identifier 'CLOCK_MONOTONIC'
>> (void)clock_gettime(CLOCK_MONOTONIC, &ts);
>> ^
>> 1 warning and 1 error generated.
>> configure:20466: $? = 1
>> =
>> 
>> I changed “curl_func_clock_gettime” to “no” in configure as a quick 
>> workaround and the libcurl binary didn’t cause any issues in either iOS9 or 
>> iOS10.
>> 
>> Although not tested yet, I believe the same issue would occur when building 
>> libcurl on macOS 10.12 and using that binary on OSX 10.11 or lower.
>> 
>> Best,
>> Peter
>> ---
>> List admin: https://cool.haxx.se/list/listinfo/curl-library
>> Etiquette: https://curl.haxx.se/mail/etiquette.html
> ---
> List admin: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette:  https://curl.haxx.se/mail/etiquette.html

This is actually fairly nasty (and does affect OSX as well as iOS)

Apple did in fact declare the function with the appropriate availability, 
however they did so in a weakly linked manner. This means that even if you 
specify -miphoneos-version-min=9.0 or -mmacosx-version-min=10.11, clock_gettime 
will still be declared at compile time. The only point that you can know if the 
function is available is by checking if clock_gettime == null at runtime.

See: 
https://opensource.apple.com/source/xnu/xnu-3247.1.106/EXTERNAL_HEADERS/Availability.h
And: http://clang.llvm.org/docs/AttributeReference.html#availability



signature.asc
Description: Message signed with OpenPGP using GPGMail
---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

Re: macOS10.12/Xcode8 introduces run-time crash when building libcurl for earlier iOS versions

2016-09-14 Thread Craig A. Berry


On Sep 14, 2016, at 01:23 PM, "Peter White (jawhite2)"  
wrote:



Hi there,

 

On macOS Sierra (v10.12) and iOS 10, the function clock_gettime has been 
introduced in the Darwin kernel. When building libcurl on macOS 10.12 with 
Xcode 8 and iOS10 SDK, the configure script will return yes for “monotonic 
clock_gettime” (around Line 20434 of configure).

 

However, when using libcurl in an application on an earlier version of iOS, 
this will cause a run time crash due to a missing symbol for clock_gettime.

 

No crash occurs on an iPhone 6 running iOS10, but on an iPad running iOS9.3.5, 
a crash occurs due to a missing symbol for clock_gettime.

 

OS: macOS Sierra (v10.12). Darwin kernel version 16.0.0

Libcurl version build: v7.49.1

Building libcurl for iOS 9.0 with Xcode 8 GM seed.

 

Configure output with Xcode 8 (on macOS 10.12)

==

configure:20433: checking for monotonic clock_gettime

configure:20466: 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
 -c -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/
 -miphoneos-version-min=9.0 -arch armv7 -mthumb -DNDEBUG -isystem 
/Volumes/local/JenkinsSlave/trunk/dependencies/openssl/include -Qunused-arguments -Os  
conftest.c >&5

configure:20466: $? = 0

configure:20468: result: yes

==



Since you are specifying  -miphoneos-version-min=9.0 it really shouldn't be 
able to see functions that don't exist on that version.  Check time.h and see 
if Apple forgot to put a version check around the prototype for clock_gettime().



 

Configure output with Xcode 7 (on OSX 10.11)

==

configure:20466: 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
 -c -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/
 -miphoneos-version-min=9.0 -arch armv7 -mthumb -isystem 
/Volumes/local/JenkinsSlave/trunk/dependencies/openssl/include -Qunused-arguments -Os  
conftest.c >&5

conftest.c:72:15: warning: implicit declaration of function 'clock_gettime' is 
invalid in C99 [-Wimplicit-function-declaration]

    (void)clock_gettime(CLOCK_MONOTONIC, &ts);

  ^

conftest.c:72:29: error: use of undeclared identifier 'CLOCK_MONOTONIC'

    (void)clock_gettime(CLOCK_MONOTONIC, &ts);

    ^

1 warning and 1 error generated.

configure:20466: $? = 1

=

 

I changed “curl_func_clock_gettime” to “no” in configure as a quick workaround 
and the libcurl binary didn’t cause any issues in either iOS9 or iOS10.

 

Although not tested yet, I believe the same issue would occur when building 
libcurl on macOS 10.12 and using that binary on OSX 10.11 or lower.

 

Best,

Peter

---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
---
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html