glibc/include
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
..
arpa Fix resolver inet_* namespace (bug 17722). 2014-12-17 18:09:11 +00:00
bits Remove include/bits/ipc.h. 2015-06-18 23:08:15 +00:00
gnu Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
net Fix resolver if_* namespace (bug 17717). 2014-12-16 18:18:49 +00:00
netinet Fix gethostbyaddr in6addr_any, in6addr_loopback namespace (bug 18532). 2015-06-17 20:08:22 +00:00
programs Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
protocols
rpc Avoid use of "register" as optimization hint. 2013-06-07 22:24:35 +00:00
rpcsvc * nis/nis_domain_of.c (__nis_domain_of): New function. 2007-04-19 14:28:01 +00:00
sys Fix nice getpriority, setpriority namespace (bug 18553). 2015-06-17 20:22:39 +00:00
aio.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
aliases.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
alloca.h alloca: fix buf interaction 2015-02-24 13:29:40 -05:00
argp.h Update. 2000-12-28 15:08:51 +00:00
argz.h Remove use of INTDEF/INTUSE in intl 2012-05-24 23:08:18 +02:00
assert.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
atomic.h Clean up BUSY_WAIT_NOP and atomic_delay. 2015-06-30 15:57:15 +02:00
byteswap.h
caller.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
complex.h conformtest: Fix namespace testing. 2013-09-04 20:47:21 +00:00
cpio.h Add more headers to include/ for conform tests. 2014-12-11 21:41:30 +00:00
ctype.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
des.h
dirent.h Refactor scandir/scandirat to use common tail. 2015-05-13 12:34:11 -07:00
dlfcn.h Add forced deletion support to _dl_close_worker 2015-07-07 11:06:56 -07:00
elf.h Check supported DF_1_XXX bits 2012-11-21 06:33:19 -08:00
endian.h Update. 2001-03-30 05:34:59 +00:00
envz.h 2002-08-03 Roland McGrath <roland@redhat.com> 2002-08-04 01:28:06 +00:00
err.h * include/sys/syslog.h: Use libc_hidden_proto for syslog, vsyslog. 2002-08-03 12:59:33 +00:00
errno.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
error.h
execinfo.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
fcntl.h Remove __libc_creat function name. 2014-10-30 19:44:31 +00:00
features.h Update version.h and include/features.h for 2.21 release 2015-02-06 01:40:18 -05:00
fenv.h Fix libm feupdateenv namespace (bug 17748). 2015-01-07 19:01:20 +00:00
fmtmsg.h Add more headers to include/ for conform tests. 2014-12-11 21:41:30 +00:00
fnmatch.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
fpu_control.h
ftw.h
gconv.h
getopt_int.h Update. 2004-03-09 10:36:53 +00:00
getopt.h Update. 2004-03-09 10:36:53 +00:00
glob.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
gmp.h * include/gmp.h: Include/gmp-mparam.h. * stdlib/strtod.c: Include gmp-mparam.h before gmp.h and gmp-impl.h. 2003-03-14 05:48:18 +00:00
gnu-versions.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
grp.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
gshadow.h [BZ #9955] 2009-04-23 18:29:30 +00:00
iconv.h
ifaddrs.h Remove IS_IN_nscd 2014-11-24 11:41:44 +05:30
ifunc-impl-list.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
inline-hashtab.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
langinfo.h Add first fixes for conformtest for POSIX2008 2012-02-26 21:32:56 -05:00
libc-internal.h Define libc_max_align_t for internal use 2015-04-02 19:55:21 +02:00
libc-symbols.h Localplt testing for vector math library and libmvec_hidden_* macro series. 2015-05-25 21:20:20 +03:00
libgen.h
libintl.h Remove use of INTDEF/INTUSE in intl 2012-05-24 23:08:18 +02:00
libio.h Remove use of INTDEF/INTUSE in libio 2012-05-24 23:06:20 +02:00
limits.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
link.h Also use l_tls_dtor_count to decide on object unload (BZ #18657) 2015-07-23 11:16:18 +05:30
list.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
locale.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
malloc.h * malloc/malloc.c (_int_free): Second argument is now mchunkptr. 2009-02-07 22:01:49 +00:00
math.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
mcheck.h * include/sys/resource.h: Use libc_hidden_proto for getpriority, 2002-08-04 03:50:21 +00:00
memory.h
mntent.h Remove use of INTUSE/INTDEF in misc. 2012-05-31 13:10:02 +02:00
monetary.h Add first fixes for conformtest for POSIX2008 2012-02-26 21:32:56 -05:00
mqueue.h Fix mq_receive, mq_send mq_timed* namespace (bug 18545). 2015-06-17 20:19:04 +00:00
netdb.h Fix h_errno namespace (bug 18520). 2015-06-12 10:10:18 +00:00
netgroup.h
nl_types.h
nss.h
nsswitch.h
obstack.h Update. 2002-08-04 09:27:27 +00:00
poll.h
printf.h Update. 2002-08-03 07:02:10 +00:00
pthread.h Fix mq_notify pthread_barrier_* namespace (bug 18544). 2015-06-17 20:16:56 +00:00
pty.h Update. 2004-10-24 21:29:41 +00:00
pwd.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
regex.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
resolv.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
rounding-mode.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
sched.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
scratch_buffer.h Add struct scratch_buffer and its internal helper functions 2015-04-07 11:03:43 +02:00
search.h Fix sem_* tdelete, tfind, tsearch, twalk namespace (bug 18536). 2015-06-17 20:11:58 +00:00
set-hooks.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
setjmp.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
sgtty.h
shadow.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
shlib-compat.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
signal.h Fix scanf15.c testsuite build on sparc. 2015-01-13 11:28:17 -08:00
spawn.h Update. 2000-10-01 19:15:29 +00:00
stab.h
stackinfo.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
stap-probe.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
stdc-predef.h Amendments to Unicode 7 update. 2015-02-23 11:35:24 -03:00
stdio_ext.h Remove use of INTDEF/INTUSE in libio 2012-05-24 23:06:20 +02:00
stdio.h Provide __libc_fatal for rtld. 2015-07-09 15:32:32 -07:00
stdlib.h Remove NOT_IN_libc 2014-11-24 15:03:45 +05:30
string.h Use libc_hidden_proto / libc_hidden_def with __strnlen. 2015-06-02 20:24:25 +00:00
strings.h
stropts.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
stubs-prologue.h * sysdeps/generic/bits/libc-tsd.h [USE___THREAD]: Conditional 2002-10-11 10:52:20 +00:00
syscall.h
sysexits.h
syslog.h
tar.h
termios.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
tgmath.h
time.h Fix symbol definitions for __clock_* functions 2013-06-11 11:11:11 +05:30
ttyent.h Fix ttyslot namespace (bug 18547). 2015-06-17 20:21:19 +00:00
uchar.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
ucontext.h
ulimit.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
unistd.h PLT avoidance for _exit in rtld. 2015-07-09 15:25:47 -07:00
utime.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
utmp.h Remove pre-ISO C support 2012-01-07 23:57:22 -05:00
values.h Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
wchar.h Fix swscanf vswscanf namespace (bug 18542). 2015-06-17 20:15:22 +00:00
wctype.h Fix regex wctype namespace (bug 18495). 2015-06-05 20:04:47 +00:00
wordexp.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
xlocale.h