Question about __attribute__ ((construtor))
Jeroen Benckhuijsen
jeroen@themindconnection.com
Wed Oct 15 09:33:00 GMT 2003
Hi,
I've got the following problem. I've implemented some shared libs in
windows, now porting to linux (running RedHat 9). Most of those libs use
some initialization code using a function defined with __attribute__
((constructor)). These libs have hierarchical dependencies among
eachother. The problem is, when I run an application dependend on these
libs, the first library to run the initialization code is not the lib at
the root of the dependency tree. The result is a seg fault. My guess is
that the initialization code for the static members of the classes i use
(it's written in C++) isn't executed yet (e.g. a constructor for a
std::string hasn't been called yet). The init code of the library which
is executed first uses some static functions (and internal some static
members) of the library it depends on.
My questions are:
(1) How is the order determined for functions defined with __attribute__
((constructor)) with respect to normal variable initialization and other
functions defined with the same attribute?
(2) Is it possible to change or correct this order?
TIA
Jeroen Benckhuijsen
Software Architect
The Mind Connection
More information about the Gcc-bugs
mailing list