_dlfcn_hook and SHARED

Carlos O'Donell carlos@systemhalted.org
Fri Aug 8 02:43:00 GMT 2008


On Mon, Jul 21, 2008 at 5:58 PM, Mathieu Lacage
<mathieu.lacage@sophia.inria.fr> wrote:
> while trying to go through the glibc dlfcn/elf source code, I stumbled
> upon the _dlfcn_hook global variable defined in dlfcn/dlerror.c: this
> pointer is initialized to zero (nocommon attribute) and is tested
> extensively at the start of each of the __dlfoo functions for equality
> to NULL when the macro SHARED is defined.
>
> I have, however, been unable to find anywhere this pointer would be
> reset to anything but NULL when SHARED is defined. This begs the
> question: where is _dlfcn_hook ever set to anything but NULL when SHARED
> is defined ?

A statically compiled application will have a copy of all the dl* functions.

If that statically compiled application tries to dlopen a shared
object, there are *may* be two copies of all the dl* functions (and
two copies of the data).

The only way to make this work is to force the newly loaded second
copy of the functions to call back into the static versions.

This song-and-dance allows glibc to support dlopen'd NSS modules from
statically linked applications.

Someone else can correct me if I'm wrong :-)

Cheers,
Carlos.



More information about the Libc-help mailing list