Question

If a library defines multiple version of the same symbol, dlsym(RTLD_NEXT, "symbol") returns the older symbol even though the older symbol is not the default symbol.

For example, libpthread defines two versions of pthread_cond_broadcast:

$:> nm -g /lib64/libpthread-2.15.so|grep pthread_cond_broadcast
000000000000bfc0 T pthread_cond_broadcast@@GLIBC_2.3.2
000000000000c310 T pthread_cond_broadcast@GLIBC_2.2.5
  • "GLIBC_2.3.2" is the default version that you get when linking with libpthread (without any dlsym involvement). (Notice the "@@" which signifies the default symbol)
  • "GLIBC_2.2.5" is an older version

Now, if I use dlsym(RTLD_NEXT, "pthread_cond_broadcast"), I always get the GLIBC_2.2.5 version and not the GLIBC_2.3.2 version. Of course one can use dlvsym to get the default version, but that gets complicated if one needs to do it for a large number of symbols and a lot of them have different new/old versions.

I do understand that RTLD_NEXT shouldn't always return the latest symbol to maintain compatibility, but why not return the default symbol?

Does anyone know about the rationale behind this?

Was it helpful?

Solution

This has been reported as a glibc bug:

As far as I know, it has not been fixed yet.

OTHER TIPS

The whole point of RTLD_NEXT is to return the symbol after the first, default one. Aren't you just looking for RTLD_DEFAULT?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top