-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix usage of unavailable weak symbol clock_gettime() on Apple platform. #3048
Conversation
Commited change from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like this. Is there any reason why we can't use traditional weak-linking here instead of __builtin_available()? __builtin_available() won't work with compilers other than LLVM.
If we can't use traditional weak-linking, then why don't we use the HAVE_BUILTIN_AVAILABLE preprocessor macro instead of making a new one?
If you mean by weak-linking the
Proposed changes do not affect GCC users in any sense, so there is no limitation, code compiles and works successfully. If GCC user defines But the main problem with GCC on Apple platform - it is depreciated by Apple and thus it does not make sense to try to use GCC + recent Apple SDK based on LLVM/Clang to compile binaries for production. I do not think anybody will do that. And older Apple SDK, which is using/compatible with GCC. does not have To avoid confusion with public defines of |
…es of HAVE_XXX style
But since the variable is always updated by the if(), why does it need to be static? Surely removing static from it will keep it working just as good and just remove potential problems? |
make variable local, simplified __builtin_available detection with already existing HAVE_BUILTIN_AVAILABLE define
@bagder, agree that variable may be local. Also replaced check for I used #define HAVE_BUILTIN_AVAILABLE 0 |
limit clock_gettime check to only Apple OS because LLVM/Clang defines __builtin_available() on other platforms too (for example Android, NDK r17b)
It appears that |
I suppose this is fine then. By "traditional" weak linking, I meant the way it was done prior to __builtin_available(), which was to check at run-time if the symbol was defined or not. The darwinssl.c code still does this for backward compatibility with older compilers, and it hasn't caused any problems. But using __builtin_available() will solve this for the vast majority of users. |
Thanks! |
Latest Apple SDK declares clock_gettime() and it is available during compile time but it may not always be available during run time - weak symbol. E.g. code compiles but later will crash if clock_gettime() is used on unsupported version of Apple OS.
clock_gettime() is supported since these OS versions: macOS 10.12, iOS 10, tvOS 10, watchOS 3.
This fix uses __builtin_available() Clang's extension which tests OS version and does not allow to use clock_gettime() on unsupported OS version.
There is only small overhead on Apple OS due to have_clock_gettime variable check but it makes binary portable (clock_gettime() will not be used on unsupported OS version) and ready for usage of high-resolution monotonic clock on Apple OS (clock_gettime() will be used on supported OS version).
Other platforms are unaffected by this implementation due to HAVE_CLOCK_GETTIME_CHECK define used in place.