From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19503 invoked by alias); 30 May 2011 13:19:14 -0000 Received: (qmail 19494 invoked by uid 22791); 30 May 2011 13:19:13 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,TW_RG X-Spam-Check-By: sourceware.org Received: from mail-bw0-f41.google.com (HELO mail-bw0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 30 May 2011 13:18:54 +0000 Received: by bwz17 with SMTP id 17so3576690bwz.0 for ; Mon, 30 May 2011 06:18:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.38.88 with SMTP id a24mr4292496bke.130.1306761532523; Mon, 30 May 2011 06:18:52 -0700 (PDT) Received: by 10.204.154.216 with HTTP; Mon, 30 May 2011 06:18:52 -0700 (PDT) Date: Mon, 30 May 2011 23:07:00 -0000 Message-ID: Subject: dlclose() doesn't unload any .so that uses Boost From: J To: binutils@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00379.txt.bz2 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 #include 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 #include 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.