This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
shared lib exit function
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Subject: shared lib exit function
- From: Carsten Paeth <calle at calle dot in-berlin dot de>
- Date: Wed, 3 Nov 1999 08:53:51 +0100
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
Hello.
I have written a CAPI20 library for linux in the past. Now it is a shared lib.
If someone use the library with dlopen/dlclose I need to call a
lib exit function on unload. I looked in the source of the ld.so package.
I tried something like this:
int capi_fd = -1;
#define __exit __attribute__ ((__section__ (".fini")))
static void __exit exitfunc(void)
{
if (capi_fd >= 0) {
close(capi_fd);
capi_fd = -1;
}
}
The function will be called, but program crashes on exit of the function.
int capi_fd = -1;
static void __exitfunc(void)
{
if (capi_fd >= 0) {
close(capi_fd);
capi_fd = -1;
}
}
static void exitfunc(void)
{
asm(".section .fini");
__exitfunc();
asm(".section .text");
}
will be rejected by the linker, call to __exitfunc() had to be relativ
and will go in a different section .....
Did someone know the solution ?
thanks in advance and best regards
calle