rtld: Add main object initialization and finalization
authorJohn Marino <draco@marino.st>
Sat, 17 Mar 2012 18:52:17 +0000 (19:52 +0100)
committerJohn Marino <draco@marino.st>
Sun, 18 Mar 2012 02:11:56 +0000 (03:11 +0100)
commit7f5c8f9721216c496b54eff209b96f6f5f6bd189
tree7fd475eac39c41510b6ed7667898b668031427b9
parent79dc5732ea6dc3ae0afe6a30136cad1d23d5a74a
rtld: Add main object initialization and finalization

Since DragonFly's inception, crt1 has called _init and _fini functions of
the binary rather than leaving this task to the runtime linker.  Likely
this was done in order to use the same crt code for both statically and
dynamically linked binaries.

When FreeBSD imported DragonFly's preinit, init, and fini array handling
code, they moved the _init and _fini calls to rtld.  In order for rtld to
maintain compatiblity with binaries created with crt code that call these
functions, rtld looks for an ELF note that indicates the binary was built
with a crt that does not call _init and _fini.

This commit imports this capability as well as synchronizes some of the
changes FreeBSD made to the DragonFly code.  Many of the differences
weren't necessary, but some represented improvements.  In any case, it
benefits both operating systems to minimize the differences between the
runtime linkers in order to continue to collaborate and share new
features.

Taken from: FreeBSD SVN 232831 (2012-03-11)

One key difference between the DragonFly and FreeBSD implementations is
that FreeBSD will not properly execute a binary that requires
initialization and/or finalization if the PT_NOTE program header is
intentionally omitted using a custom linker script and the PHDRS
directive.  In the same case, DragonFly will look to see if the main
binary contains a gnu hash dynamic tag.  If it does, it assumes the binary
was built with the new crt, which is a very good assumption.  Since gnu
hash was inserted by default into binaries only a week ago, there's only
a window of few days where this isn't true, and PT_NOTE-free binaries are
very rare.
libexec/rtld-elf/Makefile
libexec/rtld-elf/i386/rtld_machdep.h
libexec/rtld-elf/map_object.c
libexec/rtld-elf/rtld.c
libexec/rtld-elf/rtld.h
libexec/rtld-elf/x86_64/rtld_machdep.h