Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dlclose() not unloading dynamic library

652 views
Skip to first unread message

jois.d...@gmail.com

unread,
Apr 4, 2008, 3:02:19 PM4/4/08
to
I have a perplexing problem that I'm having trouble finding much
information on.

I've developed a dynamic library as an extension to an existing
application. I load this library at runtime when the application
starts, and I have created a function that will unload (using
dlclose()) and load it (dlopen()) whenever I want to update the
working version of the library without having to take the application
down.

However, I'm finding that dlclose() does not unload the library, and
as such, when I call dlopen() again I get the same stale handle.
Calling dlclose() once does not return an error. Calling dlclose()
twice returns with an error on the second attempt, with dlerror()
saying "shared object not open". A subsequent call to dlopen()
should theoretically load the new, changed library, but I find that
the same pointer is returned as the one that was just closed (and this
is confirmed by the fact that none of my changes take effect). Doing
an ldconfig between loads does not seem to have any effect.

Oddly enough, if, after the first load I delete the shared object
entirely from the filesystem, call dlclose until it says "shared
object not open" and then call dlopen() again, it somehow is able to
load it! It's obvious it's caching it somehow.

My dlopen flags are RTLD_NOW and RTLD_LOCAL (I explicitly specified
this second one).

I'm at a loss as to what I could do to figure out the problem. Any
suggestions?

Paul Pluzhnikov

unread,
Apr 4, 2008, 11:58:30 PM4/4/08
to
jois.d...@gmail.com writes:

> I've developed a dynamic library as an extension to an existing
> application. I load this library at runtime when the application
> starts, and I have created a function that will unload (using
> dlclose()) and load it (dlopen()) whenever I want to update the
> working version of the library without having to take the application
> down.

Man dlclose says:

The function dlclose() decrements the reference count on the
dynamic library handle handle. If the reference count drops to
zero and no other loaded libraries use symbols in it, then the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
dynamic library is unloaded.

> However, I'm finding that dlclose() does not unload the library,

Because something else is still referencing it. You can find out
what that is by running your program with LD_DEBUG=bindings and
studying the output.

Note that calling dlclose() more times than you called dlopen()
induces undefined behavior.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

0 new messages