[BUG: 93065] libgomp: destructor missing to delete goacc_cleanup_key
libgomp constructor creates goacc_cleanup_key on dlopen but doesn't delete key 
on dlclose. 
dlopen and dlclose of libgomp.so exhausts pthread keys, which results in 
pthread_key_create failure.

pthread_key_delete needs to be called by libgomp destructor.

Signed-off-by: Ayush Mittal <ayus...@samsung.com>
Signed-off-by: Vaneet Narang <v.nar...@samsung.com>
---
 libgomp/env.c       |  5 ++++-
 libgomp/oacc-init.c | 10 ++++++++++
 libgomp/oacc-int.h  |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libgomp/env.c b/libgomp/env.c
index ac05c3b..be35e5e 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -1303,7 +1303,10 @@ initialize_env (void)
   goacc_runtime_initialize ();
 }
 
-
+static void __attribute__((destructor)) env_destroy(){
+       goacc_runtime_deinitialize();
+}
+
 /* The public OpenMP API routines that access these variables.  */
 
 void
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index 42d005d..9bd0c1a 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -658,6 +658,16 @@ goacc_runtime_initialize (void)
   goacc_host_init ();
 }
 
+attribute_hidden void 
+goacc_runtime_deinitialize() {
+
+#if !(defined HAVE_TLS || defined USE_EMUTLS)
+  pthread_key_delete (goacc_tls_key);
+#endif
+  pthread_key_delete(goacc_cleanup_key);
+
+}
+
 /* Compiler helper functions */
 
 attribute_hidden void
diff --git a/libgomp/oacc-int.h b/libgomp/oacc-int.h
index db0a937..732847a 100644
--- a/libgomp/oacc-int.h
+++ b/libgomp/oacc-int.h
@@ -94,6 +94,7 @@ goacc_thread (void)
 void goacc_register (struct gomp_device_descr *) __GOACC_NOTHROW;
 void goacc_attach_host_thread_to_device (int);
 void goacc_runtime_initialize (void);
+void goacc_runtime_deinitialize (void);
 void goacc_save_and_set_bind (acc_device_t);
 void goacc_restore_bind (void);
 void goacc_lazy_initialize (void);
-- 
1.9.1

Reply via email to