dlclose() doesn't unload any .so that uses Boost

J j@jabster.pl
Tue May 31 12:38:00 GMT 2011


On Tue, May 31, 2011 at 7:43 AM, Alan Modra <amodra@gmail.com> wrote:
> On Mon, May 30, 2011 at 03:18:52PM +0200, J wrote:
>> As you can see, dlclose() doesn't properly unload the .so, even though
>> it claims that it has done so. If you'll remove this line:
>>
>> boost :: signal< void () > signal;
>>
>> it works properly:
>
> On x86 with gcc-4.4.3, ld 2.21.51.20110509, glibc 2.11.1, libboost
> 1.40.0 I get
> host: Loading libchild.so...
> child: Constructor
> host: so = 0x8240020
> host: Unloading libchild.so...
> child: Destructor
> host: Unloaded.
> host: (nil)
>
> ie. the same result as your "works properly".  My guess would be that
> your version of glibc handles dlclose differently to mine.  Note that
> there are quite legitimate reasons that dlclose might not behave
> as you expect, eg. if libchild.so was built with DF_1_NODELETE set.
> That probably isn't the case here, but worth checking with readelf
> whether that flag is set for libchild.so and any of its dependencies.

I've managed to track this issue down. It looks like a bug in GCC:

$ g++-4.4 -lboost_signals child.cc -shared -fPIC -o libchild.so
$ ./host
host: Loading libchild.so...
child: Constructor
host: so = 0x85ab020
host: Unloading libchild.so...
child: Destructor
host: Unloaded.
host: (nil)

$ g++-4.6 -lboost_signals child.cc -shared -fPIC -o libchild.so
$ ./host
host: Loading libchild.so...
child: Constructor
host: so = 0x8b34020
host: Unloading libchild.so...
host: Unloaded.
host: (nil)
child: Destructor

Thanks for your help anyway. (:



More information about the Binutils mailing list