Bug 1399746 - Use atexit() to register _PR_Fini on OSX. r=kaie NSPR_4_19_BETA1
authorMike Hommey <mh@glandium.org>
Thu, 22 Feb 2018 13:39:45 +0900
changeset 4780 875fee4c031efeb1af4f48db37669b96a749ac1d
parent 4779 d750caf6e4c65d80189facb3bcd4864ac2e1dc24
child 4781 02c18d2d9ea64e24dfeffdca0f1776cbfbdc3187
push id290
push usermh@glandium.org
push dateThu, 22 Feb 2018 21:25:21 +0000
reviewerskaie
bugs1399746
Bug 1399746 - Use atexit() to register _PR_Fini on OSX. r=kaie
pr/src/pthreads/ptthread.c
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -973,17 +973,33 @@ void _PR_InitThreads(
     PR_ASSERT(0 == rv);
 }  /* _PR_InitThreads */
 
 #ifdef __GNUC__
 /*
  * GCC supports the constructor and destructor attributes as of
  * version 2.5.
  */
+#if defined(DARWIN)
+/*
+ * The dynamic linker on OSX doesn't execute __attribute__((destructor))
+ * destructors in the right order wrt non-__attribute((destructor)) destructors
+ * in other libraries. So use atexit() instead, which does.
+ * See https://bugzilla.mozilla.org/show_bug.cgi?id=1399746#c99
+ */
+static void _PR_Fini(void);
+
+__attribute__ ((constructor))
+static void _register_PR_Fini() {
+  atexit(_PR_Fini);
+}
+#else
 static void _PR_Fini(void) __attribute__ ((destructor));
+#endif
+
 #elif defined(__SUNPRO_C)
 /*
  * Sun Studio compiler
  */
 #pragma fini(_PR_Fini)
 static void _PR_Fini(void);
 #elif defined(HPUX)
 /*