This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

shared lib exit function


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]