Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dlsym(RTLD_NEXT, "msgctl") does not return the default version

Tags:

c

glibc

dlsym

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?

like image 369
Kapil Arya Avatar asked Oct 22 '22 16:10

Kapil Arya


1 Answers

This has been reported as a glibc bug:

  • dlsym(handle, "foo") and dlsym(RTLD_NEXT, "foo") return different result with versioned "foo"

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

like image 115
Florian Weimer Avatar answered Oct 24 '22 10:10

Florian Weimer