Bug 23552

Summary: destructors for function scope statics run at exit
Product: [Retired] Red Hat Linux Reporter: David Baron <dbaron>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: David Lawrence <dkl>
Severity: high Docs Contact:
Priority: medium    
Version: 7.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-01-07 20:02:50 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
bug23552.tar - contains Makefile, statictest.cpp, libstatictest.cpp none

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
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.

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.