(Wangle) Possibly undefined behavior in collect
[folly.git] / folly / VersionCheck.h
index a15675d7defdf8d3244a5e9c812e6f81c2e301d4..184be3b6da7ddd105c05ea169832395f7c49bded 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  * ... and then commpile your file with -DMYLIB_VERSION=\"1\"
  */
+
+#ifdef __APPLE__
+// OS X doesn't support constructor priorities. Just pray it works, I guess.
+#define FOLLY_VERSION_CHECK_PRIORITY __attribute__((__constructor__))
+#else
+#define FOLLY_VERSION_CHECK_PRIORITY __attribute__((__constructor__(101)))
+#endif
+
 // Note that this is carefully crafted: PRODUCT##Version must have external
 // linkage (so it collides among versions), versionCheck must have internal
 // linkage (so it does NOT collide between versions); if we're trying to have
@@ -75,7 +83,7 @@
 #define FOLLY_VERSION_CHECK(PRODUCT, VERSION) \
   const char* PRODUCT##Version = VERSION; \
   namespace { \
-  __attribute__((constructor(101))) void versionCheck() { \
+  FOLLY_VERSION_CHECK_PRIORITY void versionCheck() { \
     if (strcmp(PRODUCT##Version, VERSION)) { \
       fprintf(stderr, \
               "Invalid %s version: desired [%s], currently loaded [%s]\n", \