Revision | df82d659c340312c5d7e32a5660168624d5fa265 (tree) |
---|---|
Time | 2019-04-14 17:02:19 |
Author | Yann Sionneau <ysionneau@kalr...> |
Commiter | Waldemar Brodkorb |
Fix _dl_deallocate_tls in !SHARED case
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:
0 do_check_chunk (p=0x52638 <fork_handler_pool+2296>) at libc/stdlib/malloc-standard/malloc.c:80
1 0x0000000000017fa0 in do_check_inuse_chunk (p=0x52638 <fork_handler_pool+2296>) at libc/stdlib/malloc-standard/malloc.c:143
2 0x0000000000017354 in free (mem=0x52648 <static_dtv>) at libc/stdlib/malloc-standard/free.c:293
3 0x000000000002d5b0 in _dl_deallocate_tls (tcb=0x58690, dealloc_tcb=false) at libpthread/nptl/sysdeps/generic/dl-tls.c:588
4 0x0000000000021c0c in deallocate_stack (pd=0x58000) at libpthread/nptl/allocatestack.c:717
5 0x0000000000024408 in free_tcb (pd=0x58000) at libpthread/nptl/pthread_create.c:217
6 0x00000000000200ac in pthread_join (threadid=360448, thread_return=0x0 <k1c_start>) at libpthread/nptl/pthread_join.c:109
7 0x0000000000010354 in tf (a=0x58000) at tst-basic3.c:42
8 0x00000000000247c8 in start_thread (arg=0x4000200960) at libpthread/nptl/pthread_create.c:285
9 0x0000000000026560 in ?? ()
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>
@@ -48,6 +48,9 @@ | ||
48 | 48 | /* Value used for dtv entries for which the allocation is delayed. */ |
49 | 49 | # define TLS_DTV_UNALLOCATED ((void *) -1l) |
50 | 50 | |
51 | +#ifndef SHARED | |
52 | +extern dtv_t static_dtv; | |
53 | +#endif | |
51 | 54 | |
52 | 55 | /* Out-of-memory handler. */ |
53 | 56 | # ifdef SHARED |
@@ -584,6 +587,8 @@ _dl_deallocate_tls (void *tcb, bool dealloc_tcb) | ||
584 | 587 | /* The array starts with dtv[-1]. */ |
585 | 588 | #ifdef SHARED |
586 | 589 | if (dtv != GL(dl_initial_dtv)) |
590 | +#else | |
591 | + if ((dtv - 1) != &static_dtv) | |
587 | 592 | #endif |
588 | 593 | free (dtv - 1); |
589 | 594 |
@@ -42,7 +42,10 @@ extern size_t _dl_phnum; | ||
42 | 42 | extern int __tdata_start; |
43 | 43 | #endif |
44 | 44 | |
45 | -static dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS]; | |
45 | +#ifdef SHARED | |
46 | +static | |
47 | +#endif | |
48 | +dtv_t static_dtv[2 + TLS_SLOTINFO_SURPLUS]; | |
46 | 49 | |
47 | 50 | |
48 | 51 | static struct |