X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=7aircVT1MrY/+yMpJBLAhdBfh5MwrPw2mDAL6Ez/3to=; b=zQLCfqKsX/SDOzevA69P8tV5m3n3puIEJIY31VAv/SblNwcEIlyv/r0Rp42W19Mnci vlJCUPgBcPTdqQZ77v1CR9dy3hzt66T5ohv9zLg6/rdT+O5eo5VJYAx7d6I0w5YV528l h4ySko4InpBUiMd7i8NgmjuvDJ2y8pglhqCDh4jOnOa6qvFvgUKmMCml/RomzybNsuQR 0It7FMqThqewAj3EObNMxsmpdge4wVLIOPq9v3rZbUd3ZFTptJACw17mpJs1SMS+e/jq RAw56TZhFFcjiSM6U24QfYMuMdLcCrP+Vg/dwdItE1TyfVspzQwzJEGI6rVZlqYq5QX2 ribg== MIME-Version: 1.0 X-Received: by 10.50.143.1 with SMTP id sa1mr9386814igb.32.1443302904715; Sat, 26 Sep 2015 14:28:24 -0700 (PDT) In-Reply-To: References: Date: Sun, 27 Sep 2015 00:28:24 +0300 Message-ID: Subject: Re: dlclose not removing dependency dxes From: "Ozkan Sezer (sezeroz AT gmail DOT com) [via djgpp AT delorie DOT com]" To: djgpp AT delorie DOT com Content-Type: text/plain; charset=UTF-8 Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On 9/26/15, Juan Manuel Guerrero (juan DOT guerrero AT gmx DOT de) [via 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 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 #include 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