C
clilley
The following code causes a segmentation fault on DEC Tru64:
foo.cc (built into libFoo.so)
//---------------------------
include <iostream>
bool createFoo()
{
std::cout << "createFoo" << std::endl;
}
bool registerCreate = createFoo();
//-----------------------------------------
main.cc (built into a.out and linked to libFoo.so)
//-----------------------------
int main (int argc, char *argv[])
{
// Do nothing
};
//------------------------------------------
What is happening is that at runtime the library loader is loading the
libFoo.so library and attempting to initialise any
statics present in libFoo.so. This causes an attempt to initialise the bool
registerCreate variable in foo.cc, by calling the createFoo
method. The SEGV occurs because std::cout has not yet been initialised.
The same code works fine using gnu g++ 3.3.1
So my question is, is this a bug or is this behaviour allowed under the C++
standard?
I realise that the order of static initialisation, before main is entered,
is undeterministic, but I would have expected the runtime system to be
initialised before the user defined librarys are loaded.
Any help would be gratefully appreciated.
Regards
Clive Lilley.
foo.cc (built into libFoo.so)
//---------------------------
include <iostream>
bool createFoo()
{
std::cout << "createFoo" << std::endl;
}
bool registerCreate = createFoo();
//-----------------------------------------
main.cc (built into a.out and linked to libFoo.so)
//-----------------------------
int main (int argc, char *argv[])
{
// Do nothing
};
//------------------------------------------
What is happening is that at runtime the library loader is loading the
libFoo.so library and attempting to initialise any
statics present in libFoo.so. This causes an attempt to initialise the bool
registerCreate variable in foo.cc, by calling the createFoo
method. The SEGV occurs because std::cout has not yet been initialised.
The same code works fine using gnu g++ 3.3.1
So my question is, is this a bug or is this behaviour allowed under the C++
standard?
I realise that the order of static initialisation, before main is entered,
is undeterministic, but I would have expected the runtime system to be
initialised before the user defined librarys are loaded.
Any help would be gratefully appreciated.
Regards
Clive Lilley.