delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/01/21/15:11:17

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=3.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
Date: Fri, 21 Jan 2011 15:10:45 -0500
Message-ID: <AANLkTinXKb+2m3LFYnaCergTDz5CpPyM1P2d_y=JPVOo@mail.gmail.com>
Subject: use of LD_PRELOAD (and RTLD_NEXT?)
From: David Boyce <dsb AT boyski DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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.

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 {
    [prefix code]
    [call through to the "real" foo() function]
    [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
(<http://cygwin.com/ml/cygwin/2004-09/msg00288.html>). I'm guessing
the main problem is that EnumProcessModules does not guarantee an
order?

Thanks,
David Boyce

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019