[compiler-rt] r342608 - [builtins] Add __emutls_unregister_key function

Yi Kong via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 19 18:02:14 PDT 2018


Author: kongyi
Date: Wed Sep 19 18:02:13 2018
New Revision: 342608

URL: http://llvm.org/viewvc/llvm-project?rev=342608&view=rev
Log:
[builtins] Add __emutls_unregister_key function

This is called by Bionic on dlclose to delete the emutls pthread key.

The return value of pthread_key_delete is unchecked and behaviour of
multiple calls to the method is dependent on the implementation of
pthread_key_delete.

Differential Revision: https://reviews.llvm.org/D52251

Modified:
    compiler-rt/trunk/lib/builtins/emutls.c

Modified: compiler-rt/trunk/lib/builtins/emutls.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/emutls.c?rev=342608&r1=342607&r2=342608&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/emutls.c (original)
+++ compiler-rt/trunk/lib/builtins/emutls.c Wed Sep 19 18:02:13 2018
@@ -42,6 +42,7 @@ static void emutls_shutdown(emutls_addre
 
 static pthread_mutex_t emutls_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_key_t emutls_pthread_key;
+static bool emutls_key_created = false;
 
 typedef unsigned int gcc_word __attribute__((mode(word)));
 typedef unsigned int gcc_pointer __attribute__((mode(pointer)));
@@ -109,6 +110,7 @@ static void emutls_key_destructor(void*
 static __inline void emutls_init(void) {
     if (pthread_key_create(&emutls_pthread_key, emutls_key_destructor) != 0)
         abort();
+    emutls_key_created = true;
 }
 
 static __inline void emutls_init_once(void) {
@@ -390,3 +392,14 @@ void* __emutls_get_address(__emutls_cont
         array->data[index] = emutls_allocate_object(control);
     return array->data[index];
 }
+
+#ifdef __BIONIC__
+/* Called by Bionic on dlclose to delete the emutls pthread key. */
+__attribute__((visibility("hidden")))
+void __emutls_unregister_key(void) {
+    if (emutls_key_created) {
+        pthread_key_delete(emutls_pthread_key);
+        emutls_key_created = false;
+    }
+}
+#endif




More information about the llvm-commits mailing list