dlopen broken?

John Lancaster John.Lancaster at brunel.ac.uk
Mon Aug 6 20:24:30 AEST 1990


Is the program interface to the dynamic linker (dlopen) broken?

The following program will cause a segmentation error when the second call
to dlopen is made.  If the first call to dlclose is deleted the program
will run.  It appears that after a call to dlclose dlopen can no longer be
called.  This is not the behaviour implied by the manual.

Has anyone got this to work?  Have I misunderstood the documentation?

Test program:

#include<dlfcn.h>

main()
{
     int closeResult;
     static int *handle;
     char *file, *symbol;
     int (*symAdr)();

     p1();

     file = "p2.out";
     handle = dlopen(file,1);
     printf("returned handle of %s is %x\n",file,handle);
     printf("dlerror: %s\n",dlerror());

     symbol = "_p2";
     symAdr = dlsym(handle,symbol);
     printf("returned symbol address of %s is %x\n",symbol,symAdr);
     (*symAdr)();

     closeResult = dlclose(handle); /** this line the problem **/
     printf("dlclose call returned %d\n",closeResult);
     printf("dlerror: %s\n",dlerror());

     file = "p3.out";
     handle = dlopen(file,1);
     printf("returned handle of %s is %x\n",file,handle);

     symbol = "_p3";
     symAdr = dlsym(handle,symbol);
     printf("returned symbol address of %s is %x\n",symbol,symAdr);
     (*symAdr)();

     closeResult = dlclose(handle);
     printf("dlclose call returned %d\n",closeResult);
     printf("dlerror: %s\n",dlerror());

     exit(0);
}

p1()
{
     printf("inside p1\n");
     return;
}

John Lancaster      Email: J.Lancaster at brunel.ac.uk
Brunel University   Phone: +44 (0)895 74000 ext 2330
Uxbridge            Fax: +44 (0)895 58728
England             Telex: 261173 G
UB8 3PH




More information about the Comp.sys.sun mailing list