Opened 6 years ago

Closed 6 years ago

#12617 closed Bugs (fixed)

clock_gettime not available on OS X 10.11

Reported by: djh Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

Looks like the Boost.Interprocess check for clock_gettime does not correctly handle OS X 10.11.

(see os_thread_functions.hpp)

Here is a small self-contained test case triggering on OS X 10.11 with xcode8:

$ xcodebuild -version
Xcode 8.1
Build version 8B62
#include <iostream>
#include <boost/interprocess/detail/os_thread_functions.hpp>

int main() {
    boost::interprocess::ipcdetail::get_current_system_highres_count();
    std::clog << "hello" << "\n";
    return 0;
}
$ clang++ -o t t.cpp -Imason_packages/headers/boost/1.61.0/include/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -Wl,-bind_at_load

$ ./t
dyld: Symbol not found: _clock_gettime
  Referenced from: /Users/dane/projects/osrm-backend/./t (which was built for Mac OS X 10.12)
  Expected in: /usr/lib/libSystem.B.dylib
 in /Users/dane/projects/osrm-backend/./t
Trace/BPT trap: 5

Downstream ticket is at: https://github.com/Project-OSRM/osrm-backend/issues/3297#issuecomment-262037848

Seems like is does not trigger on OS X 10.12, though.

Change History (4)

comment:1 by Ion Gaztañaga, 6 years ago

In theory clock_gettime is used if BOOST_INTERPROCESS_CLOCK_MONOTONIC is defined. This is defined if one of the following is defined:

CLOCK_MONOTONIC_PRECISE bsd

CLOCK_MONOTONIC_RAW linux

CLOCK_HIGHRES solaris

Is any of those defined in macos 10.11? In theory the implementation should use a mac-os specific code calling match kernel functions (BOOST_INTERPROCESS_MATCH_ABSOLUTE_TIME should be defined).

Could you please check why BOOST_INTERPROCESS_MATCH_ABSOLUTE_TIME is not defined in mac os 10.11?

comment:2 by Chris Newbold, 6 years ago

It appears that the macOS 10.12 SDK, which is what is used with XCode 8, defines both CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW which then causes Boost.Interprocess to follow the Linux branch and reach for clock_gettime. That works fine when actually running on a 10.12 machine, but 10.11 does not have clock_gettime so you get a busted executable that dies at runtime with an unresolved external.

Unfortunately Apple does not condition the definition of these macros on the deployment target, so even telling XCode 8 that you're targeting 10.11 results in references to clock_gettime.

comment:3 by rjain, 6 years ago

We applied the following patch. So even if CLOCK_MONOTINIC and CLOCK_MONOTONIC_RAW are defined we explicitly include "mach_time.h". Hence no reference to _clock_gettime()

//Xcode 8 fix due to ::clock_gettime issue
#  if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
#     include <mach/mach_time.h>  // mach_absolute_time, mach_timebase_info_data_t
#     define BOOST_INTERPROCESS_MATCH_ABSOLUTE_TIME
#  elif defined(CLOCK_MONOTONIC_PRECISE)   //BSD
#     define BOOST_INTERPROCESS_CLOCK_MONOTONIC CLOCK_MONOTONIC_PRECISE
#  elif defined(CLOCK_MONOTONIC_RAW)     //Linux
#     define BOOST_INTERPROCESS_CLOCK_MONOTONIC CLOCK_MONOTONIC_RAW
#  elif defined(CLOCK_HIGHRES)           //Solaris
#     define BOOST_INTERPROCESS_CLOCK_MONOTONIC CLOCK_HIGHRES
#  elif defined(CLOCK_MONOTONIC)         //POSIX (AIX, BSD, Linux, Solaris)
#     define BOOST_INTERPROCESS_CLOCK_MONOTONIC CLOCK_MONOTONIC

comment:4 by Ion Gaztañaga, 6 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.