[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
iostreams, DSO, atexit and static linking
From: |
Frederic Olivie |
Subject: |
iostreams, DSO, atexit and static linking |
Date: |
Thu, 03 May 2001 02:19:27 +0200 |
Hi,
I know the title sounds weird (DSO and static linking), but I have
identified the following problem :
Porting a software on AIX, I got the AIX toolbox with ports of the
different GNU tools, including g++.
This distribution only provides a static version of the libstdc++.
My project involves using parts of the iostreams library (libio) inside
C++ dynamically loaded modules.
I had a weird bug which happened at the end of the program's execution.
It took me a while to trace it up to the exit
libc routine which calls all functions registered using atexit.
The problem apparetly comes from the libio library which registers a
function called _IO_cleanup
with atexit (inside cleanup.c).
This would work perfectly in lots of cases. But, when linking statically
libstdc++ with my dynamically loaded
modules, this function gets registered with atexit.
The problem happens when the module is unloaded (dlclose) before the
program end. Then, the exit routine
will call a no more existent _IO_cleanup function. This leads to an
Illegal Instruction (a handler pointing to 0x0).
I found a very dirty solution : Declare the
_IO_cleanup_registration_needed function inside my modules, and
initialize
it to zero (this will prevent the library code from registering
_IO_cleanup with atexit) :
Inside the declarations part :
#define NOREGISTER_CLEANUP
#ifdef NOREGISTER_CLEANUP
#ifndef __PMT
# ifdef __STDC__
# define __PMT(p) p
# else
# define __PMT(p) ()
# endif
#endif /*!__P*/
extern void (*_IO_cleanup_registration_needed) __PMT ((void));
#endif
Inside the constructor :
#ifdef NOREGISTER_CLEANUP
_IO_cleanup_registration_needed = 0;
#endif
Then, to make things clean, I do call the _IO_cleanup function just
before the dlclose() call if it exists.
Yes, it is absolutely dirty and not very portable :-(
I have found something that looks like this problem in the 1999 g++
mailing list archives, but without any
explanation or solving procedure.
Is this a know issue ? If no, does it seem like one ?
Is this logical that the iostreams library registers itself with
atexit() ?
Thanks for any help you could bring. Please CC: my email addr because
I'm not subscribed to this list.
--
Frédéric Olivié (Alf) http://www.albert.com
Mailto: address@hidden
Don't SCREAM, it hurts my eyes (Alf - 2001).
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- iostreams, DSO, atexit and static linking,
Frederic Olivie <=