This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Missing global constructor
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: Missing global constructor
- From: "Steve Keppel-Jones" <stevekj at nortelnetworks dot com>
- Date: Mon, 8 Mar 1999 09:40:26 -0500 (EST)
- Reply-To: "Steve Keppel-Jones" <stevekj at nortelnetworks dot com>
This bug is related to EGCS version 1.1.1, and is also reproducible in
GCC 2.8.1. I am compiling on a Sun UltraSPARC 10, and the bug also occurs
on my PowerPC machine. The compile options are simply -S to get the assembly
source. The exact bug is as follows: the compiler fails to generate a
global constructor and destructor for the tcGlobal variable in this example.
Note that if the initializer is removed from the (unrelated) rgpi variable,
the tcGlobal constructor/destructor are generated (_GLOBAL_.I.tcGlobal,
_GLOBAL_.D.tcGlobal).
I cannot think of anything in the C++ standard that could allow the compiler
to fail to generate this global constructor, so I can only conclude that it
is a bug.
The only workaround I've been able to come up with is to separate global
variables each into their own object file, which is workable but hardly an
elegant idea.
Source code is attached: I haven't bothered to preprocess it since there are
no included files, so the only thing the preprocessor will do is remove the
comments.
Command line: gcc -S file.cc
---------------------------------------------------------------------
// Enabling this line prevents the generation of a
// global constructor symbol for the TestClass
// (_GLOBAL_.I.tcGlobal)
int *rgpi[5] = { (int *)5 } ;
// This line, on the other hand, doesn't interfere with
// the global constructor generation.
//int *rgpi[5];
class TestClass
{
public:
TestClass();
~TestClass();
};
TestClass tcGlobal;
-----------------------------------------------------------------------
Thanks,
Steve
stevekj@nortelnetworks.com