Static data in dynamically loaded C++ shared libs on linux
koch
koch@epc.de
Tue Nov 30 03:29:00 GMT 1999
Hi,
I think I've stumbled across a bug in the current version of egcs (gcc
version 2.95.2 19991024 (release)) and previous versions on linux
(Linux version 2.2.10 and probably other platforms).
Problem description:
I'm creating a shared library that contains static data inside a
function or method. When the library is unloaded with dlclose, the
program crashes on exit with a segmentation violation.
Global objects are properly destructed when the library is unloaded,
i.e. upon the dlclose() call.
According to the egcs source, for static objects within a function, a
local function is generated and registered as an exit handler, using
atexit() (See egcs-*/gcc/cp/decl.c:expand_static_init()). This leads
to the problem that this function's memory address is invalid when
exit() tries to invoke it.
The attached tar-ball contains a simple example program that
reproduces the problem.
I hope this is helpful. Best regards,
Heinz-Detlev Koch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shlibtest.tgz
Type: application/x-gzip
Size: 954 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/19991130/cb6a7153/attachment.bin>
More information about the Gcc-bugs
mailing list