git: rtld: Add main object initialization and finalization

John Marino marino at
Sat Mar 17 19:19:30 PDT 2012

commit 7f5c8f9721216c496b54eff209b96f6f5f6bd189
Author: John Marino <draco at>
Date:   Sat Mar 17 19:52:17 2012 +0100

    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
    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.

Summary of changes:
 libexec/rtld-elf/Makefile              |    1 +
 libexec/rtld-elf/i386/rtld_machdep.h   |    4 +-
 libexec/rtld-elf/map_object.c          |   13 ++++
 libexec/rtld-elf/rtld.c                |  109 +++++++++++++++++++++++--------
 libexec/rtld-elf/rtld.h                |   10 +++-
 libexec/rtld-elf/x86_64/rtld_machdep.h |    4 +-
 6 files changed, 108 insertions(+), 33 deletions(-)

DragonFly BSD source repository

More information about the Commits mailing list