Static data in dynamically loaded C++ shared libs on linux

Mike Stump mrs@windriver.com
Wed Dec 1 14:56:00 GMT 1999


> Date: Wed, 1 Dec 1999 09:54:42 +0100
> From: "Martin v. Loewis" <martin@mira.isdn.cs.tu-berlin.de>

> Thanks for your bug report. This is a know limitation of g++, although
> it is not strictly a bug.

It is not a nonconformance with the ANSI standard for C++, but it is a
bug.  I'm not into this, well we know it is stupid and wrong, but it
isn't a bug thing.  Let's call it what it is, a bug.

> The behaviour you see is mandated by the C++ standard.

No, it is not.  The C++ Standard is silent with regard to unloading
objects.  You cannot reason about _any_ code in this way, once you
exit the bounds of the Standard.

> About the only way to implement this correctly is to use atexit. Of
> course, this has undesirable side effects on libraries unloaded with
> dlclose.

There are solutions that can be implemented to solve this bug.  One of
them is an atexit with two parameters.  One is the routine, and the
other is the notion of which module (unit of loading and unloading)
the registration is associated with.  If the module is unloaded before
exit, then all the atexit registrations for that module run on demand
and are not run again.  Else, at exit, the atexit routines are all
just run as normal.  See HJ Lu's (or was it Drepper?) excellent
previous posting.

> This is not a bug in the strict sense, because nobody says that this
> should work.

I'll say it if you want.


More information about the Gcc-bugs mailing list