Commit ffbc9664 authored by Dan Zimmerman's avatar Dan Zimmerman Committed by Facebook Github Bot

Make clock_gettime weak on darwin

Summary:
We try to detect if you're building for a darwin version where clock_gettime doesn't have a library definition and provide our own if that's the case. However, if you build for an earlier darwin verion but then run on a newer darwin version where clock_gettime does have a definition our symbol still overrides that one, when I think it shouldn't (I'd rather use the library definition whenever possible). This is one of the exact situations why weak linkage exists (I guess at least on darwin since that's the only place I have knowledge), so let's use it here: provide our own definition if a library one doesn't exist, otherwise the strong library definition will override ours.

This creates the following issue now: previous to this diff you would have a unified API (though divergent from the system one on darwin) across all versions of darwin when linking in this library. Now when running on a newer version of darwin the semantics of each clock type may change (in fact I know CLOCK_MONOTONIC diverges). Look for a follow up diff to try and patch up divergence.

Reviewed By: mzlee, Orvid

Differential Revision: D8781475

fbshipit-source-id: e80e9d309115b64563511935ef074c4f46da025b
parent 562675f6
......@@ -97,7 +97,7 @@ static int clock_thread_cputime(struct timespec* ts) {
return 0;
}
int clock_gettime(clockid_t clk_id, struct timespec* ts) {
__attribute__((weak)) int clock_gettime(clockid_t clk_id, struct timespec* ts) {
switch (clk_id) {
case CLOCK_REALTIME: {
auto now = std::chrono::system_clock::now().time_since_epoch();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment