dynamic-linkingdlopendlsym

What are the scoping rules for subsequent calls to dlopen?


Suppose I have an executable that dlopens libfirst.so with RTLD_LOCAL which then dlopens libsecond.so with RTLD_GLOBAL. Should the symbols from libsecond.so now be directly available (i.e., without dlsym) in (1) only libfirst.so or (2) in both libfirst.so and the executable?

From the manpage on dlopen

RTLD_GLOBAL: The symbols defined by this shared object will be made available for symbol resolution of subsequently loaded shared objects.

This sounds like the symbols from libsecond.so are not made available to either the executable or libfirst.so (except via dlsym). Is this correct?


Solution

  • Should the symbols from libsecond.so now be directly available (i.e., without dlsym) in (1) only libfirst.so or (2) in both libfirst.so and the executable?

    I don't think you understand what "directly available" means in this context.

    Suppose libsecond.so defines second(). That symbol is not available in either libfirst.so or the main a.out (obviously -- they have been already loaded before libsecond.so was brought in).

    But if you now load (via dlopen()) libthird.so, and if that library has second() as an unresolved symbol (in other words, libthird.so has a direct dependency on second()), the load of libthird.so would succeed if libsecond.so was loaded with RTLD_GLOBAL, but would fail (with unresolved second()) if libsecond.so was loaded with RTLD_LOCAL.