glibc/include
Florian Weimer 6985865bc3 elf: Always call destructors in reverse constructor order (bug 30785)
The current implementation of dlclose (and process exit) re-sorts the
link maps before calling ELF destructors.  Destructor order is not the
reverse of the constructor order as a result: The second sort takes
relocation dependencies into account, and other differences can result
from ambiguous inputs, such as cycles.  (The force_first handling in
_dl_sort_maps is not effective for dlclose.)  After the changes in
this commit, there is still a required difference due to
dlopen/dlclose ordering by the application, but the previous
discrepancies went beyond that.

A new global (namespace-spanning) list of link maps,
_dl_init_called_list, is updated right before ELF constructors are
called from _dl_init.

In dl_close_worker, the maps variable, an on-stack variable length
array, is eliminated.  (VLAs are problematic, and dlclose should not
call malloc because it cannot readily deal with malloc failure.)
Marking still-used objects uses the namespace list directly, with
next and next_idx replacing the done_index variable.

After marking, _dl_init_called_list is used to call the destructors
of now-unused maps in reverse destructor order.  These destructors
can call dlopen.  Previously, new objects do not have l_map_used set.
This had to change: There is no copy of the link map list anymore,
so processing would cover newly opened (and unmarked) mappings,
unloading them.  Now, _dl_init (indirectly) sets l_map_used, too.
(dlclose is handled by the existing reentrancy guard.)

After _dl_init_called_list traversal, two more loops follow.  The
processing order changes to the original link map order in the
namespace.  Previously, dependency order was used.  The difference
should not matter because relocation dependencies could already
reorder link maps in the old code.

The changes to _dl_fini remove the sorting step and replace it with
a traversal of _dl_init_called_list.  The l_direct_opencount
decrement outside the loader lock is removed because it appears
incorrect: the counter manipulation could race with other dynamic
loader operations.

tst-audit23 needs adjustments to the changes in LA_ACT_DELETE
notifications.  The new approach for checking la_activity should
make it clearer that la_activty calls come in pairs around namespace
updates.

The dependency sorting test cases need updates because the destructor
order is always the opposite order of constructor order, even with
relocation dependencies or cycles present.

There is a future cleanup opportunity to remove the now-constant
force_first and for_fini arguments from the _dl_sort_maps function.

Fixes commit 1df71d32fe ("elf: Implement
force_first handling in _dl_sort_maps_dfs (bug 28937)").

Reviewed-by: DJ Delorie <dj@redhat.com>
2023-09-08 12:34:27 +02:00
..
arpa Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
bits misc/bits/syslog.h: Clearly separate declaration from definition 2023-07-05 16:59:48 +02:00
gnu Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
net Fix resolver if_* namespace (bug 17717). 2014-12-16 18:18:49 +00:00
netinet nss_files: Consolidate line parse declarations in <nss_files.h> 2020-07-21 07:33:20 +02:00
programs Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
protocols (abmon): Remove spaces. 1998-11-12 18:03:43 +00:00
rpc Handle out-of-memory case in svc_tcp.c/svc_unix.c:rendezvous_request. 2020-12-10 11:11:20 +01:00
rpcsvc Remove --enable-obsolete-nsl configure flag 2020-07-08 17:25:57 +02:00
sys misc/bits/syslog.h: Clearly separate declaration from definition 2023-07-05 16:59:48 +02:00
aio.h Linux: Move aio_suspend, aio_suspend64, __aio_suspend_time64 to libc 2021-06-25 11:55:27 +02:00
aliases.h Remove --enable-obsolete-nsl configure flag 2020-07-08 17:25:57 +02:00
alloc_buffer.h Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
alloca.h Remove macros extend_alloca, extend_alloca_account [BZ #18023] 2018-06-27 19:20:37 +02:00
allocate_once.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
ar.h Add missing header wrappers under include/ 2019-02-16 08:25:16 +01:00
argp-fmtstream.h Mark internal argp functions with attribute_hidden [BZ #18822] 2017-10-01 15:10:27 -07:00
argp.h ldbl-opt: Add argp_error and argp_failure (bug 23983) 2019-03-01 15:21:32 -03:00
argz.h Use libc_hidden_* for argz_next, __argz_next (bug 15105). 2018-02-15 21:00:02 +00:00
array_length.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
assert.h assert: Do not use stderr in libc-internal assert 2022-08-03 11:43:04 +02:00
atomic_wide_counter.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
atomic.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
byteswap.h Update. 1998-04-10 10:52:25 +00:00
clone_internal.h posix: Add pidfd_spawn and pidfd_spawnp (BZ 30349) 2023-09-05 13:08:59 -03:00
complex.h float128: Add private _Float128 declarations for libm. 2017-05-15 10:23:28 -03:00
cpio.h Add more headers to include/ for conform tests. 2014-12-11 21:41:30 +00:00
crypt.h Add include/crypt.h. 2016-10-28 22:40:16 -04:00
ctype.h Use libc_hidden_* for tolower, toupper (bug 15105). 2018-02-23 13:54:53 +00:00
des.h Update. 1998-03-24 10:39:42 +00:00
dirent.h Use 64 bit time_t stat internally 2021-06-22 12:09:52 -03:00
dlfcn.h elf: Add _dl_find_object function 2021-12-28 22:52:56 +01:00
dso_handle.h Mark __dso_handle as hidden [BZ #18822] 2017-09-26 16:53:44 -07:00
elf.h elf: Refuse to dlopen PIE objects [BZ #24323] 2019-06-18 16:42:10 +02:00
endian.h Update. 2001-03-30 05:34:59 +00:00
envz.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
err.h ldbl-128ibm-compat: PLT redirects for using ldbl redirects internally 2020-03-25 14:34:23 -05:00
errno.h Remove tls.h inclusion from internal errno.h 2020-11-13 12:59:19 -03:00
error.h Mark various cold functions as __COLD 2023-05-01 19:33:21 +02:00
execinfo.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
fcntl.h Fix Linux fcntl OFD locks for non-LFS architectures (BZ#20251) 2018-06-26 13:22:53 -03:00
features-time64.h y2038: Add support for 64-bit time on legacy ABIs 2021-06-15 10:42:11 -03:00
features.h Increase version numbers 2023-07-30 21:35:28 +02:00
fenv.h Move fenv.h soft-float inlines from fenv_private.h to include/fenv.h. 2018-09-04 19:52:06 +00:00
file_change_detection.h Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
filename.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
float.h Make totalorder and totalordermag functions take pointer arguments. 2019-08-15 15:18:34 +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 Hide internal __setfpucw function [BZ #18822] 2017-10-01 17:52:15 -07:00
fstab.h Add missing header wrappers under include/ 2019-02-16 08:25:16 +01:00
fts.h io: Add fts64 with 64-bit time_t support 2021-06-15 10:42:11 -03:00
ftw.h io: Add ftw64 with 64-bit time_t support 2021-06-15 10:42:11 -03:00
gconv.h Update. 1997-11-18 02:50:07 +00:00
getopt_int.h Update. 2004-03-09 10:36:53 +00:00
getopt.h getopt: remove USE_NONOPTION_FLAGS 2017-04-07 07:45:53 -04:00
glob.h Fix extra PLT reference in libc.so due to __glob64_time64 if build with gcc 7.5 on 32bit. 2021-07-01 16:46:59 +02:00
gmp.h Apply asm redirection in gmp.h before first use 2022-11-07 10:40:21 -03:00
gnu-versions.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
grp-merge.h NSS: Implement group merging support. 2016-04-29 22:18:21 -04:00
grp.h nss_files: Consolidate line parse declarations in <nss_files.h> 2020-07-21 07:33:20 +02:00
gshadow.h nss_files: Consolidate line parse declarations in <nss_files.h> 2020-07-21 07:33:20 +02:00
iconv.h Update. 1999-08-21 00:38:15 +00:00
idx.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
ifaddrs.h nscd: Do not rebuild getaddrinfo (bug 30709) 2023-08-11 10:10:16 +02:00
ifreq.h Hide internal __ifreq function [BZ #18822] 2017-10-01 17:35:46 -07:00
ifunc-impl-list.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
inline-hashtab.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
intprops.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
inttypes.h Make strtoimax, strtoumax, wcstoimax, wcstoumax into aliases 2020-12-08 18:15:27 +00:00
langinfo.h Add first fixes for conformtest for POSIX2008 2012-02-26 21:32:56 -05:00
lastlog.h Add missing header wrappers under include/ 2019-02-16 08:25:16 +01:00
libc-diag.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
libc-internal.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
libc-pointer-arith.h Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
libc-symbols.h Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
libgen.h Update. 1997-06-21 02:59:26 +00:00
libintl.h Document the internal _ and N_ macros 2020-05-06 17:35:40 +02:00
limits.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
link.h elf: Always call destructors in reverse constructor order (bug 30785) 2023-09-08 12:34:27 +02:00
list_t.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
list.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
locale.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
loop_unroll.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
malloc.h Simplify __malloc_initialized 2021-07-22 18:38:04 +05:30
math-narrow-eval.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
math.h Redirect fma calls to __fma in libm 2021-09-15 22:57:35 +00:00
mcheck.h mcheck: Wean away from malloc hooks [BZ #23489] 2021-07-22 18:38:02 +05:30
memory.h Update. 1997-06-21 02:59:26 +00:00
mntent.h Hide internal __hasmntopt function [BZ #18822] 2017-10-01 17:37:42 -07:00
monetary.h Rename __LONG_DOUBLE_USES_FLOAT128 to __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI 2020-04-30 08:52:08 -05:00
mqueue.h Linux: Move mq_send, mq_timedsend, __mq_timedsend_time64 to libc 2021-06-25 12:21:12 +02:00
netdb.h nss_files: Move into libc 2021-07-07 18:33:52 +02: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_dns.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
nss_files.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
nss.h nss: Export nscd hash function as __nss_hash [BZ #22459] 2017-11-23 14:08:11 +01:00
nsswitch.h Update. 1997-06-21 02:59:26 +00:00
obstack.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
plural-exp.h Hide internal __gettextparse function [BZ #18822] 2017-10-01 17:31:05 -07:00
poll.h Update. 2000-08-21 16:02:48 +00:00
printf_buffer.h Fix all the remaining misspellings -- BZ 25337 2023-06-02 01:39:48 +00:00
printf.h stdio-common: Convert vfprintf and related functions to buffers 2022-12-19 18:56:54 +01:00
pthread.h Linux: Move mq_notify from librt to libc 2021-06-25 12:20:47 +02:00
pty.h login: Move libutil into libc 2021-06-30 08:43:37 +02:00
pwd.h nss_files: Consolidate line parse declarations in <nss_files.h> 2020-07-21 07:33:20 +02:00
random-bits.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
re_comp.h Add missing header wrappers under include/ 2019-02-16 08:25:16 +01:00
regex.h Fix regex type usage 2023-05-01 09:08:59 -04:00
regexp.h Add missing header wrappers under include/ 2019-02-16 08:25:16 +01:00
register-atfork.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
resolv.h resolv: Add internal __res_binary_hnok function 2022-08-30 10:02:49 +02:00
rounding-mode.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
rtld-malloc.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
sched.h Add hidden prototypes for __sched_getparam, __sched_getscheduler 2020-02-20 08:57:01 +01:00
scratch_buffer.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
search.h misc: Add twalk_r function 2019-05-02 11:42:51 +02:00
set-freeres.h Fix a few more typos I missed in previous round -- BZ 25337 2023-06-02 23:46:32 +00:00
setjmp.h chk: Add and fix hidden builtin definitions for *_chk 2023-08-03 22:46:48 +02:00
sgtty.h Update. 1997-06-21 02:59:26 +00:00
shadow.h nss_files: Consolidate line parse declarations in <nss_files.h> 2020-07-21 07:33:20 +02:00
shlib-compat.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
shm-directory.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
signal.h stdio: Remove the usage of $(fno-unit-at-a-time) for siglist.c 2022-05-13 10:54:41 -03:00
spawn.h posix: Use posix_spawn for wordexp 2019-10-09 17:48:41 -03:00
stab.h Update. 1997-06-21 02:59:26 +00:00
stackinfo.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
stap-probe.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
stdc-predef.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
stdint.h Move inttypes.h and stdint.h to stdlib. 2019-03-13 09:42:09 -04:00
stdio_ext.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
stdio.h stdio: Ensure *_chk routines have their hidden builtin definition available 2023-07-05 16:59:48 +02:00
stdlib.h __call_tls_dtors: Use call_function_static_weak 2023-09-04 20:03:37 +02:00
string.h chk: Add and fix hidden builtin definitions for *_chk 2023-08-03 22:46:48 +02:00
strings.h Update. 1997-06-21 02:59:26 +00:00
struct___timeb64.h time: Add 64-bit time_t support for ftime 2020-10-27 09:54:50 -03:00
struct___timespec64.h y2038: include: Move struct __timespec64 definition to a separate file 2020-04-06 23:05:11 +02:00
struct___timeval64.h y2038: include: Move struct __timeval64 definition to a separate file 2020-05-05 19:36:25 +02: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 Hide internal __tcgetattr function [BZ #18822] 2017-10-01 17:48:24 -07:00
tgmath.h Update. 1998-09-06 23:45:24 +00:00
time.h Define in_int32_t_range to check if the 64 bit time_t syscall should be used 2022-11-17 14:35:13 -03:00
ttyent.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04: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_ext.h Move {read,write}_all functions to a dedicated header 2023-06-06 08:23:53 -04:00
unistd.h unistd: Avoid PLT entries with _FORTIFY_SOURCE 2023-07-05 16:59:48 +02:00
utime.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
utmp.h login: Move libutil into libc 2021-06-30 08:43:37 +02:00
values.h Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
verify.h posix: Sync regex with gnulib 2019-11-06 09:20:52 -03:00
wait.h Add missing header wrappers under include/ 2019-02-16 08:25:16 +01:00
wchar.h wchar: Avoid PLT entries with _FORTIFY_SOURCE 2023-07-05 16:59:48 +02:00
wctype.h Remove __need macros from stdio.h and wchar.h. 2017-06-08 13:58:17 -04:00
wordexp.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00