mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-11 22:00:08 +00:00
024a7640ab
The fix for bug 19329 caused a regression such that pthread_create can
deadlock when concurrent ctors from dlopen are waiting for it to finish.
Use a new GL(dl_load_tls_lock) in pthread_create that is not taken
around ctors in dlopen.
The new lock is also used in __tls_get_addr instead of GL(dl_load_lock).
The new lock is held in _dl_open_worker and _dl_close_worker around
most of the logic before/after the init/fini routines. When init/fini
routines are running then TLS is in a consistent, usable state.
In _dl_open_worker the new lock requires catching and reraising dlopen
failures that happen in the critical section.
The new lock is reinitialized in a fork child, to keep the existing
behaviour and it is kept recursive in case malloc interposition or TLS
access from signal handlers can retake it. It is not obvious if this
is necessary or helps, but avoids changing the preexisting behaviour.
The new lock may be more appropriate for dl_iterate_phdr too than
GL(dl_load_write_lock), since TLS state of an incompletely loaded
module may be accessed. If the new lock can replace the old one,
that can be a separate change.
Fixes bug 28357.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 83b5323261
)
42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
/* Verify that pthread_create does not deadlock when ctors take locks.
|
|
Copyright (C) 2021 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#include <stdio.h>
|
|
|
|
/* Require TLS setup for the module. */
|
|
__thread int tlsvar;
|
|
|
|
void ctor (void);
|
|
void dtor (void);
|
|
|
|
static void __attribute__ ((constructor))
|
|
do_init (void)
|
|
{
|
|
dprintf (1, "constructor started: %d.\n", tlsvar++);
|
|
ctor ();
|
|
dprintf (1, "constructor done: %d.\n", tlsvar++);
|
|
}
|
|
|
|
static void __attribute__ ((destructor))
|
|
do_end (void)
|
|
{
|
|
dprintf (1, "destructor started: %d.\n", tlsvar++);
|
|
dtor ();
|
|
dprintf (1, "destructor done: %d.\n", tlsvar++);
|
|
}
|