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

Tavian Barnes via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 18:52:36 PDT 2016


tavianator added inline comments.

================
Comment at: src/cxa_thread_atexit.cpp:36-47
@@ +35,14 @@
+  public:
+    DtorListHolder() {
+      pthread_key_create(&key_, run_dtors);
+    }
+
+    ~DtorListHolder() {
+      run_dtors(get());
+      pthread_key_delete(key_);
+    }
+
+    DtorList* get() {
+      return static_cast<DtorList*>(pthread_getspecific(key_));
+    }
+
----------------
majnemer wrote:
> What happens if `pthread_key_create` fails?
Nothing good!  I'll add the necessary error handling.

================
Comment at: src/cxa_thread_atexit.cpp:61-67
@@ -18,6 +60,9 @@
+_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__));
 
-#endif // HAVE__CXA_THREAD_ATEXIT_IMPL
+  if (__cxa_thread_atexit_impl) {
+    return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
+  } else {
+    static DtorListHolder dtors;
----------------
majnemer wrote:
> Is there a reason to use the weak symbol on non-Android platforms?
Just simplicity.  (There are some fringe benefits, like the ability to build against pre-2.18 glibc but have it detect ..._impl() support when run with newer libraries.  Or magically supporting musl etc. if they add it, without having to recompile.)

Would you rather keep the build-time checks for non-Android platforms?


http://reviews.llvm.org/D21803





More information about the cfe-commits mailing list