cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: Martin Storsjö <martin_at_martin.st>
Date: Thu, 15 Sep 2016 22:13:53 +0300 (EEST)

On Thu, 15 Sep 2016, Justin Ehlert wrote:

>
>> On Sep 14, 2016, at 3:00 PM, Craig A. Berry <craigberry_at_mac.com> wrote:
>>
>>
>> On Sep 14, 2016, at 01:23 PM, "Peter White (jawhite2)" <jawhite2_at_cisco.com> 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
Received on 2016-09-15