M
Markku Linnoskivi
Environment: Linux + g++ (4.3.X)
Let there be the following classes:
//libfoo <<<
struct Bar
{
Bar()
: s()
{}
Bar(const std::string& s_)
: s(s_)
{}
std::string s;
};
struct Foo
{
static Bar getBar()
{
static Bar b;
static done = false;
if (done)
{
return b;
}
std::stringstream s;
s << __FILE__ ;
}
};
//libfoo >>>>
//libX <<<
struct FooObj
{
//has instance of Foo and calls Foo:getBar()
};
extern "C"
{
FooObj* create()
{
return new FooObj;
}
}
//libX >>>
The context is a plugin system where the plugins use a common library
(libfoo) and appfoo is the host for the plugins.
There is a shared library, call it, libX that calls Foo::getBar() at
some point. And is linked during compile time to libfoo.
There is an application appfoo that opens libX via dlopen and
instantiates an FooObj from that library (using extern "C" function
create). appfoo destroys the instantiated object, closes libfoo with
dlclose and then later on opens it again with dlopen and creates a new
instance of FooObj.
At this point appfoo segfaults with a weird stack trace, mayby
pointing to std::stringstream.
What happens? This has to have something to do with the way GCC
creates/destroys the static variables or something like that.
Let there be the following classes:
//libfoo <<<
struct Bar
{
Bar()
: s()
{}
Bar(const std::string& s_)
: s(s_)
{}
std::string s;
};
struct Foo
{
static Bar getBar()
{
static Bar b;
static done = false;
if (done)
{
return b;
}
std::stringstream s;
s << __FILE__ ;
}
};
//libfoo >>>>
//libX <<<
struct FooObj
{
//has instance of Foo and calls Foo:getBar()
};
extern "C"
{
FooObj* create()
{
return new FooObj;
}
}
//libX >>>
The context is a plugin system where the plugins use a common library
(libfoo) and appfoo is the host for the plugins.
There is a shared library, call it, libX that calls Foo::getBar() at
some point. And is linked during compile time to libfoo.
There is an application appfoo that opens libX via dlopen and
instantiates an FooObj from that library (using extern "C" function
create). appfoo destroys the instantiated object, closes libfoo with
dlclose and then later on opens it again with dlopen and creates a new
instance of FooObj.
At this point appfoo segfaults with a weird stack trace, mayby
pointing to std::stringstream.
What happens? This has to have something to do with the way GCC
creates/destroys the static variables or something like that.