Skip to content
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

7.5.0 clock_gettime runtime failure built with macOS 10.11 and Xcode 8.x #11104

Closed
ilovezfs opened this issue Feb 1, 2017 · 5 comments
Closed
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. macos Issues and PRs related to the macOS platform / OSX.

Comments

@ilovezfs
Copy link

ilovezfs commented Feb 1, 2017

Full build log is here: https://gist.githubusercontent.com/ilovezfs/10f5a75cd9b9603813b51bfcfe51c025/raw/eb61b577e16b9aa1951a8ac6fe24979d73611702/gistfile1.txt

I encountered this problem while working on the 7.5.0 upgrade from Homebrew.

==> ./configure --prefix=/usr/local/Cellar/node/7.5.0/libexec/npm
==> make install
node cli.js install -g -f 
dyld: lazy symbol binding failed: Symbol not found: _clock_gettime
  Referenced from: /usr/local/Cellar/node/7.5.0/bin/node
  Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: _clock_gettime
  Referenced from: /usr/local/Cellar/node/7.5.0/bin/node
  Expected in: /usr/lib/libSystem.B.dylib

This will occur if node is built on macOS 10.11 El Capitan either without the Command Line Tools (CLT) installed, or with SDKROOT set to the Xcode.app (8.x) SDK (SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk), or both.

The problem is that the use of clock_gettime in node is only guarded with # ifdef CLOCK_REALTIME, and CLOCK_REALTIME is defined in the Xcode 8 SDK regardless of whether you happen to be building on macOS 10.11 El Capitan or macOS 10.12 Sierra.

I am currently using the following patch on El Capitan to work around the bug: https://gist.github.com/ilovezfs/7f72153c2c870a35877b91a2b16c1235

diff --git a/deps/openssl/openssl/apps/apps.c b/deps/openssl/openssl/apps/apps.c
index c487bd9..9456e47 100644
--- a/deps/openssl/openssl/apps/apps.c
+++ b/deps/openssl/openssl/apps/apps.c
@@ -150,6 +150,10 @@ static int WIN32_rename(const char *from, const char *to);
 # define rename(from,to) WIN32_rename((from),(to))
 #endif
 
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#endif
+
 typedef struct {
     const char *name;
     unsigned long flag;
@@ -3041,7 +3045,7 @@ double app_tminterval(int stop, int usertime)
 double app_tminterval(int stop, int usertime)
 {
     double ret = 0;
-# ifdef CLOCK_REALTIME
+# if (defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (!defined(__APPLE__) && defined(CLOCK_REALTIME))
     static struct timespec tmstart;
     struct timespec now;
 # else
@@ -3055,7 +3059,13 @@ double app_tminterval(int stop, int usertime)
                    "this program on idle system.\n");
         warning = 0;
     }
-# ifdef CLOCK_REALTIME
+# if (defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (!defined(__APPLE__) && defined(CLOCK_REALTIME))
+    clock_gettime(CLOCK_REALTIME, &now);
+    if (stop == TM_START)
+        tmstart = now;
+    else
+        ret = ((now.tv_sec + now.tv_nsec * 1e-9)
+               - (tmstart.tv_sec + tmstart.tv_nsec * 1e-9));
     clock_gettime(CLOCK_REALTIME, &now);
     if (stop == TM_START)
         tmstart = now;
diff --git a/deps/uv/src/unix/darwin.c b/deps/uv/src/unix/darwin.c
index b1ffbc3..23e91db 100644
--- a/deps/uv/src/unix/darwin.c
+++ b/deps/uv/src/unix/darwin.c
@@ -36,6 +36,7 @@
 #include <sys/sysctl.h>
 #include <time.h>
 #include <unistd.h>  /* sysconf */
+#include <AvailabilityMacros.h>
 
 #undef NANOSEC
 #define NANOSEC ((uint64_t) 1e9)
@@ -57,7 +58,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) {
 
 
 uint64_t uv__hrtime(uv_clocktype_t type) {
-#ifdef MAC_OS_X_VERSION_10_12
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
   struct timespec ts;
   clock_gettime(CLOCK_MONOTONIC, &ts);
   return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);

However, in its current form, it will cause clock_gettime not to be used even if building on macOS 10.12 Sierra. The reason is that node specifically sets 'MACOSX_DEPLOYMENT_TARGET': '10.7', # -mmacosx-version-min=10.7 in common.gypi which will therefore cause MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 to be false.

Obviously one way to make the patch viable would be to set the "correct" MACOSX_DEPLOYMENT_TARGET, namely MACOSX_DEPLOYMENT_TARGET=10.12 when building on Sierra, if the Sierra-only functions are desired. But if MACOSX_DEPLOYMENT_TARGET will continue to be set to 10.7, and yet you also want to enable clock_gettime, then some other strategy besides using MAC_OS_X_VERSION_MIN_REQUIRED at build time will be required. Another approach would be to use weak linking, which defers the decision until run time whether or not to use the symbol.

If you want to avoid using MAC_OS_X_VERSION_MIN_REQUIRED and want to avoid using weak linking, then a configure-time solution will be needed, which not only attempts to compile a sample program using clock_gettime, but also checks whether it executes. The latter is sometimes a show stopper because it can interfere with cross-compiling.

@Fishrock123 Fishrock123 added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Feb 1, 2017
@ilovezfs
Copy link
Author

ilovezfs commented Feb 1, 2017

@Fishrock123 note the patch above also touches the vendored openssl, not just libuv.

@joyeecheung
Copy link
Member

It's going to be fixed by #11094

@ilovezfs
Copy link
Author

ilovezfs commented Feb 1, 2017

@joyeecheung excellent

@mscdex mscdex added the macos Issues and PRs related to the macOS platform / OSX. label Feb 1, 2017
@cjihrig cjihrig closed this as completed in 8514269 Feb 9, 2017
@ilovezfs
Copy link
Author

Were the issues in deps/openssl/openssl/apps/apps.c addressed too?

@joyeecheung
Copy link
Member

I've bumped into the same failure in lazy symbol binding before (caused by the reverted uv patch), it probably happened before the openssl part so never noticed it. The latest master works fine for me.

italoacasas pushed a commit that referenced this issue Feb 13, 2017
Fixes: #10165
Fixes: #9856
Fixes: #10607
Fixes: #11104
PR-URL: #11094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
italoacasas pushed a commit to italoacasas/node that referenced this issue Feb 14, 2017
Fixes: nodejs#10165
Fixes: nodejs#9856
Fixes: nodejs#10607
Fixes: nodejs#11104
PR-URL: nodejs#11094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
krydos pushed a commit to krydos/node that referenced this issue Feb 25, 2017
Fixes: nodejs#10165
Fixes: nodejs#9856
Fixes: nodejs#10607
Fixes: nodejs#11104
PR-URL: nodejs#11094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
MylesBorins pushed a commit that referenced this issue May 18, 2017
Fixes: #10165
Fixes: #9856
Fixes: #10607
Fixes: #11104
PR-URL: #11094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
MylesBorins pushed a commit that referenced this issue May 18, 2017
Fixes: #10165
Fixes: #9856
Fixes: #10607
Fixes: #11104
PR-URL: #11094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
MylesBorins pushed a commit that referenced this issue May 18, 2017
Fixes: #10165
Fixes: #9856
Fixes: #10607
Fixes: #11104
PR-URL: #11094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
andrew749 pushed a commit to michielbaird/node that referenced this issue Jul 19, 2017
Fixes: nodejs/node#10165
Fixes: nodejs/node#9856
Fixes: nodejs/node#10607
Fixes: nodejs/node#11104
PR-URL: nodejs/node#11094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. macos Issues and PRs related to the macOS platform / OSX.
Projects
None yet
Development

No branches or pull requests

4 participants