public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32688]  New: Dynamic linking cause static Dtor and Ctor to ran twice on same instance
@ 2007-07-09  7:01 ranc at mobixell dot com
  2007-07-09  7:07 ` [Bug c++/32688] " ranc at mobixell dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ranc at mobixell dot com @ 2007-07-09  7:01 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1107 bytes --]

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


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

* [Bug c++/32688] Dynamic linking cause static Dtor and Ctor to ran twice on same instance
  2007-07-09  7:01 [Bug c++/32688] New: Dynamic linking cause static Dtor and Ctor to ran twice on same instance ranc at mobixell dot com
@ 2007-07-09  7:07 ` ranc at mobixell dot com
  2007-07-09  7:08 ` ranc at mobixell dot com
  2007-07-09  7:12 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: ranc at mobixell dot com @ 2007-07-09  7:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ranc at mobixell dot com  2007-07-09 07:07 -------
Created an attachment (id=13874)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13874&action=view)
gzipped tar ball of a sample code

The is the sample code problem, execute from bash the compile.bash script:
. compile.bash
then execute:
./main


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32688


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

* [Bug c++/32688] Dynamic linking cause static Dtor and Ctor to ran twice on same instance
  2007-07-09  7:01 [Bug c++/32688] New: Dynamic linking cause static Dtor and Ctor to ran twice on same instance ranc at mobixell dot com
  2007-07-09  7:07 ` [Bug c++/32688] " ranc at mobixell dot com
@ 2007-07-09  7:08 ` ranc at mobixell dot com
  2007-07-09  7:12 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: ranc at mobixell dot com @ 2007-07-09  7:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ranc at mobixell dot com  2007-07-09 07:08 -------
Attached is a gzipped tag ball with a sample problem.

just execute from bash the compile.bash script and execute ./main .

(I use RHEL 4.0)

[ranc@Rans_Linux test]$ g++ --version
g++ (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[ranc@Rans_Linux test]$ ld --version
GNU ld version 2.15.92.0.2 20040927
Copyright 2002 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32688


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

* [Bug c++/32688] Dynamic linking cause static Dtor and Ctor to ran twice on same instance
  2007-07-09  7:01 [Bug c++/32688] New: Dynamic linking cause static Dtor and Ctor to ran twice on same instance ranc at mobixell dot com
  2007-07-09  7:07 ` [Bug c++/32688] " ranc at mobixell dot com
  2007-07-09  7:08 ` ranc at mobixell dot com
@ 2007-07-09  7:12 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-09  7:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2007-07-09 07:12 -------
This is not a bug in GCC, you are violating the One Definition Rule which does
not need any diagnostic.  
Actually there are two violations, first the class Common are different between
the TUs.
Second you have two definitions of cmn which is a global.

If you use 4.2.0 and above you can use the attribute hidden applied to classes
and objects to get the effect of having a local class/variable to that DSO.

Also by the way you forgot to compile the libraries with PIC which could also
be causing an issue.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32688


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

end of thread, other threads:[~2007-07-09  7:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-09  7:01 [Bug c++/32688] New: Dynamic linking cause static Dtor and Ctor to ran twice on same instance ranc at mobixell dot com
2007-07-09  7:07 ` [Bug c++/32688] " ranc at mobixell dot com
2007-07-09  7:08 ` ranc at mobixell dot com
2007-07-09  7:12 ` pinskia at gcc dot gnu dot org

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).