c++ static initialization question

Ian Lance Taylor iant@google.com
Mon Mar 8 20:53:00 GMT 2010


Juan Carlos Franzoy <jfranzoy@gmail.com> writes:

> I do not think it is a bug on gcc. I just want to know if there are
> some docs that describes how static initializations is in gcc.

As far as I know it is not documented.  I wrote some very shorts notes
at http://www.airs.com/blog/archives/51 .

The basic idea is pretty simple.  For static variables not defined in
any function, all the constructors are run at program startup time.
The order in which they are run is unspecified, except that within a
single file they are run in the order in which they appear in the
file.

The backtrace in http://gcc.gnu.org/ml/gcc-help/2010-03/msg00090.html
does not make much sense to me.  Somehow calling
ats::base::getEnvironmentVariable leads to a call to _init.  How does
that happen?  Do you have different shared libraries involved?  It
seems that perhaps a symbol in one shared library is referring to a
symbol defined in a different shared library, and that the Solaris
dynamic linker is deciding to run the static initializers in the
latter library.  This is then leading to the reentrant call.

Ian



More information about the Gcc-help mailing list