[PATCH] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 29 10:59:23 PDT 2016


majnemer added inline comments.

================
Comment at: src/cxa_thread_atexit.cpp:64-90
@@ -18,8 +63,29 @@
+_LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void *obj,
                                             void *dso_symbol) throw() {
-  extern int __cxa_thread_atexit_impl(void (*)(void *), void *, void *);
-  return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
-}
+  extern int __cxa_thread_atexit_impl(Dtor, void *, void *)
+    __attribute__((__weak__));
+
+  if (__cxa_thread_atexit_impl) {
+    return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
+  } else {
+    static DtorListHolder dtors;
+
+    auto head = static_cast<DtorList*>(std::malloc(sizeof(DtorList)));
+    if (!head) {
+      return -1;
+    }
+
+    head->dtor = dtor;
+    head->obj = obj;
+    head->next = dtors.get();
+
+    if (!dtors.set(head)) {
+      std::free(head);
+      return -1;
+    }
 
-#endif // HAVE__CXA_THREAD_ATEXIT_IMPL
+    return 0;
+  }
+}
 
 } // extern "C"
----------------
I think that this should be an opt-in mechanism, there are platforms that presumably never need to pay the cost of the unused code (macOS comes to mind).


http://reviews.llvm.org/D21803





More information about the cfe-commits mailing list