Newsgroups: comp.sys.sun
Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!rice!rice!sun-spots-request
From: John Lancaster <John.Lancaster@brunel.ac.uk>
Subject: dlopen broken?
Message-ID: <1990Aug7.003745.2365@rice.edu>
Originator: spots@titan.rice.edu
Keywords: Miscellaneous
Sender: sun-spots-request@rice.edu
Organization: Sun-Spots
X-Sun-Spots-Digest: Volume 9, Issue 296, message 6
Date: 6 Aug 90 10:24:30 GMT
Approved: Sun-Spots@rice.edu

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@brunel.ac.uk
Brunel University   Phone: +44 (0)895 74000 ext 2330
Uxbridge            Fax: +44 (0)895 58728
England             Telex: 261173 G
UB8 3PH

