94084c
commit 024a7640ab9ecea80e527f4e4d7f7a1868e952c5
94084c
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
94084c
Date:   Wed Sep 15 15:16:19 2021 +0100
94084c
94084c
    elf: Avoid deadlock between pthread_create and ctors [BZ #28357]
94084c
    
94084c
    The fix for bug 19329 caused a regression such that pthread_create can
94084c
    deadlock when concurrent ctors from dlopen are waiting for it to finish.
94084c
    Use a new GL(dl_load_tls_lock) in pthread_create that is not taken
94084c
    around ctors in dlopen.
94084c
    
94084c
    The new lock is also used in __tls_get_addr instead of GL(dl_load_lock).
94084c
    
94084c
    The new lock is held in _dl_open_worker and _dl_close_worker around
94084c
    most of the logic before/after the init/fini routines.  When init/fini
94084c
    routines are running then TLS is in a consistent, usable state.
94084c
    In _dl_open_worker the new lock requires catching and reraising dlopen
94084c
    failures that happen in the critical section.
94084c
    
94084c
    The new lock is reinitialized in a fork child, to keep the existing
94084c
    behaviour and it is kept recursive in case malloc interposition or TLS
94084c
    access from signal handlers can retake it.  It is not obvious if this
94084c
    is necessary or helps, but avoids changing the preexisting behaviour.
94084c
    
94084c
    The new lock may be more appropriate for dl_iterate_phdr too than
94084c
    GL(dl_load_write_lock), since TLS state of an incompletely loaded
94084c
    module may be accessed.  If the new lock can replace the old one,
94084c
    that can be a separate change.
94084c
    
94084c
    Fixes bug 28357.
94084c
    
94084c
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
94084c
    (cherry picked from commit 83b5323261bb72313bffcf37476c1b8f0847c736)
94084c
94084c
diff --git a/elf/dl-close.c b/elf/dl-close.c
94084c
index f39001cab981b723..cd7b9c9fe83a1a44 100644
94084c
--- a/elf/dl-close.c
94084c
+++ b/elf/dl-close.c
94084c
@@ -549,6 +549,9 @@ _dl_close_worker (struct link_map *map, bool force)
94084c
   size_t tls_free_end;
94084c
   tls_free_start = tls_free_end = NO_TLS_OFFSET;
94084c
 
94084c
+  /* Protects global and module specitic TLS state.  */
94084c
+  __rtld_lock_lock_recursive (GL(dl_load_tls_lock));
94084c
+
94084c
   /* We modify the list of loaded objects.  */
94084c
   __rtld_lock_lock_recursive (GL(dl_load_write_lock));
94084c
 
94084c
@@ -784,6 +787,9 @@ _dl_close_worker (struct link_map *map, bool force)
94084c
 	GL(dl_tls_static_used) = tls_free_start;
94084c
     }
94084c
 
94084c
+  /* TLS is cleaned up for the unloaded modules.  */
94084c
+  __rtld_lock_unlock_recursive (GL(dl_load_tls_lock));
94084c
+
94084c
 #ifdef SHARED
94084c
   /* Auditing checkpoint: we have deleted all objects.  */
94084c
   if (__glibc_unlikely (do_audit))
94084c
diff --git a/elf/dl-open.c b/elf/dl-open.c
94084c
index 41c7250bf630f978..bc68e2c376debd71 100644
94084c
--- a/elf/dl-open.c
94084c
+++ b/elf/dl-open.c
94084c
@@ -66,6 +66,9 @@ struct dl_open_args
94084c
      libc_map value in the namespace in case of a dlopen failure.  */
94084c
   bool libc_already_loaded;
94084c
 
94084c
+  /* Set to true if the end of dl_open_worker_begin was reached.  */
94084c
+  bool worker_continue;
94084c
+
94084c
   /* Original parameters to the program and the current environment.  */
94084c
   int argc;
94084c
   char **argv;
94084c
@@ -482,7 +485,7 @@ call_dl_init (void *closure)
94084c
 }
94084c
 
94084c
 static void
94084c
-dl_open_worker (void *a)
94084c
+dl_open_worker_begin (void *a)
94084c
 {
94084c
   struct dl_open_args *args = a;
94084c
   const char *file = args->file;
94084c
@@ -774,6 +777,36 @@ dl_open_worker (void *a)
94084c
       _dl_call_libc_early_init (libc_map, false);
94084c
     }
94084c
 
94084c
+  args->worker_continue = true;
94084c
+}
94084c
+
94084c
+static void
94084c
+dl_open_worker (void *a)
94084c
+{
94084c
+  struct dl_open_args *args = a;
94084c
+
94084c
+  args->worker_continue = false;
94084c
+
94084c
+  {
94084c
+    /* Protects global and module specific TLS state.  */
94084c
+    __rtld_lock_lock_recursive (GL(dl_load_tls_lock));
94084c
+
94084c
+    struct dl_exception ex;
94084c
+    int err = _dl_catch_exception (&ex, dl_open_worker_begin, args);
94084c
+
94084c
+    __rtld_lock_unlock_recursive (GL(dl_load_tls_lock));
94084c
+
94084c
+    if (__glibc_unlikely (ex.errstring != NULL))
94084c
+      /* Reraise the error.  */
94084c
+      _dl_signal_exception (err, &ex, NULL);
94084c
+  }
94084c
+
94084c
+  if (!args->worker_continue)
94084c
+    return;
94084c
+
94084c
+  int mode = args->mode;
94084c
+  struct link_map *new = args->map;
94084c
+
94084c
   /* Run the initializer functions of new objects.  Temporarily
94084c
      disable the exception handler, so that lazy binding failures are
94084c
      fatal.  */
94084c
diff --git a/elf/dl-support.c b/elf/dl-support.c
94084c
index 01557181753fb38d..d8c06ba7eb4c76ea 100644
94084c
--- a/elf/dl-support.c
94084c
+++ b/elf/dl-support.c
94084c
@@ -229,6 +229,13 @@ __rtld_lock_define_initialized_recursive (, _dl_load_lock)
94084c
    list of loaded objects while an object is added to or removed from
94084c
    that list.  */
94084c
 __rtld_lock_define_initialized_recursive (, _dl_load_write_lock)
94084c
+  /* This lock protects global and module specific TLS related data.
94084c
+     E.g. it is held in dlopen and dlclose when GL(dl_tls_generation),
94084c
+     GL(dl_tls_max_dtv_idx) or GL(dl_tls_dtv_slotinfo_list) are
94084c
+     accessed and when TLS related relocations are processed for a
94084c
+     module.  It was introduced to keep pthread_create accessing TLS
94084c
+     state that is being set up.  */
94084c
+__rtld_lock_define_initialized_recursive (, _dl_load_tls_lock)
94084c
 
94084c
 
94084c
 #ifdef HAVE_AUX_VECTOR
94084c
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
94084c
index 423e380f7ca654fe..40263cf586e74c64 100644
94084c
--- a/elf/dl-tls.c
94084c
+++ b/elf/dl-tls.c
94084c
@@ -532,7 +532,7 @@ _dl_allocate_tls_init (void *result)
94084c
   size_t maxgen = 0;
94084c
 
94084c
   /* Protects global dynamic TLS related state.  */
94084c
-  __rtld_lock_lock_recursive (GL(dl_load_lock));
94084c
+  __rtld_lock_lock_recursive (GL(dl_load_tls_lock));
94084c
 
94084c
   /* Check if the current dtv is big enough.   */
94084c
   if (dtv[-1].counter < GL(dl_tls_max_dtv_idx))
94084c
@@ -606,7 +606,7 @@ _dl_allocate_tls_init (void *result)
94084c
       listp = listp->next;
94084c
       assert (listp != NULL);
94084c
     }
94084c
-  __rtld_lock_unlock_recursive (GL(dl_load_lock));
94084c
+  __rtld_lock_unlock_recursive (GL(dl_load_tls_lock));
94084c
 
94084c
   /* The DTV version is up-to-date now.  */
94084c
   dtv[0].counter = maxgen;
94084c
@@ -745,7 +745,7 @@ _dl_update_slotinfo (unsigned long int req_modid)
94084c
 
94084c
 	 Here the dtv needs to be updated to new_gen generation count.
94084c
 
94084c
-	 This code may be called during TLS access when GL(dl_load_lock)
94084c
+	 This code may be called during TLS access when GL(dl_load_tls_lock)
94084c
 	 is not held.  In that case the user code has to synchronize with
94084c
 	 dlopen and dlclose calls of relevant modules.  A module m is
94084c
 	 relevant if the generation of m <= new_gen and dlclose of m is
94084c
@@ -867,11 +867,11 @@ tls_get_addr_tail (GET_ADDR_ARGS, dtv_t *dtv, struct link_map *the_map)
94084c
   if (__glibc_unlikely (the_map->l_tls_offset
94084c
 			!= FORCED_DYNAMIC_TLS_OFFSET))
94084c
     {
94084c
-      __rtld_lock_lock_recursive (GL(dl_load_lock));
94084c
+      __rtld_lock_lock_recursive (GL(dl_load_tls_lock));
94084c
       if (__glibc_likely (the_map->l_tls_offset == NO_TLS_OFFSET))
94084c
 	{
94084c
 	  the_map->l_tls_offset = FORCED_DYNAMIC_TLS_OFFSET;
94084c
-	  __rtld_lock_unlock_recursive (GL(dl_load_lock));
94084c
+	  __rtld_lock_unlock_recursive (GL(dl_load_tls_lock));
94084c
 	}
94084c
       else if (__glibc_likely (the_map->l_tls_offset
94084c
 			       != FORCED_DYNAMIC_TLS_OFFSET))
94084c
@@ -883,7 +883,7 @@ tls_get_addr_tail (GET_ADDR_ARGS, dtv_t *dtv, struct link_map *the_map)
94084c
 #else
94084c
 # error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
94084c
 #endif
94084c
-	  __rtld_lock_unlock_recursive (GL(dl_load_lock));
94084c
+	  __rtld_lock_unlock_recursive (GL(dl_load_tls_lock));
94084c
 
94084c
 	  dtv[GET_ADDR_MODULE].pointer.to_free = NULL;
94084c
 	  dtv[GET_ADDR_MODULE].pointer.val = p;
94084c
@@ -891,7 +891,7 @@ tls_get_addr_tail (GET_ADDR_ARGS, dtv_t *dtv, struct link_map *the_map)
94084c
 	  return (char *) p + GET_ADDR_OFFSET;
94084c
 	}
94084c
       else
94084c
-	__rtld_lock_unlock_recursive (GL(dl_load_lock));
94084c
+	__rtld_lock_unlock_recursive (GL(dl_load_tls_lock));
94084c
     }
94084c
   struct dtv_pointer result = allocate_and_init (the_map);
94084c
   dtv[GET_ADDR_MODULE].pointer = result;
94084c
@@ -962,7 +962,7 @@ _dl_tls_get_addr_soft (struct link_map *l)
94084c
     return NULL;
94084c
 
94084c
   dtv_t *dtv = THREAD_DTV ();
94084c
-  /* This may be called without holding the GL(dl_load_lock).  Reading
94084c
+  /* This may be called without holding the GL(dl_load_tls_lock).  Reading
94084c
      arbitrary gen value is fine since this is best effort code.  */
94084c
   size_t gen = atomic_load_relaxed (&GL(dl_tls_generation));
94084c
   if (__glibc_unlikely (dtv[0].counter != gen))
94084c
diff --git a/elf/rtld.c b/elf/rtld.c
94084c
index d733359eaf808b8a..08cf50145a1c01ce 100644
94084c
--- a/elf/rtld.c
94084c
+++ b/elf/rtld.c
94084c
@@ -322,6 +322,7 @@ struct rtld_global _rtld_global =
94084c
 #ifdef _LIBC_REENTRANT
94084c
     ._dl_load_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
94084c
     ._dl_load_write_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
94084c
+    ._dl_load_tls_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
94084c
 #endif
94084c
     ._dl_nns = 1,
94084c
     ._dl_ns =
94084c
diff --git a/posix/fork.c b/posix/fork.c
94084c
index c471f7b15fe4290d..021691b9b7441f15 100644
94084c
--- a/posix/fork.c
94084c
+++ b/posix/fork.c
94084c
@@ -99,6 +99,9 @@ __libc_fork (void)
94084c
       /* Reset the lock the dynamic loader uses to protect its data.  */
94084c
       __rtld_lock_initialize (GL(dl_load_lock));
94084c
 
94084c
+      /* Reset the lock protecting dynamic TLS related data.  */
94084c
+      __rtld_lock_initialize (GL(dl_load_tls_lock));
94084c
+
94084c
       reclaim_stacks ();
94084c
 
94084c
       /* Run the handlers registered for the child.  */
94084c
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
94084c
index 9c15259236adab43..1ceb9c3212c148ba 100644
94084c
--- a/sysdeps/generic/ldsodefs.h
94084c
+++ b/sysdeps/generic/ldsodefs.h
94084c
@@ -372,6 +372,13 @@ struct rtld_global
94084c
      list of loaded objects while an object is added to or removed
94084c
      from that list.  */
94084c
   __rtld_lock_define_recursive (EXTERN, _dl_load_write_lock)
94084c
+  /* This lock protects global and module specific TLS related data.
94084c
+     E.g. it is held in dlopen and dlclose when GL(dl_tls_generation),
94084c
+     GL(dl_tls_max_dtv_idx) or GL(dl_tls_dtv_slotinfo_list) are
94084c
+     accessed and when TLS related relocations are processed for a
94084c
+     module.  It was introduced to keep pthread_create accessing TLS
94084c
+     state that is being set up.  */
94084c
+  __rtld_lock_define_recursive (EXTERN, _dl_load_tls_lock)
94084c
 
94084c
   /* Incremented whenever something may have been added to dl_loaded.  */
94084c
   EXTERN unsigned long long _dl_load_adds;
94084c
@@ -1261,7 +1268,7 @@ extern int _dl_scope_free (void *) attribute_hidden;
94084c
 
94084c
 /* Add module to slot information data.  If DO_ADD is false, only the
94084c
    required memory is allocated.  Must be called with GL
94084c
-   (dl_load_lock) acquired.  If the function has already been called
94084c
+   (dl_load_tls_lock) acquired.  If the function has already been called
94084c
    for the link map L with !do_add, then this function will not raise
94084c
    an exception, otherwise it is possible that it encounters a memory
94084c
    allocation failure.  */
94084c
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
94084c
index 0af9c59b425aefb1..df8943f4860a39d8 100644
94084c
--- a/sysdeps/pthread/Makefile
94084c
+++ b/sysdeps/pthread/Makefile
94084c
@@ -152,15 +152,17 @@ tests += tst-cancelx2 tst-cancelx3 tst-cancelx6 tst-cancelx8 tst-cancelx9 \
94084c
 	 tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3
94084c
 
94084c
 ifeq ($(build-shared),yes)
94084c
-tests += tst-atfork2 tst-pt-tls4 tst-_res1 tst-fini1
94084c
+tests += tst-atfork2 tst-pt-tls4 tst-_res1 tst-fini1 tst-create1
94084c
 tests-nolibpthread += tst-fini1
94084c
 endif
94084c
 
94084c
 modules-names += tst-atfork2mod tst-tls4moda tst-tls4modb \
94084c
-		 tst-_res1mod1 tst-_res1mod2 tst-fini1mod
94084c
+		 tst-_res1mod1 tst-_res1mod2 tst-fini1mod \
94084c
+		 tst-create1mod
94084c
 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
94084c
 
94084c
 tst-atfork2mod.so-no-z-defs = yes
94084c
+tst-create1mod.so-no-z-defs = yes
94084c
 
94084c
 ifeq ($(build-shared),yes)
94084c
 # Build all the modules even when not actually running test programs.
94084c
@@ -279,4 +281,8 @@ LDFLAGS-tst-join7mod.so = -Wl,-soname,tst-join7mod.so
94084c
 
94084c
 CFLAGS-tst-unwind-thread.c += -funwind-tables
94084c
 
94084c
+LDFLAGS-tst-create1 = -Wl,-export-dynamic
94084c
+$(objpfx)tst-create1: $(shared-thread-library)
94084c
+$(objpfx)tst-create1.out: $(objpfx)tst-create1mod.so
94084c
+
94084c
 endif
94084c
diff --git a/sysdeps/pthread/tst-create1.c b/sysdeps/pthread/tst-create1.c
94084c
new file mode 100644
94084c
index 0000000000000000..932586c30990d1d4
94084c
--- /dev/null
94084c
+++ b/sysdeps/pthread/tst-create1.c
94084c
@@ -0,0 +1,119 @@
94084c
+/* Verify that pthread_create does not deadlock when ctors take locks.
94084c
+   Copyright (C) 2021 Free Software Foundation, Inc.
94084c
+   This file is part of the GNU C Library.
94084c
+
94084c
+   The GNU C Library is free software; you can redistribute it and/or
94084c
+   modify it under the terms of the GNU Lesser General Public
94084c
+   License as published by the Free Software Foundation; either
94084c
+   version 2.1 of the License, or (at your option) any later version.
94084c
+
94084c
+   The GNU C Library is distributed in the hope that it will be useful,
94084c
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
94084c
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
94084c
+   Lesser General Public License for more details.
94084c
+
94084c
+   You should have received a copy of the GNU Lesser General Public
94084c
+   License along with the GNU C Library; if not, see
94084c
+   <https://www.gnu.org/licenses/>.  */
94084c
+
94084c
+#include <stdio.h>
94084c
+#include <support/xdlfcn.h>
94084c
+#include <support/xthread.h>
94084c
+
94084c
+/*
94084c
+Check if ctor and pthread_create deadlocks in
94084c
+
94084c
+thread 1: dlopen -> ctor -> lock(user_lock)
94084c
+thread 2: lock(user_lock) -> pthread_create
94084c
+
94084c
+or in
94084c
+
94084c
+thread 1: dlclose -> dtor -> lock(user_lock)
94084c
+thread 2: lock(user_lock) -> pthread_create
94084c
+*/
94084c
+
94084c
+static pthread_barrier_t bar_ctor;
94084c
+static pthread_barrier_t bar_dtor;
94084c
+static pthread_mutex_t user_lock = PTHREAD_MUTEX_INITIALIZER;
94084c
+
94084c
+void
94084c
+ctor (void)
94084c
+{
94084c
+  xpthread_barrier_wait (&bar_ctor);
94084c
+  dprintf (1, "thread 1: in ctor: started.\n");
94084c
+  xpthread_mutex_lock (&user_lock);
94084c
+  dprintf (1, "thread 1: in ctor: locked user_lock.\n");
94084c
+  xpthread_mutex_unlock (&user_lock);
94084c
+  dprintf (1, "thread 1: in ctor: unlocked user_lock.\n");
94084c
+  dprintf (1, "thread 1: in ctor: done.\n");
94084c
+}
94084c
+
94084c
+void
94084c
+dtor (void)
94084c
+{
94084c
+  xpthread_barrier_wait (&bar_dtor);
94084c
+  dprintf (1, "thread 1: in dtor: started.\n");
94084c
+  xpthread_mutex_lock (&user_lock);
94084c
+  dprintf (1, "thread 1: in dtor: locked user_lock.\n");
94084c
+  xpthread_mutex_unlock (&user_lock);
94084c
+  dprintf (1, "thread 1: in dtor: unlocked user_lock.\n");
94084c
+  dprintf (1, "thread 1: in dtor: done.\n");
94084c
+}
94084c
+
94084c
+static void *
94084c
+thread3 (void *a)
94084c
+{
94084c
+  dprintf (1, "thread 3: started.\n");
94084c
+  dprintf (1, "thread 3: done.\n");
94084c
+  return 0;
94084c
+}
94084c
+
94084c
+static void *
94084c
+thread2 (void *a)
94084c
+{
94084c
+  pthread_t t3;
94084c
+  dprintf (1, "thread 2: started.\n");
94084c
+
94084c
+  xpthread_mutex_lock (&user_lock);
94084c
+  dprintf (1, "thread 2: locked user_lock.\n");
94084c
+  xpthread_barrier_wait (&bar_ctor);
94084c
+  t3 = xpthread_create (0, thread3, 0);
94084c
+  xpthread_mutex_unlock (&user_lock);
94084c
+  dprintf (1, "thread 2: unlocked user_lock.\n");
94084c
+  xpthread_join (t3);
94084c
+
94084c
+  xpthread_mutex_lock (&user_lock);
94084c
+  dprintf (1, "thread 2: locked user_lock.\n");
94084c
+  xpthread_barrier_wait (&bar_dtor);
94084c
+  t3 = xpthread_create (0, thread3, 0);
94084c
+  xpthread_mutex_unlock (&user_lock);
94084c
+  dprintf (1, "thread 2: unlocked user_lock.\n");
94084c
+  xpthread_join (t3);
94084c
+
94084c
+  dprintf (1, "thread 2: done.\n");
94084c
+  return 0;
94084c
+}
94084c
+
94084c
+static void
94084c
+thread1 (void)
94084c
+{
94084c
+  dprintf (1, "thread 1: started.\n");
94084c
+  xpthread_barrier_init (&bar_ctor, NULL, 2);
94084c
+  xpthread_barrier_init (&bar_dtor, NULL, 2);
94084c
+  pthread_t t2 = xpthread_create (0, thread2, 0);
94084c
+  void *p = xdlopen ("tst-create1mod.so", RTLD_NOW | RTLD_GLOBAL);
94084c
+  dprintf (1, "thread 1: dlopen done.\n");
94084c
+  xdlclose (p);
94084c
+  dprintf (1, "thread 1: dlclose done.\n");
94084c
+  xpthread_join (t2);
94084c
+  dprintf (1, "thread 1: done.\n");
94084c
+}
94084c
+
94084c
+static int
94084c
+do_test (void)
94084c
+{
94084c
+  thread1 ();
94084c
+  return 0;
94084c
+}
94084c
+
94084c
+#include <support/test-driver.c>
94084c
diff --git a/sysdeps/pthread/tst-create1mod.c b/sysdeps/pthread/tst-create1mod.c
94084c
new file mode 100644
94084c
index 0000000000000000..62c9006961683177
94084c
--- /dev/null
94084c
+++ b/sysdeps/pthread/tst-create1mod.c
94084c
@@ -0,0 +1,41 @@
94084c
+/* Verify that pthread_create does not deadlock when ctors take locks.
94084c
+   Copyright (C) 2021 Free Software Foundation, Inc.
94084c
+   This file is part of the GNU C Library.
94084c
+
94084c
+   The GNU C Library is free software; you can redistribute it and/or
94084c
+   modify it under the terms of the GNU Lesser General Public
94084c
+   License as published by the Free Software Foundation; either
94084c
+   version 2.1 of the License, or (at your option) any later version.
94084c
+
94084c
+   The GNU C Library is distributed in the hope that it will be useful,
94084c
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
94084c
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
94084c
+   Lesser General Public License for more details.
94084c
+
94084c
+   You should have received a copy of the GNU Lesser General Public
94084c
+   License along with the GNU C Library; if not, see
94084c
+   <https://www.gnu.org/licenses/>.  */
94084c
+
94084c
+#include <stdio.h>
94084c
+
94084c
+/* Require TLS setup for the module.  */
94084c
+__thread int tlsvar;
94084c
+
94084c
+void ctor (void);
94084c
+void dtor (void);
94084c
+
94084c
+static void __attribute__ ((constructor))
94084c
+do_init (void)
94084c
+{
94084c
+  dprintf (1, "constructor started: %d.\n", tlsvar++);
94084c
+  ctor ();
94084c
+  dprintf (1, "constructor done: %d.\n", tlsvar++);
94084c
+}
94084c
+
94084c
+static void __attribute__ ((destructor))
94084c
+do_end (void)
94084c
+{
94084c
+  dprintf (1, "destructor started: %d.\n", tlsvar++);
94084c
+  dtor ();
94084c
+  dprintf (1, "destructor done: %d.\n", tlsvar++);
94084c
+}