Mail Archives: djgpp/2015/10/01/06:45:12
On Thursday, October 1, 2015 at 9:35:24 AM UTC+2, Ozkan Sezer (sezeroz AT gmail DOT com) [via djgpp AT delorie DOT com] wrote:
> On 9/27/15, Ozkan Sezer <sezeroz AT gmail DOT com> wrote:
> > On 9/26/15, Juan Manuel Guerrero (juan DOT guerrero AT gmx DOT de) [via
> > djgpp AT delorie DOT com] <djgpp AT delorie DOT com> wrote:
> >> On Friday, September 25, 2015 at 7:21:47 PM UTC+2, Ozkan Sezer
> >> (sezeroz AT gmail DOT com) [via djgpp AT delorie DOT com] wrote:
> >>> On 9/25/15, Ozkan Sezer <sezeroz AT gmail DOT com> wrote:
> >>> > AFAICS, dlclose()ing of a dxe doesn't remove its dependency dxes along
> >>> > with it, which will result in unnecessarily occupied memory which may
> >>> > prove fatal upon multiple dlopen()/dlclose() of a dxe with deps. This
> >>> > needs addressing.
> >>> >
> >>>
> >>> My last argument was inaccurate and misleading. Here's better:
> >>>
> >>> One has a.dxe and b.dxe; a.dxe depends on b.dxe. Do dlopen a.dxe
> >>> and b.dxe is opened implicitly. Do dlcose a.dxe, and b.dxe stays
> >>> open still occupying its memory. The memory occupied by the unused
> >>> b.dxe might be needed by the app but will be unavailable to it.
> >>> Further dlopen calls for a.dxe will increment the refcount for b.dxe
> >>> which never gets decremented.
> >>
> >>
> >> Can you provide a minimal sample code to demonstrate the issue?
> >>
> >> Regards,
> >> Juan M. Guerrero
> >>
> >
> > =======================================
> >
> > $ cat 12.c
> > extern int my_func2();
> > int my_func1() {
> > return my_func2();
> > }
> > $ gcc -c 12.c
> > $ dxe3gen -o a.dxe -P b.dxe -U 12.o
> > $ dxe3gen --show-exp a.dxe
> > _my_func1
> > $ dxe3gen --show-dep a.dxe
> > b.dxe
> >
> > =======================================
> >
> > $ cat 13.c
> > int my_func2() {
> > return -1;
> > }
> > $ gcc -c 13.c
> > $ dxe3gen -o b.dxe 13.o
> > $ dxe3gen --show-exp b.dxe
> > _my_func2
> >
> > =======================================
> >
> > $ cat 11.c
> > #include <dlfcn.h>
> > #include <stdio.h>
> >
> > void *my_dxe1;
> > int (*my_f)();
> >
> > int main (void) {
> > my_dxe1 = dlopen("a.dxe",0);
> > if (!my_dxe1) {
> > printf("dlopen() failed\n");
> > return 1;
> > }
> > dlclose(my_dxe1);
> >
> > my_f = dlsym(RTLD_DEFAULT,"_my_func1");
> > if(!my_f) {
> > printf("a.dxe not loaded\n");
> > }
> > else {
> > printf("a.dxe:my_func1(): %p\n",my_f);
> > }
> >
> > my_f = dlsym(RTLD_DEFAULT,"_my_func2");
> > if(!my_f) {
> > printf("b.dxe not loaded\n");
> > }
> > else {
> > printf("b.dxe:my_func2(): %p\n",my_f);
> > printf("b.dxe:my_func2() returns: %d\n",my_f());
> > }
> >
> > return 0;
> > }
> >
> > $ gcc -Wall -W 11.c
> >
> > =======================================
> >
> > $ a.exe > a.log
> > $ cat a.log
> > a.dxe not loaded
> > b.dxe:my_func2(): 95830
> > b.dxe:my_func2() returns: -1
> >
>
> PING? Any ideas? (Sorry that I brought the issue
> but have no patch for it myself.)
An inspection of your sample code and dldemo.cpp shows that it seems to be that it is the user's responsibility to explicitly dlclose every dlopen'ed modules.
This is what an inspection of dldemo.cpp shows.
This may not be what you expected from unix but I assume that no DJGPP developer has really promised that the behaviour would be identical to unix behaviour.
Neither less I will inspect the issue during week-end but I do not promise that a fix will be possible.
Regards,
Juan M. Guerrero
- Raw text -