diff mbox series

[uclibc-ng-devel] Fix _dl_deallocate_tls in !SHARED case

Message ID 20190409110043.23642-1-ysionneau@kalray.eu
State Superseded
Headers show
Series [uclibc-ng-devel] Fix _dl_deallocate_tls in !SHARED case | expand

Commit Message

Yann Sionneau April 9, 2019, 11 a.m. UTC
This patch seems needed in builds where
- SHARED is not defined (no shared lib support)
- and USE_TLS is set

Without this patch, static_dtv is free'ed.
See the following backtrace:

This backtrace is obtained while debugging tst-basic3 from the uclibc-ng nptl testsuite.
It aborts because of the assert in malloc:
https://elixir.bootlin.com/uclibc-ng/v1.0.31/source/libc/stdlib/malloc-standard/malloc.c#L80

Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
---
 libpthread/nptl/sysdeps/generic/dl-tls.c   | 5 +++++
 libpthread/nptl/sysdeps/generic/libc-tls.c | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Yann Sionneau April 9, 2019, 11:03 a.m. UTC | #1
Resending the patch with the backtrace included...

On 4/9/19 1:00 PM, Yann Sionneau wrote:
> This patch seems needed in builds where
> - SHARED is not defined (no shared lib support)
> - and USE_TLS is set
>
> Without this patch, static_dtv is free'ed.
> See the following backtrace:
>
> This backtrace is obtained while debugging tst-basic3 from the uclibc-ng nptl testsuite.
> It aborts because of the assert in malloc:
> https://elixir.bootlin.com/uclibc-ng/v1.0.31/source/libc/stdlib/malloc-standard/malloc.c#L80
>
> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
> ---
>   libpthread/nptl/sysdeps/generic/dl-tls.c   | 5 +++++
>   libpthread/nptl/sysdeps/generic/libc-tls.c | 5 ++++-
>   2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/libpthread/nptl/sysdeps/generic/dl-tls.c b/libpthread/nptl/sysdeps/generic/dl-tls.c
> index 989e587a2..7d25e4706 100644
> --- a/libpthread/nptl/sysdeps/generic/dl-tls.c
> +++ b/libpthread/nptl/sysdeps/generic/dl-tls.c
> @@ -48,6 +48,9 @@
>   /* Value used for dtv entries for which the allocation is delayed.  */
>   # define TLS_DTV_UNALLOCATED	((void *) -1l)
>   
> +#ifndef SHARED
> +extern dtv_t static_dtv;
> +#endif
>   
>   /* Out-of-memory handler.  */
>   # ifdef SHARED
> @@ -584,6 +587,8 @@ _dl_deallocate_tls (void *tcb, bool dealloc_tcb)
>     /* The array starts with dtv[-1].  */
>   #ifdef SHARED
>     if (dtv != GL(dl_initial_dtv))
> +#else
> +  if ((dtv - 1) != &static_dtv)
>   #endif
>       free (dtv - 1);
>   
> diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c
> index a6df4cdc4..d746c9a38 100644
> --- a/libpthread/nptl/sysdeps/generic/libc-tls.c
> +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c
> @@ -42,7 +42,10 @@ extern size_t _dl_phnum;
>   extern int __tdata_start;
>   #endif
>   
> -static dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS];
> +#ifdef SHARED
> +static
> +#endif
> +dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS];
>   
>   
>   static struct
diff mbox series

Patch

diff --git a/libpthread/nptl/sysdeps/generic/dl-tls.c b/libpthread/nptl/sysdeps/generic/dl-tls.c
index 989e587a2..7d25e4706 100644
--- a/libpthread/nptl/sysdeps/generic/dl-tls.c
+++ b/libpthread/nptl/sysdeps/generic/dl-tls.c
@@ -48,6 +48,9 @@ 
 /* Value used for dtv entries for which the allocation is delayed.  */
 # define TLS_DTV_UNALLOCATED	((void *) -1l)
 
+#ifndef SHARED
+extern dtv_t static_dtv;
+#endif
 
 /* Out-of-memory handler.  */
 # ifdef SHARED
@@ -584,6 +587,8 @@  _dl_deallocate_tls (void *tcb, bool dealloc_tcb)
   /* The array starts with dtv[-1].  */
 #ifdef SHARED
   if (dtv != GL(dl_initial_dtv))
+#else
+  if ((dtv - 1) != &static_dtv)
 #endif
     free (dtv - 1);
 
diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c
index a6df4cdc4..d746c9a38 100644
--- a/libpthread/nptl/sysdeps/generic/libc-tls.c
+++ b/libpthread/nptl/sysdeps/generic/libc-tls.c
@@ -42,7 +42,10 @@  extern size_t _dl_phnum;
 extern int __tdata_start;
 #endif
 
-static dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS];
+#ifdef SHARED
+static
+#endif
+dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS];
 
 
 static struct