From e57b0c6100e63bfd816ae59339452eafc81f1d3a Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 28 Mar 2013 16:52:57 -0700 Subject: Avoid unconditional __call_tls_dtors calls in static linking. --- ChangeLog | 7 +++++++ include/stdlib.h | 8 ++++++-- nptl/ChangeLog | 5 +++++ nptl/pthread_create.c | 5 ++++- stdlib/cxa_thread_atexit_impl.c | 2 +- stdlib/exit.c | 5 ++++- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 876b577839..d4da5407d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-03-28 Roland McGrath + + * include/stdlib.h [!SHARED] (__call_tls_dtors): + Declare with __attribute__ ((weak)). + * stdlib/exit.c (__libc_atexit) [!SHARED]: + Call __call_tls_dtors only if it's not NULL. + 2013-03-28 Roland McGrath * csu/libc-start.c (__libc_start_main) [!SHARED]: If _dl_aux_init diff --git a/include/stdlib.h b/include/stdlib.h index db1812d85a..e50985a5b8 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -102,8 +102,12 @@ extern int __cxa_atexit_internal (void (*func) (void *), void *arg, void *d) extern int __cxa_thread_atexit_impl (void (*func) (void *), void *arg, void *d); -extern void __call_tls_dtors (void); -libc_hidden_proto (__call_tls_dtors); +extern void __call_tls_dtors (void) +#ifndef SHARED + __attribute__ ((weak)) +#endif + ; +libc_hidden_proto (__call_tls_dtors) extern void __cxa_finalize (void *d); diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 707744a657..3a1dde6f43 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,8 @@ +2013-03-28 Roland McGrath + + * pthread_create.c (start_thread) [!SHARED]: + Call __call_tls_dtors only if it's not NULL. + 2013-03-19 Siddhesh Poyarekar * allocatestack.c (allocate_stack): Use __default_pthread_attr diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index c18278cf08..c43077fe2d 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -312,7 +312,10 @@ start_thread (void *arg) } /* Call destructors for the thread_local TLS variables. */ - __call_tls_dtors (); +#ifndef SHARED + if (&__call_tls_dtors != NULL) +#endif + __call_tls_dtors (); /* Run the destructor for the thread-local data. */ __nptl_deallocate_tsd (); diff --git a/stdlib/cxa_thread_atexit_impl.c b/stdlib/cxa_thread_atexit_impl.c index ebf3c4ab05..dfd4c7e694 100644 --- a/stdlib/cxa_thread_atexit_impl.c +++ b/stdlib/cxa_thread_atexit_impl.c @@ -76,7 +76,7 @@ __cxa_thread_atexit_impl (dtor_func func, void *obj, void *dso_symbol) } /* Call the destructors. This is called either when a thread returns from the - initial function or when the process exits via the exit(3) function. */ + initial function or when the process exits via the exit function. */ void __call_tls_dtors (void) { diff --git a/stdlib/exit.c b/stdlib/exit.c index 2e86caa2d4..270fda7b4f 100644 --- a/stdlib/exit.c +++ b/stdlib/exit.c @@ -34,7 +34,10 @@ __run_exit_handlers (int status, struct exit_function_list **listp, bool run_list_atexit) { /* First, call the TLS destructors. */ - __call_tls_dtors (); +#ifndef SHARED + if (&__call_tls_dtors != NULL) +#endif + __call_tls_dtors (); /* We do it this way to handle recursive calls to exit () made by the functions registered with `atexit' and `on_exit'. We call -- cgit 1.4.1