freebsd-dev/libexec/rtld-elf
Konstantin Belousov 760e34772c Fix order of destructors between main binary and libraries.
Since inits for the main binary are run from rtld (for some time), the
rtld_exit atexit(3) handler, which is passed from rtld to the program
entry and installed by csu, is installed after any atexit(3) handlers
installed by main binary constructors.  This means that rtld_exit() is
fired before main binary handlers.

Typical C++ static constructors are executed from init (either binary
or libs) but use atexit(3) to ensure that destructors are called in
the right order, independent of the linking order.  Also, C++
libraries finalizers call __cxa_finalize(3) to flush library'
atexit(3) entries.  Since atexit(3) entry is cleared after being run,
this would be mostly innocent, except that, atexit(rtld_exit) done
after main binary constructors, makes destructors from libraries
executed before destructors for main.

Fix by reordering atexit(rtld_exit) before inits for main binary, same
as it happened when inits were called by csu.  Do it using new private
libc symbol with pre-defined ABI.

Reported. tested, and reviewed by:	kan
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2019-04-15 13:03:09 +00:00
..
aarch64 Improve R_AARCH64_TLSDESC relocation. 2018-12-15 10:38:07 +00:00
amd64 Improve R_AARCH64_TLSDESC relocation. 2018-12-15 10:38:07 +00:00
arm rtld: attempt to fix reloc_nonplt_object TLS allocation 2019-03-29 14:35:23 +00:00
i386 rtld: pacify -Wmaybe-uninitialized from gcc6 2019-02-01 23:16:59 +00:00
mips rtld: attempt to fix reloc_non_plt TLS allocation on MIPS 2019-03-29 15:07:00 +00:00
powerpc Improve R_AARCH64_TLSDESC relocation. 2018-12-15 10:38:07 +00:00
powerpc64 Fix rtld-elf compilation warning for powerpc64 ELFv2 ABI 2019-01-13 02:33:20 +00:00
riscv Improve R_AARCH64_TLSDESC relocation. 2018-12-15 10:38:07 +00:00
sparc64 Improve R_AARCH64_TLSDESC relocation. 2018-12-15 10:38:07 +00:00
tests Fix regression tests broken by r337067. 2018-08-02 11:55:16 +00:00
debug.c libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
debug.h ld-elf.so: make LD_DEBUG always functional. 2019-04-14 18:04:53 +00:00
libmap.c rtld-elf: fix more warnings to allow compiling with WARNS=6 2018-10-29 21:08:28 +00:00
libmap.conf Move libmap.conf to libexec/rtld-elf/ 2018-09-18 00:25:00 +00:00
libmap.h rtld-elf: make it compile with WARNS=3 2018-10-29 21:08:11 +00:00
Makefile ld-elf.so: make LD_DEBUG always functional. 2019-04-14 18:04:53 +00:00
Makefile.depend new depends 2015-06-16 23:37:19 +00:00
map_object.c Remove Obj_Entry textsize member. 2018-11-04 00:32:28 +00:00
paths.h rtld-elf: compile with WANRS=4 warnings other than -Wcast-align 2018-10-29 21:08:19 +00:00
rtld_lock.c rtld-elf: fix more warnings to allow compiling with WARNS=6 2018-10-29 21:08:28 +00:00
rtld_lock.h libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
rtld_malloc.c Rename rtld-elf/malloc.c to rtld-elf/rtld_malloc.c. 2019-01-30 16:28:27 +00:00
rtld_malloc.h Add header file missed in r343564. 2019-01-29 22:45:24 +00:00
rtld_printf.c rtld-elf: fix more warnings to allow compiling with WARNS=6 2018-10-29 21:08:28 +00:00
rtld_printf.h libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
rtld_tls.h libexec: adoption of SPDX licensing ID tags. 2017-11-27 15:25:02 +00:00
rtld_utrace.h Renumber copyright clause 4 2017-02-28 23:42:47 +00:00
rtld.1 Add serial comma. 2017-09-01 16:56:37 +00:00
rtld.c Fix order of destructors between main binary and libraries. 2019-04-15 13:03:09 +00:00
rtld.h Fix initial exec TLS mode for dynamically loaded shared objects. 2019-03-29 17:52:57 +00:00
Symbol.map Add rtld private interface for dso to detect dynamic loading 2015-01-03 18:09:53 +00:00
xmalloc.c Adjust posix symbols from rtld-elf/malloc.c with the __crt_ prefix. 2019-01-29 22:40:42 +00:00