+2018-06-26 Florian Weimer <fweimer@redhat.com>
+
+ Run thread shutdown functions in an explicit order.
+ * malloc/thread-freeres.c (__libc_thread_subfreeres): Remove hook
+ definition.
+ (__libc_thread_freeres): Call thread shutdown functions
+ explicitly.
+ * include/rpc/rpc.h (__rpc_thread_destroy): Add hidden attribute.
+ * include/string.h (__strerror_thread_freeres): Declare.
+ * malloc/arena.c (__malloc_arena_thread_freeres): Renamed from
+ arena_thread_freeres. No longer static. Remove thread shutdown
+ hook registration.
+ * malloc/malloc-internal.h (__malloc_arena_thread_freeres):
+ Declare.
+ * resolv/res-close.c (__res_thread_freeres): Renamed from
+ res_thread_freeres. No longer static. Remove thread shutdown
+ hook registration.
+ * resolv/resolv-internal.h (__res_thread_freeres): Declare.
+ * resolv/resolv_conf.c (freeres): Remove incorrect section
+ attribute and use libc_freeres_fn.
+ * string/strerror_l.c (__strerror_thread_freeres): Renamed from
+ strerror_thread_freeres. No longer static. Remove thread
+ shutdown hook registration.
+ * sysdeps/mach/strerror_l.c (__strerror_thread_freeres): Likewise.
+ * sunrpc/rpc_thread.c (__rpc_thread_destroy): Remove thread
+ shutdown hook registration.
+ * Makerules (shlib.lds): Do not provide section boundary symbols
+ for __libc_thread_subfreeres.
+ * manual/memory.texi (Basic Allocation): Update comment.
+
2018-06-26 Florian Weimer <fweimer@redhat.com>
Remove always-defined _RPC_THREAD_SAFE_ macro.
PROVIDE(__start___libc_atexit = .);\
__libc_atexit : { *(__libc_atexit) }\
PROVIDE(__stop___libc_atexit = .);\
- PROVIDE(__start___libc_thread_subfreeres = .);\
- __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
- PROVIDE(__stop___libc_thread_subfreeres = .);\
PROVIDE(__start___libc_IO_vtables = .);\
__libc_IO_vtables : { *(__libc_IO_vtables) }\
PROVIDE(__stop___libc_IO_vtables = .);\
extern void __rpc_thread_clnt_cleanup (void) attribute_hidden;
extern void __rpc_thread_key_cleanup (void) attribute_hidden;
-extern void __rpc_thread_destroy (void);
+extern void __rpc_thread_destroy (void) attribute_hidden;
__libc_tsd_define (extern, struct rpc_thread_variables *, RPC_VARS)
extern char *__strerror_r (int __errnum, char *__buf, size_t __buflen);
+/* Called as part of the thread shutdown sequence. */
+void __strerror_thread_freeres (void) attribute_hidden;
+
/* Get _STRING_ARCH_unaligned. */
#include <string_private.h>
#endif
return ar_ptr;
}
-static void __attribute__ ((section ("__libc_thread_freeres_fn")))
-arena_thread_freeres (void)
+void
+__malloc_arena_thread_freeres (void)
{
/* Shut down the thread cache first. This could deallocate data for
the thread arena, so do this before we put the arena on the free
__libc_lock_unlock (free_list_lock);
}
}
-text_set_element (__libc_thread_subfreeres, arena_thread_freeres);
/*
* Local variables:
/* Called in the child process after a fork. */
void __malloc_fork_unlock_child (void) attribute_hidden;
+/* Called as part of the thread shutdown sequence. */
+void __malloc_arena_thread_freeres (void) attribute_hidden;
+
/* Set *RESULT to LEFT * RIGHT. Return true if the multiplication
overflowed. */
static inline bool
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <stdlib.h>
#include <libc-internal.h>
-#include <set-hooks.h>
+#include <malloc-internal.h>
+#include <resolv/resolv-internal.h>
+#include <rpc/rpc.h>
+#include <string.h>
-#ifdef _LIBC_REENTRANT
-DEFINE_HOOK (__libc_thread_subfreeres, (void));
-
-void __attribute__ ((section ("__libc_thread_freeres_fn")))
+/* Thread shutdown function. Note that this function must be called
+ for threads during shutdown for correctness reasons. Unlike
+ __libc_subfreeres, skipping calls to it is not a valid
+ optimization. */
+void
__libc_thread_freeres (void)
{
- RUN_HOOK (__libc_thread_subfreeres, ());
+ call_function_static_weak (__rpc_thread_destroy);
+ call_function_static_weak (__res_thread_freeres);
+ call_function_static_weak (__strerror_thread_freeres);
+
+ /* This should come last because it shuts down malloc for this
+ thread and the other shutdown functions might well call free. */
+ call_function_static_weak (__malloc_arena_thread_freeres);
}
-#endif
@c reads&writes next_to_use and iterates over arena next without guards
@c those are harmless as long as we don't drop arenas from the
@c NEXT list, and we never do; when a thread terminates,
-@c arena_thread_freeres prepends the arena to the free_list
+@c __malloc_arena_thread_freeres prepends the arena to the free_list
@c NEXT_FREE list, but NEXT is never modified, so it's safe!
@c mutex_trylock (arena lock) @asulock @aculock
@c mutex_lock (arena lock) dup @asulock @aculock
libc_hidden_def (__res_nclose)
/* This is called when a thread is exiting to free resources held in _res. */
-static void __attribute__ ((section ("__libc_thread_freeres_fn")))
-res_thread_freeres (void)
+void
+__res_thread_freeres (void)
{
__resolv_context_freeres ();
/* Make sure we do a full re-initialization the next time. */
_res.options = 0;
}
-text_set_element (__libc_thread_subfreeres, res_thread_freeres);
-text_set_element (__libc_subfreeres, res_thread_freeres);
+text_set_element (__libc_subfreeres, __res_thread_freeres);
int __inet_pton_length (int af, const char *src, size_t srclen, void *);
libc_hidden_proto (__inet_pton_length)
+/* Called as part of the thread shutdown sequence. */
+void __res_thread_freeres (void) attribute_hidden;
+
#endif /* _RESOLV_INTERNAL_H */
}
/* Deallocate the global data. */
-static void __attribute__ ((section ("__libc_thread_freeres_fn")))
-freeres (void)
+libc_freeres_fn (freeres)
{
/* No locking because this function is supposed to be called when
the process has turned single-threaded. */
deallocated memory. */
global = NULL;
}
-text_set_element (__libc_subfreeres, freeres);
}
-#ifdef _LIBC
-# ifdef _LIBC_REENTRANT
-/* This is called when a thread is exiting to free the last_value string. */
-static void __attribute__ ((section ("__libc_thread_freeres_fn")))
-strerror_thread_freeres (void)
+void
+__strerror_thread_freeres (void)
{
free (last_value);
}
-text_set_element (__libc_thread_subfreeres, strerror_thread_freeres);
-text_set_element (__libc_subfreeres, strerror_thread_freeres);
-# endif
-#endif
+text_set_element (__libc_subfreeres, __strerror_thread_freeres);
/*
* Task-variable destructor
*/
-void __attribute__ ((section ("__libc_thread_freeres_fn")))
+void
__rpc_thread_destroy (void)
{
struct rpc_thread_variables *tvp = thread_rpc_vars;
thread_rpc_vars = NULL;
}
}
-#ifdef _LIBC_REENTRANT
-text_set_element (__libc_thread_subfreeres, __rpc_thread_destroy);
-#endif
text_set_element (__libc_subfreeres, __rpc_thread_destroy);
-
/*
* Initialize RPC multi-threaded operation
*/
}
-#ifdef _LIBC
-# ifdef _LIBC_REENTRANT
-/* This is called when a thread is exiting to free the last_value string. */
-static void __attribute__ ((section ("__libc_thread_freeres_fn")))
-strerror_thread_freeres (void)
+void
+__strerror_thread_freeres (void)
{
free (last_value);
}
-text_set_element (__libc_thread_subfreeres, strerror_thread_freeres);
-text_set_element (__libc_subfreeres, strerror_thread_freeres);
-# endif
-#endif
+text_set_element (__libc_subfreeres, __strerror_thread_freeres);