Destructors for static objects in function scope are run at exit (using calls to atexit()). This causes a segfault on exit when the destructor is in a shared library that has since been closed. IMO, the destructors ought to be run when the shared library is unloaded (as I think they are for static objects with global scope). I haven't seen anything in the C++ standard that forbids that, although I haven't looked very closely. (This is one reason mozilla doesn't unload shared libraries, although not the only one. There are only a handful of changes that would need to be made in Mozilla to work around this, though, and I've made most of them already.) I'll attach a tar file containing a simple testcase. I wrote the testcase with gcc-2.96-69, although I've seen this happen in older versions as well.
Created attachment 7204 [details] bug23552.tar - contains Makefile, statictest.cpp, libstatictest.cpp
You could try building the shared C++ library with -fuse-cxa-atexit, I admit I haven't tried it yet but it should work.
Yup, that works.