public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* dlclose() doesn't unload any .so that uses Boost
@ 2011-05-30 23:07 J
  2011-05-31 10:18 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: J @ 2011-05-30 23:07 UTC (permalink / raw)
  To: binutils

Hi.

I've been told on the GCC mailing list to ask here. Please consider
the following code:

// host.cpp
// compile with: g++ -ldl host.cpp -o host
#include <stdio.h>
#include <dlfcn.h>

int main( int argc, char ** argv )
{
   printf( "host: Loading libchild.so...\n" );
   void * so = dlopen( "./libchild.so", RTLD_LOCAL | RTLD_NOW );
   printf( "host: so = %p\n", so );

   if( so == 0 ) return 1;

   printf( "host: Unloading libchild.so...\n" );
   if( dlclose( so ) != 0 )
   {
       printf( "host: Error: %s\n", dlerror() );
       return 1;
   }
   printf( "host: Unloaded.\n" );
   printf( "host: %p\n", dlopen( "./libchild.so", RTLD_NOLOAD ) );

   return 0;
}

// child.cpp
// compile with: g++ -lboost_signals child.cpp -shared -fPIC -o libchild.so
#include <stdio.h>
#include <boost/signals.hpp>

struct foobar_t
{
   boost :: signal< void () > signal;
};

void  __attribute__ ( ( constructor ) ) ctor()
{
   foobar_t foobar;

   printf( "child: Constructor\n" );
}

void  __attribute__ ( ( destructor ) ) dtor()
{
   printf( "child: Destructor\n" );
}


This is the output I get:

host: Loading libchild.so...
child: Constructor
host: so = 0x94b6020
host: Unloading libchild.so...
host: Unloaded.
host: (nil)
child: Destructor

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:

host: Loading libchild.so...
child: Constructor
host: so = 0x8f6f020
host: Unloading libchild.so...
child: Destructor
host: Unloaded.
host: (nil)

It took me a while to track this down. Now, my question is - is this a
bug? If so, in what? In GCC? (I tried this with both 4.5 and 4.6) In
the dynamic linker? In Boost? If not - why? And how would I fix this?
Any insight in greatly appreciated.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-31 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-30 23:07 dlclose() doesn't unload any .so that uses Boost J
2011-05-31 10:18 ` Alan Modra
2011-05-31 12:38   ` J
2011-05-31 14:04     ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).