Question about dlopen load ordering
Caslyn Tonelli
caslyn.tonelli@gmail.com
Tue Jun 18 18:11:26 GMT 2024
Oh - great! Thanks Jeff. I see the concept of global/local scopes and how
they affect the ordering for symbol lookups. The paper doesn't name this
specifically, but provides enough examples and explanations that I've
concluded that without any exception flags (RTLD_GLOBAL, etc), the local
scope ordering is not affected if a dependency was loaded by a previous
dlopen call. This matches what I see in LD_DEBUG logs for dlopen behavior.
On Mon, Jun 17, 2024 at 3:04 PM Jeffrey Walton <noloader@gmail.com> wrote:
> On Mon, Jun 17, 2024 at 5:46 PM Caslyn Tonelli via Libc-help
> <libc-help@sourceware.org> wrote:
> >
> > I’m hoping someone could help clarify the load ordering semantics of
> > glibc’s dlopen for a specific scenario:
> >
> > multiple-foo-deps.so has the following DT_NEEDEDs in this order:
> >
> > - libfoo-v1.so where foo() returns 2
> >
> > - libfoo-v2.so where foo() returns 7
> >
> > If I perform the following steps:
> > 1. dlopen(“libfoo-v2.so”, RTLD_NOW | RTLD_LOCAL);
> > 2. dlopen(“multiple-foo-deps.so”, RTLD_NOW | RTLD_LOCAL);
> >
> > What would be the value of the resolved `foo()` from
> “multiple-foo-deps.so
> > ”?
> >
> > Based on POSIX documentation, I would expect the value to be 7 since “
> > libfoo-v2.so” was already loaded. However, my tests are showing that the
> > dependency order is prioritized and the foo symbol is resolved from “
> > libfoo-v1.so”. Is that right? Would someone be able to explain the
> > reasoning around this?
> >
> > Let me know if I can clarify anything or provide a reproducer.
>
> I think the best written docs that would explain the behavior for
> Linux is Drepper's How To Write Shared Libraries,
> <https://www.akkadia.org/drepper/dsohowto.pdf>. (Or it was in the
> past). See section 1.5, Startup in the Dynamic Linker.
> Jeff
>
More information about the Libc-help
mailing list