NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

dlopen(), atexit() SEGV in NetBSD

I am facing some issue with atexit handler in NetBSD.
The procedure to reproduce the problem i have explained below:

Step 1.
 Create using the following code
$ cat example.c

#include <stdlib.h>
#include <stdio.h>

void exithandler(void) {
  printf("now exiting\n");
void register_handler(void) {
  printf("Inside register handler\n");

Step 2.
Use the following test case to which dlopens the

$ cat test.c
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

int main (void) {
  void *dlhandle = NULL;
 void (*handler) (void);

  dlhandle = dlopen("./", RTLD_LAZY);
  if (!dlhandle) {
    printf("cannot open module\n");
  handler = dlsym(dlhandle, "register_handler");
  if (!handler) {
    printf("cannot locate function\n");

Step 3. Execute the test case
$ ./test
Inside register handler
Segmentation fault

As explained above the program gives SEGV.

Because after a dlopened library that calls atexit() the
is dlclosed, an executable can't
access a registered handler in the library and causes SEGV.

The same issue is discussed in the FreeBSD mailing list link given below

Could any one help me in finding a solution for the above issue?

Awaiting for your reply.

Thanks & Regards,

Home | Main Index | Thread Index | Old Index