glibc/sysdeps
Szabolcs Nagy 024a7640ab elf: Avoid deadlock between pthread_create and ctors [BZ #28357]
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)
2021-10-19 14:21:14 +02:00
..
aarch64 glibc.malloc.check: Wean away from malloc hooks 2021-07-22 18:38:08 +05:30
alpha
arc ARC: elf: make type safe 2021-07-21 13:13:45 -07:00
arm nptl: Remove remaining code from libpthread 2021-05-21 22:35:01 +02:00
csky
generic elf: Avoid deadlock between pthread_create and ctors [BZ #28357] 2021-10-19 14:21:14 +02:00
gnu hurd: Fix glob lstat compatibility 2021-07-22 20:31:52 +02:00
hppa
htl htl: Do not expose pthread hidden proto outside libpthread 2021-07-18 20:25:33 +00:00
hurd
i386 i386: Regenerate ulps 2021-07-25 22:29:27 +02:00
ia64 nptl: Remove remaining code from libpthread 2021-05-21 22:35:01 +02:00
ieee754 Update math: redirect roundeven function 2021-06-27 07:56:57 -07:00
m68k
mach misc: Add __get_nprocs_sched 2021-10-01 18:19:09 +02:00
microblaze
mips Update MIPS libm-test-ulps 2021-07-07 15:50:18 +00:00
nios2
nptl nptl: Fix type of pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np (bug 28036) 2021-09-21 07:15:25 +02:00
posix gaiconf_init: Avoid double-free in label and precedence lists 2021-08-04 15:53:46 +05:30
powerpc Force building with -fno-common 2021-07-09 20:09:14 +02:00
pthread elf: Avoid deadlock between pthread_create and ctors [BZ #28357] 2021-10-19 14:21:14 +02:00
riscv RISC-V: Update rv64 ULPs 2021-07-21 08:44:09 +02:00
s390 S390: Add PCI_MIO and SIE HWCAPs 2021-10-07 06:59:31 +02:00
sh
sparc nptl: Remove remaining code from libpthread 2021-05-21 22:35:01 +02:00
unix timex: Use 64-bit fields on 32-bit TIMESIZE=64 systems (BZ #28469) 2021-10-18 17:45:42 -03:00
wordsize-32
wordsize-64
x86 x86-64: Add Avoid_Short_Distance_REP_MOVSB 2021-07-28 13:23:57 -07:00
x86_64 x86-64: Use testl to check __x86_string_control 2021-08-31 08:09:25 -07:00