Glibc 2.5 - dlsym issue in threaded app.

Carlos O'Donell
Mon Nov 3 20:07:00 GMT 2008

On Fri, Oct 31, 2008 at 11:45 AM, Vitaliy Ivanov
<> wrote:
> So, what I understand is that dlsym when linked with pthreads is calling changed calloc and we enter infinite loop.
> When we are not linking with pthreads is seems like dlsym doesn't call calloc at all.
> Are you aware of this? What is the practice to avoid this endless loop?

You will always have this problem whenever you have a possibly
circular reference e.g. calloc which depends on calloc.

You must break the dependency by providing your own static buffer, and
returning calloc references to that static buffer, for all of the
calloc calls that can possibly be made by the dynamic loader calls
during the resolution of the next calloc symbol. Once you run out of
static calloc space, you can fall back to calling the next calloc
symbol, hopefully by this point all the internal library calloc's will
be handled.

I can see only one calloc reference in libc/dlfcn/dlerror.c
(_dlerror_run), and it allocates ~20 bytes of data. Once that data is
allocated, it won't be allocated again.


More information about the Libc-help mailing list