glibc/stdlib
Siddhesh Poyarekar 90b37cac8b Also use l_tls_dtor_count to decide on object unload (BZ #18657)
When an TLS destructor is registered, we set the DF_1_NODELETE flag to
signal that the object should not be destroyed.  We then clear the
DF_1_NODELETE flag when all destructors are called, which is wrong -
the flag could have been set by other means too.

This patch replaces this use of the flag by using l_tls_dtor_count
directly to determine whether it is safe to unload the object.  This
change has the added advantage of eliminating the lock taking when
calling the destructors, which could result in a deadlock.  The patch
also fixes the test case tst-tls-atexit - it was making an invalid
dlclose call, which would just return an error silently.

I have also added a detailed note on concurrency which also aims to
justify why I chose the semantics I chose for accesses to
l_tls_dtor_count.  Thanks to Torvald for his help in getting me
started on this and (literally) teaching my how to approach the
problem.

Change verified on x86_64; the test suite does not show any
regressions due to the patch.

ChangeLog:

	[BZ #18657]
	* elf/dl-close.c (_dl_close_worker): Don't unload DSO if there
	are pending TLS destructor calls.
	* include/link.h (struct link_map): Add concurrency note for
	L_TLS_DTOR_COUNT.
	* stdlib/cxa_thread_atexit_impl.c (__cxa_thread_atexit_impl):
	Don't touch the link map flag.  Atomically increment
	l_tls_dtor_count.
	(__call_tls_dtors): Atomically decrement l_tls_dtor_count.
	Avoid taking the load lock and don't touch the link map flag.
	* stdlib/tst-tls-atexit-nodelete.c: New test case.
	* stdlib/Makefile (tests): Use it.
	* stdlib/tst-tls-atexit.c (do_test): dlopen
	tst-tls-atexit-lib.so again before dlclose.  Add conditionals
	to allow tst-tls-atexit-nodelete test case to use it.
2015-07-23 11:16:18 +05:30
..
bits Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
sys
a64l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
abort.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
abs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
add_n.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
addmul_1.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
alloca.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
at_quick_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atexit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atof.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atoi.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atol.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
atoll.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
bsearch.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
bug-fmtmsg1.c
bug-getcontext.c
bug-strtod2.c
bug-strtod.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
canonicalize.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cmp.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cxa_at_quick_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cxa_atexit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cxa_finalize.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
cxa_thread_atexit_impl.c Also use l_tls_dtor_count to decide on object unload (BZ #18657) 2015-07-23 11:16:18 +05:30
dbl2mpn.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
Depend
div.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
divmod_1.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
divrem.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
drand48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
drand48-iter.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
drand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
erand48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
erand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
errno.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
exit.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
fmtmsg.c Fix fmtmsg addseverity namespace (bug 18539). 2015-06-17 20:13:07 +00:00
fmtmsg.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
fpioconst.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
fpioconst.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gen-fpioconst.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gen-tst-strtod-round.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
getcontext.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
getenv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
getsubopt.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
gmp-impl.h Remove various ABS macros and replace uses with fabs (or in one case abs) 2015-05-15 11:04:40 +00:00
gmp.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
grouping.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
grouping.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
groupingwc.c
inlines.c
isomac.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
jrand48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
jrand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
l64a.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
labs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lcong48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lcong48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
ldbl2mpn.c
ldiv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
llabs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lldiv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
longlong.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lrand48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lrand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
lshift.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
makecontext.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
Makefile Also use l_tls_dtor_count to decide on object unload (BZ #18657) 2015-07-23 11:16:18 +05:30
mblen.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mbstowcs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mbtowc.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mod_1.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
monetary.h Fix monetary.h comment 2015-05-27 08:07:07 +05:30
mp_clz_tab.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mpn2dbl.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mpn2flt.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mpn2ldbl.c
mrand48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mrand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
msort.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mul_1.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mul_n.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
mul.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
nrand48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
nrand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
old_atexit.c
on_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
putenv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
qsort.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
quick_exit.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
rand_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
rand.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
random_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
random.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
rpmatch.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
rshift.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
secure-getenv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
seed48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
seed48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
setcontext.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
setenv.c Fix setenv.c diagnostic pragma to be compatible with GCC 4.6 2015-06-02 12:58:45 -07:00
srand48_r.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
srand48.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
stdlib.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strfmon_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strfmon.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtod_l.c Fix strtof decimal rounding close to half least subnormal (bug 18247). 2015-04-10 20:45:30 +00:00
strtod.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtof_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtof.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoimax.c
strtol_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtol.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtold_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtold.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoll_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoll.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoul_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoul.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoull_l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoull.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
strtoumax.c
sub_n.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
submul_1.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
swapcontext.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
system.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tens_in_limb.c
test-a64l.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
test-canon2.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
test-canon.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
testdiv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
testdiv.input
testmb2.c
testmb.c
testrand.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
testsort.c
tst-atof1.c
tst-atof2.c
tst-bsearch.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-environ.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-fmtmsg.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-fmtmsg.sh Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-limits.c Fix a couple of -Wundef warnings. 2014-12-29 23:14:38 -05:00
tst-makecontext2.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-makecontext3.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-makecontext.c S390: Fix "backtrace() returns infinitely deep stack frames with makecontext()" [BZ #18508]. 2015-07-07 16:11:14 +02:00
tst-putenv.c
tst-putenvmod.c
tst-qsort2.c stdlib/tst-qsort2.c: Fix off-by-one argc interpretation error 2014-06-20 21:29:33 +01:00
tst-qsort.c
tst-rand48-2.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-rand48.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-random2.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-random.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-secure-getenv.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-setcontext2.c S/390: Fix setcontext/swapcontext which are not restoring sigmask. 2015-03-12 11:08:11 +01:00
tst-setcontext3.c Bug 18125: Call exit after last linked context. 2015-05-08 11:29:38 -04:00
tst-setcontext3.sh Fix stdlib/tst-setcontext3 with dash [BZ#18418] 2015-05-17 08:48:08 -03:00
tst-setcontext.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-strtod2.c
tst-strtod3.c
tst-strtod4.c
tst-strtod5.c
tst-strtod6.c [BZ #15522] strtod ("nan(N)") returning a sNaN in some cases 2013-08-29 12:22:10 +02:00
tst-strtod-overflow.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-strtod-round-data Fix strtof decimal rounding close to half least subnormal (bug 18247). 2015-04-10 20:45:30 +00:00
tst-strtod-round.c Fix strtof decimal rounding close to half least subnormal (bug 18247). 2015-04-10 20:45:30 +00:00
tst-strtod-underflow.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-strtod.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-strtol.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-strtoll.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-system.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-tininess.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
tst-tls-atexit-lib.c Remove Linuxism from tst-tls-atexit 2015-07-21 07:14:17 +05:30
tst-tls-atexit-nodelete.c Also use l_tls_dtor_count to decide on object unload (BZ #18657) 2015-07-23 11:16:18 +05:30
tst-tls-atexit.c Also use l_tls_dtor_count to decide on object unload (BZ #18657) 2015-07-23 11:16:18 +05:30
tst-unsetenv1.c
tst-xpg-basename.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
ucontext.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
udiv_qrnnd.c
Versions C++11 thread_local destructors support 2013-02-18 19:08:21 +05:30
wcstoimax.c
wcstombs.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
wcstoumax.c
wctomb.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
xpg_basename.c Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00