glibc/include
Pavel Kopyl 02d5e5d94a Add forced deletion support to _dl_close_worker
https://sourceware.org/bugzilla/show_bug.cgi?id=17833

I've a shared library that contains both undefined and unique symbols.
Then I try to call the following sequence of dlopen:

1. dlopen("./libfoo.so", RTLD_NOW)
2. dlopen("./libfoo.so", RTLD_LAZY | RTLD_GLOBAL)

First dlopen call terminates with error because of undefined symbols,
but STB_GNU_UNIQUE ones set DF_1_NODELETE flag and hence block library
in the memory.

The library goes into inconsistent state as several structures remain
uninitialized. For instance, relocations for GOT table were not performed.

By the time of second dlopen call this library looks like as it would be
fully initialized but this is not true: any call through incorrect GOT
table leads to segmentation fault.  On some systems this inconsistency
triggers assertions in the dynamic linker.

This patch adds a parameter to _dl_close_worker to implement forced object
deletion in case of dlopen() failure:

1. Clears DF_1_NODELETE bit if forced, to allow library to be removed from
memory.
2. For each unique symbol that is defined in this object clears
appropriate entry in _ns_unique_sym_table.

	[BZ #17833]
	* elf/Makefile (tests): Add tst-nodelete.
	(modules-names): Add tst-nodelete-uniquemod.
	(tst-nodelete-uniquemod.so-no-z-defs): New.
	(tst-nodelete-rtldmod.so-no-z-defs): Likewise.
	(tst-nodelete-zmod.so-no-z-defs): Likewise.
	($(objpfx)tst-nodelete): Likewise.
	($(objpfx)tst-nodelete.out): Likewise.
	(LDFLAGS-tst-nodelete): Likewise.
	(LDFLAGS-tst-nodelete-zmod.so): Likewise.
	* elf/dl-close.c (_dl_close_worker): Add a parameter to
	implement forced object deletion.
	(_dl_close): Pass false to _dl_close_worker.
	* elf/dl-open.c (_dl_open): Pass true to _dl_close_worker.
	* elf/tst-nodelete.cc: New file.
	* elf/tst-nodeletelib.cc: Likewise.
	* elf/tst-znodeletelib.cc: Likewise.
	* include/dlfcn.h (_dl_close_worker): Add a new parameter.
2015-07-07 11:06:56 -07:00
..
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 (abmon): Remove spaces. 1998-11-12 18:03:43 +00:00
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 Update. 1998-04-10 10:52:25 +00:00
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 Update. 1998-03-24 10:39:42 +00:00
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 Update. 1997-06-21 02:59:26 +00:00
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 Update. 1999-11-23 17:22:17 +00:00
ftw.h Update. 1997-06-21 02:59:26 +00:00
gconv.h Update. 1997-11-18 02:50:07 +00:00
getopt.h Update. 2004-03-09 10:36:53 +00:00
getopt_int.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 Update. 1999-08-21 00:38:15 +00:00
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 Update. 1997-06-21 02:59:26 +00:00
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 Update copyright dates with scripts/update-copyrights. 2015-01-02 16:29:47 +00:00
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 Update. 1997-06-21 02:59:26 +00:00
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 Update. 1997-06-21 02:59:26 +00:00
nl_types.h Update. 1997-12-22 20:53:38 +00:00
nss.h Update. 1997-06-21 02:59:26 +00:00
nsswitch.h Update. 1997-06-21 02:59:26 +00:00
obstack.h Update. 2002-08-04 09:27:27 +00:00
poll.h Update. 2000-08-21 16:02:48 +00:00
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 Update. 1997-06-21 02:59:26 +00:00
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 Update. 1997-06-21 02:59:26 +00:00
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.h Fix getpass fflush_unlocked namespace (bug 18540). 2015-06-17 20:14:18 +00:00
stdio_ext.h Remove use of INTDEF/INTUSE in libio 2012-05-24 23:06:20 +02: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 Update. 1997-06-21 02:59:26 +00:00
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 Update. 1997-06-21 02:59:26 +00:00
sysexits.h Update. 1997-06-21 02:59:26 +00:00
syslog.h Update. 1997-06-21 02:59:26 +00:00
tar.h Update. 1997-06-21 02:59:26 +00:00
termios.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
tgmath.h Update. 1998-09-06 23:45:24 +00:00
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 Update. 1999-10-12 18:17:41 +00:00
ulimit.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
unistd.h Fix getlogin_r namespace (bug 18527). 2015-06-12 20:02:30 +00: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 Update. 1997-06-21 02:59:26 +00:00