From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 778 invoked by alias); 9 Jul 2007 07:01:10 -0000 Received: (qmail 725 invoked by uid 48); 9 Jul 2007 07:00:55 -0000 Date: Mon, 09 Jul 2007 07:01:00 -0000 Subject: [Bug c++/32688] New: Dynamic linking cause static Dtor and Ctor to ran twice on same instance X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "ranc at mobixell dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-07/txt/msg01019.txt.bz2 When two separate Dynamic Shared Objects (DSO's) are using the same static object with the same name and each of them keeps a local copy of that object. When the application gets loaded that object’s constructor is called twice for the same instance and the destructor is also called twice when the main application exits. The Ctor is called for each load of the shared object and the Dtor for each close of the library. Regardless that the linker has optimized the instance so there would be one instance and not two. When applying the “static” prefix the problem is solved but the code is merged and the second linked shared object gets to execute the code of the first one! -- Summary: Dynamic linking cause static Dtor and Ctor to ran twice on same instance Product: gcc Version: 3.4.5 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ranc at mobixell dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32688