Bug 23552 - destructors for function scope statics run at exit
Summary: destructors for function scope statics run at exit
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
Depends On:
TreeView+ depends on / blocked
Reported: 2001-01-07 19:58 UTC by David Baron
Modified: 2007-04-18 16:30 UTC (History)
0 users

Clone Of:
Last Closed: 2001-01-07 20:02:50 UTC

Attachments (Terms of Use)
bug23552.tar - contains Makefile, statictest.cpp, libstatictest.cpp (10.00 KB, application/x-tar)
2001-01-07 20:02 UTC, David Baron
no flags Details

Description David Baron 2001-01-07 19:58:28 UTC
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

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.

Comment 1 David Baron 2001-01-07 20:02:47 UTC
Created attachment 7204 [details]
bug23552.tar - contains Makefile, statictest.cpp, libstatictest.cpp

Comment 2 Jakub Jelinek 2001-01-11 22:46:44 UTC
You could try building the shared C++ library with
-fuse-cxa-atexit, I admit I haven't tried it yet but it should work.

Comment 3 David Baron 2001-01-11 23:18:17 UTC
Yup, that works.

Note You need to log in before you can comment on or make changes to this bug.