X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 21 Jan 2011 23:14:09 +0100 Message-ID: Subject: Re: use of LD_PRELOAD (and RTLD_NEXT?) From: marco atzeri To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Fri, Jan 21, 2011 at 9:10 PM, David Boyce wrote: > I'm trying to port to Cygwin a tool which makes heavy use of > LD_PRELOAD (in other words, LD_PRELOAD is not used as a quick hack or > workaround but is a core part of how the tool works). From my web > searching, it seems that LD_PRELOAD support has been present for many > years but the semantics are (a) different from POSIX or Linux and (b) > undocumented AFAICT, so I'm looking for pointers to further knowledge. > LD_PRELOAD is working with two advises if you try to load more than 1 dlls 1) the separator is only ":" , using a space doesn't work 2) if the dlls have a dependency between them, the order is important http://cygwin.com/ml/cygwin/2009-05/msg00823.html > Specifically, searches of mailing list archives turn up sample > programs showing how to "hook" a function but not how to gain "full > control". Consider the following interposed function: > > int foo { > =A0 =A0[prefix code] > =A0 =A0[call through to the "real" foo() function] > =A0 =A0[suffix code] > } > > What I call full control is when any or all of these steps may be > elided, such that one can completely replace the function, change its > return code, etc. The standard Linux/POSIX/SysV semantics support this > by use of RTLD_NEXT which appears to be semi-unimplemented in Cygwin > (a grep through the sources shows code for RTLD_NEXT in newlib but not > in winsup). So my specific questions become: > > - Can the above functionality supported in the current implementation, > and is the CW_HOOK method documented in detail anywhere? > - What's the status of RTLD_NEXT? Is its presence in newlib just an > historical artifact, or does it mean I can use it now with the right > voodoo? > > BTW in 2004 someone asked about RTLD_DEFAULT and RTLD_NEXT, then > contributed a patch implementing RTLD_DEFAULT only without saying why > RTLD_NEXT had fallen off > (). I'm guessing > the main problem is that EnumProcessModules does not guarantee an > order? > > Thanks, > David Boyce > > -- Sorry, no clue about RTLD_DEFAULT and RTLD_NEXT Marco -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple