This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Detecting multiple libcs


On 06/03/2016 10:50 AM, Florian Weimer wrote:
> ptmalloc_init has this code:
> 
> #ifdef SHARED
>   /* In case this libc copy is in a non-default namespace, never use brk.
>      Likewise if dlopened from statically linked program.  */
>   Dl_info di;
>   struct link_map *l;
> 
>   if (_dl_open_hook != NULL
>       || (_dl_addr (ptmalloc_init, &di, &l, NULL) != 0
>           && l->l_ns != LM_ID_BASE))
>     __morecore = __failing_morecore;
> #endif
> 
> But it does not seem t work because after a static dlopen, _dl_open_hook is NULL.

Just to be clear, you have verified that the value of _dl_open_hook is NULL
for the copy of that variable in the newly loaded library?

If it is NULL in the newly loaded library (part of the dynamic namespace)
then there is a bug and we need to track it down.

> Is there a way to actually detect this situation? It does not seem to
> be apparent from the way the DT_INIT etc. functions are called.

The above code _should_ work. The static namespace purposely sets _dl_open_hook
in the library it just loaded to notify the library that it has been loaded
by dlopen.

Again, to be clear, the value of _dl_open_hook in the static namespace
remains NULL because it hasn't been loaded by dlopen.

We really want to expand this interface and instead of using just a single
value we want to setup a pointer to a global state structure that has
builtin versioning for ABI purposes, that way we can share more global
state across the static namespace, and dynamic namespaces (dlopen/dlmopen).

It shouldn't be too hard to make _dl_open_hook a pointer to a shared
structure with some internal API around it ;-)

-- 
Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]