rtld: Add support for preinit, init, and fini arrays
authorJohn Marino <draco@marino.st>
Sat, 11 Feb 2012 19:17:51 +0000 (20:17 +0100)
committerJohn Marino <draco@marino.st>
Sat, 11 Feb 2012 20:04:12 +0000 (21:04 +0100)
commitb28bf640312db2b299faff75052fbb01d67fd821
treedfe3bcd6f36207d7c6726c60cc2eb550035609f4
parent855657c51085a8e5060d19cbd5d7fd3799831479
rtld: Add support for preinit, init, and fini arrays

As far as I can tell, all BSDs limit their ELF executable file
initialization and termination to the .init and .fini sections.  In
contrast, Linux has additionally supported the .preinit_array,
.init_array, and .fini_array sections for over a decade through glibc.
With this commit, DragonFly becomes the first BSD to support these
arrays of function pointers.  It was tested using test cases taken from
glibc, gnu ld linker, and the gold linker.

For the main executable file, the .init_array and .fini_array sections
are handled by crt1, just like .init and .fini are.  In the case of
a statically linked binary, the .preinit_array section is also handled
by crt1.  The real-time linker handles the .init_array and .fini_array
sections for dynamically shared objects (libraries) and .preinit_array
for dynamically-linked binaries.  There are no .preinit_array sections
in the DSOs per standard.

These sections are described by the System V Application Binary Interface
http://www.sco.com/developers/gabi/latest/ch4.sheader.html#special_sections

The .init_array and .fini_array handling by rtld was reviewed by
Konstantin Belousov.
lib/csu/i386/crt1_c.c
lib/csu/x86_64/crt1.c
libexec/rtld-elf/i386/rtld_machdep.h
libexec/rtld-elf/rtld.c
libexec/rtld-elf/rtld.h
libexec/rtld-elf/x86_64/rtld_machdep.h