[PATCH 3/4] Factor out _dl_clear_dtv

Paul Pluzhnikov ppluzhnikov@google.com
Thu Dec 19 01:14:00 GMT 2013


On Wed, Dec 11, 2013 at 2:04 AM, Ondřej Bílka <neleai@seznam.cz> wrote:

> On Tue, Dec 10, 2013 at 04:35:42PM -0800, Andrew Hunter wrote:
>> This is patch 3/4 of the effort to make TLS access async-signal-safe.

> ok with this refactoring.

I've committed a slightly modified version of this patch as
35e8f7ab94c910659de9d507aa0f3e1f8973d914.

Modification was required due to patch 3 being committed before patch
2, which is required because patch 2 introduces a failure in tst-tls3
without patch 3.

-- 
Paul Pluzhnikov

2013-12-18  Andrew Hunter  <ahh@google.com>

	* elf/Versions (ld): Add _dl_clear_dtv.
	* sysdeps/generic/ldsodefs.h (_dl_clear_dtv): New prototype.
	* elf/dl-tls.c (_dl_clear_dtv): New function.
	* nptl/allocatestack.c (get_cached_stack): Call _dl_clear_dtv.
-------------- next part --------------
diff --git a/elf/Versions b/elf/Versions
index 2383992..01b7a59 100644
--- a/elf/Versions
+++ b/elf/Versions
@@ -53,6 +53,7 @@ ld {
     _dl_allocate_tls; _dl_allocate_tls_init;
     _dl_argv; _dl_find_dso_for_object; _dl_get_tls_static_info;
     _dl_deallocate_tls; _dl_make_stack_executable; _dl_out_of_memory;
+    _dl_clear_dtv;
     _dl_rtld_di_serinfo; _dl_starting_up; _dl_tls_setup;
     _rtld_global; _rtld_global_ro;
 
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index 576d9a1..c60a6b7 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -463,6 +463,18 @@ _dl_allocate_tls (void *mem)
 }
 rtld_hidden_def (_dl_allocate_tls)
 
+void
+internal_function
+_dl_clear_dtv (dtv_t *dtv)
+{
+  for (size_t cnt = 0; cnt < dtv[-1].counter; ++cnt)
+    if (! dtv[1 + cnt].pointer.is_static
+	&& dtv[1 + cnt].pointer.val != TLS_DTV_UNALLOCATED)
+      free (dtv[1 + cnt].pointer.val);
+  memset (dtv, '\0', (dtv[-1].counter + 1) * sizeof (dtv_t));
+}
+
+rtld_hidden_def (_dl_clear_dtv)
 
 #ifndef SHARED
 extern dtv_t _dl_static_dtv[];
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 1e0fe1f..96e3845 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -242,11 +242,7 @@ get_cached_stack (size_t *sizep, void **memp)
 
   /* Clear the DTV.  */
   dtv_t *dtv = GET_DTV (TLS_TPADJ (result));
-  for (size_t cnt = 0; cnt < dtv[-1].counter; ++cnt)
-    if (! dtv[1 + cnt].pointer.is_static
-	&& dtv[1 + cnt].pointer.val != TLS_DTV_UNALLOCATED)
-      free (dtv[1 + cnt].pointer.val);
-  memset (dtv, '\0', (dtv[-1].counter + 1) * sizeof (dtv_t));
+  _dl_clear_dtv (dtv);
 
   /* Re-initialize the TLS.  */
   _dl_allocate_tls_init (TLS_TPADJ (result));
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index e919e41..1bda60c 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -989,6 +989,11 @@ extern void *_dl_allocate_tls_storage (void)
 extern void *_dl_allocate_tls_init (void *) internal_function;
 rtld_hidden_proto (_dl_allocate_tls_init)
 
+/* Remove all allocated dynamic TLS regions from a DTV
+   for reuse by new thread.  */
+extern void _dl_clear_dtv (dtv_t *dtv) internal_function;
+rtld_hidden_proto (_dl_clear_dtv)
+
 /* Deallocate memory allocated with _dl_allocate_tls.  */
 extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb) internal_function;
 rtld_hidden_proto (_dl_deallocate_tls)


More information about the Libc-alpha mailing list