C++ shared lib, dlclose, segv on exit

Greg Wolodkin greg@mathworks.com
Mon Feb 14 16:24:00 GMT 2000


Hi all -
I'm not 100% sure if this is a g++ bug, a Linux glibc/ld.so bug, or
something odd that I'm doing wrong.  I have a very simple example
which can be found here:

ftp://ftp.mathworks.com/outgoing/users/wolodkin/gcc/static-c++-bug.tar.gz

Run the Makefile, which will build a small shared library, a small
main program, and run it in the debugger.  It will seg-fault on exit.

In short, if I dlopen a C++ shared library which later creates "new"
storage on the heap while initializing (local) static variables, the
corresponding cleanup code is not called before/during dlclose().
Instead, dlclose() succeeds but the main program seg faults on exit
while trying to call __tcf_0, a symbol that was in the C++ shared lib
but is no longer around.

The static data is local to a function, and is storage is allocated 
when I call into the library, as opposed to being created by _init during
dlopen().  In fact, _init and _fini do not appear to be called at all,
but I can clearly see __exit_funcs->fns being registered if I set a
breakpoint in exit().  I believe these destructors (if that's what they
are) should be called upon dlclose(), when the data goes out of scope.

I'm using glibc-2.1.2, and gcc-2.95.2 on a Debian 2.1 + a few unstable
patches system.  Same behavior on another machine with glibc 2.1.2 and
gcc-2.95.2 built from scratch.

Thanks for any help -
Greg


More information about the Gcc-bugs mailing list