Question about dlopen load ordering

Jeffrey Walton noloader@gmail.com
Mon Jun 17 22:04:07 GMT 2024


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