Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 08 Nov 2002 16:25:45 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Daniel Eischen <eischen@pcnet1.pcnet.com>
Cc:        "M. Warner Losh" <imp@bsdimp.com>, ataraxia@cox.net, current@FreeBSD.ORG
Subject:   Re: [PATCH] note the __sF change in src/UPDATING
Message-ID:  <3DCC5609.C21E3AA0@mindspring.com>
References:  <Pine.GSO.4.10.10211081904490.10745-100000@pcnet1.pcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Daniel Eischen wrote:
> I'm not even close to a shared library/linker expert, but
> I thought there was a way to have something run when an
> object file got loaded.  From rtld(1):
> 
>   After all shared libraries have been successfully loaded, ld-elf.so.1
>   proceeds to resolve external references from both the main program and
>   all objects loaded. A mechanism is provided for initialization routines
>   to be called on a per-object basis, giving a shared object an opportunity
>   to perform any extra set-up before execution of the program proper
>   begins.  This is useful for C++ libraries that contain static construc-
>   tors.
> 
> If you put __sF in it's own file with whatever is needed for
> the above, won't that work?

The key to this is "on a per object basis".

You only get one .init section, and if you provide your own,
then the generated one is ignored and not used.  This only
becomes a problem when you try to use Objective C or C++
code linked against the library, but at that point, it becomes
a critical problem; example:

static void _dl_init(void) __attribute__((section(".init")));
   
static void
_dl_init(void)
{
        char    *argv [2] = {
                "./xxx",
                NULL
        };
        __do_dynamic_link( argv);
}

This is code from my "libdlopen" that tries to work around the
problem with the argv parameter not being passed down to the
dynamic linker initialization.  It uses the .init section, since
the constructor code is not properly called with a non-void
argument, and the constructor code is c++rt0 instead of crt0,
so it's not universally called (an artifact of static linking).

The "which is dangerous"/"which is stupid" messages are actually
ld.so hacks, or other linker hacks to do with symbol resolution,
rather than compile-time things

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3DCC5609.C21E3AA0>