public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11137] New: Linux shared library constructors not called unless there's one global object
@ 2003-06-09 19:49 jcalcote@novell.com
  2003-06-10  1:24 ` [Bug c++/11137] [3.3 Regression] " pinskia@physics.uc.edu
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: jcalcote@novell.com @ 2003-06-09 19:49 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Linux shared library constructors not called unless
                    there's one global object
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P2
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jcalcote@novell.com
                CC: gcc-bugs@gcc.gnu.org

Linux shared library constructor and destructor routines defined by the use of 
the __attribute__((constructor)) and __attribute__((destructor)) keywords are 
not called in C++ programs when the library is loaded/unloaded unless there is 
at least one global object in the module. Global constructors and destructors 
appears to work correctly in C programs. Only C++ programs exhibit this 
strange behaviour. I use the following hack to get my constructors to be 
called - I place this statement in my init/exit code:

static struct Stupid { Stupid() {} ~Stupid() {} } stupid;

which causes Stupid() to be executed at library load time, and then adds a 
call to my __attribute__((constructor)). 

Having disassembled the code to my module by using objdump, I can see that the 
routine that calls global object constructors is not injected unless there's 
at least one global object. Since calls to __attribute__((constructor)) 
routines are placed at the end of this compiler generated code, no such calls 
will be made if this code is not generated. The cause of generation of this 
routine appears to be the existance of a global C++ object, but not the 
existence of __attribute__((constuctor)) routines.


^ permalink raw reply	[flat|nested] 7+ messages in thread
[parent not found: <bug-11137-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2010-11-16 17:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-09 19:49 [Bug c++/11137] New: Linux shared library constructors not called unless there's one global object jcalcote@novell.com
2003-06-10  1:24 ` [Bug c++/11137] [3.3 Regression] " pinskia@physics.uc.edu
2003-06-29 15:58 ` pinskia at physics dot uc dot edu
2003-07-01 18:14 ` cvs-commit at gcc dot gnu dot org
2003-07-01 18:15 ` mmitchel at gcc dot gnu dot org
2003-08-12 14:14 ` cvs-commit at gcc dot gnu dot org
     [not found] <bug-11137-4@http.gcc.gnu.org/bugzilla/>
2010-11-16 17:57 ` hjl at gcc dot gnu.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).