[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: Vaneet Narang <v.nar...@samsung.com>
Signed-off-by: Ayush Mittal <ayus...@samsung.com>
---
[v1 patch] https://gcc.gnu.org/ml/gcc-bugs/2019-12/msg02132.html
[v1] -> [v2]
* Adding ChangeLog entry.
* Instead of adding a destructor function in one file and then calling 
goacc_runtime_deinitialize function in another file,
  making goacc_runtime_deinitialize as desctrutor function.
* Making goacc_runtime_deinitialize as static function so no entry
  needed in header file.
* Not removing extra form feed character alredy present.

 ChangeLog           | 4 ++++
 libgomp/oacc-init.c | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index f64cf381655..24778a27f9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-12-30  Ayush Mittal  <ayus...@samsung.com>
+
+       * libgomp: Add destructor to delete runtime env keys
+
 2019-12-20  Jerome Lambourg  <lambo...@adacore.com>
 
        * MAINTAINERS (write_after_approval): Add myself.
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index 487a2cca61f..6aa5fd297d6 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -858,6 +858,15 @@ goacc_runtime_initialize (void)
   goacc_host_init ();
 }
 
+static void __attribute__((destructor))
+goacc_runtime_deinitialize (void)
+{
+#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
-- 
2.17.1

Reply via email to