DragonFly added support for ELF preinit, init, and fini arrays

Konstantin Belousov kostikbel at gmail.com
Sun Feb 19 18:26:53 UTC 2012


On Sun, Feb 19, 2012 at 09:03:00AM +0100, John Marino wrote:
> On 2/18/2012 10:38 PM, Konstantin Belousov wrote:
> >
> >Thank you, it was very useful. It seems that test4 needed some adjustments
> >to actually provide the required dso for tests.
> Yeah.  I thought I gave you a version that worked out of the box but I 
> did modify this test as well.
> 
> >Now, the patch at http://people.freebsd.org/~kib/misc/init_array.2.patch
> >passes your tests and allows to boot world built with pre-patched csu
> >into multiuser mode.
> >
> >I decided to move the calls to initializers for main binary into rtld,
> >and used the brand note to distinguish old and new csu.
> I assume the purpose of this is to have a clean split with static 
> initialization done in crt1 and dynamic initialization done entirely in 
> rtld for binaries built with version 100009 and later.  Does the note 
> digestion used to check osrel add significant overhead?
I do not think that note parsing can add any measureable overhead.

The goal there is not to have some theoretical cleaness, but to cause
the least possible bug propagation. The crt code gets linked into the
binary, be it static or dynamic. We cannot help the static case, but for
dynamic one, less non-application code is stored in the binary, the bigger
our possibilities to deliver fixes for OS bugs without requiring application
recompilation.

From this POV, having the preinit array/init/array init linked into the
binary is quite bad.
> 
> Is not this information already available via aux_vectors passed on from 
> imgact_elf.c?
No.

After thinking about the init_array.3 patch which uses __FreeBSD_version
of the crt to distinguish old and new crt, I understood that this change
is very hard to merge to stable branch. In essence, we would ship some
rtld's in HEAD which will misbehave on stable binaries, if the change
is merged back.

So I decided to redo this once more, adding a vendor note that signifies
that crt does not call init.

See http://people.freebsd.org/~kib/misc/init_array.4.patch
> 
> >
> >ATM patch is only for i386 and amd64, I will port to other architectures
> >after some feedback.
> It's out of scope of your current work but related to notes, but there's 
> another test that DragonFly passes that FreeBSD fails.  If memory 
> serves, it was caused by the PT_NOTE segment getting located outside of 
> the first page the majority of the time starting with binutils 2.21.
> http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/9d35f29fb5dd669d4e04521b39296e5bdf14b2b0
> 
> A related problem was an interpret segment outside of the first page:
> http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/99aed3e43ef052664173110d6db3ddf6a62e375b
> 
> Both of these were handled within sys/kern/imgact_elf.c

The fact that interpreter path and notes should be placed at the first
page of ELF image is well-known ELF quirk, possibly not well documented.
There is indeed an issue with crtbrand.c unable to create a proper section
for the note, see the long comment in recent crtbrand.c.

FreeBSD solution was to emit right section type.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-toolchain/attachments/20120219/2019c80f/attachment.pgp


More information about the freebsd-toolchain mailing list