This is the mail archive of the
mailing list for the Cygwin project.
Re: About the dll search algorithm of dlopen
- From: Michael Haubenwallner <michael dot haubenwallner at ssi-schaefer dot com>
- To: cygwin-developers at cygwin dot com
- Date: Fri, 19 Aug 2016 18:37:41 +0200
- Subject: Re: About the dll search algorithm of dlopen
- Authentication-results: sourceware.org; auth=none
- References: <574E835E.email@example.com> <20160601110947.GE11431@calimero.vinschen.de> <574EF07B.firstname.lastname@example.org> <20160601201748.GI11431@calimero.vinschen.de>
On 06/01/2016 10:17 PM, Corinna Vinschen wrote:
> On Jun 1 16:26, Michael Haubenwallner wrote:
>> On 06/01/2016 01:09 PM, Corinna Vinschen wrote:
>>> On Jun 1 08:40, Michael Haubenwallner wrote:
>>>> two issues with dlopen here (I'm about to prepare patches):
>>>> *) The algorithm to combine dll file name variants with the search path
>>>> entries needs to be reordered, as in:
>>>> - for each dll file name variant:
>>>> - for each search path:
>>>> + for each search path entry:
>>>> + for each dll file name variant:
>>>> check if useable
>>> However, if you can speed up the search process ignore the
Not sure if there's a speedup actually, ...
>> This also depends on whether find_exec really is necessary here.
> Not as such necessary, it's just the function used to search in a
> search path. If you want to change that you have to rewrite the
> same logic again, just reversed.
> One way around YA code duplication could be some kind of path iterator
> class which could be used from find_exec as well as from
0001.patch is a draft for some new cygwin::pathfinder class, with
0002.patch adding the executable's directory as searchpath, and
0003.patch to search the PATH environment as well.
Any idea about different template nesting to be useful somewhere else?
>>>> *) The directory of the current main executable should be searched
>>>> after LD_LIBRARY_PATH and before /usr/bin:/usr/lib.
>>>> And PATH should be searched before /usr/bin:/usr/lib as well.
>>> Checking the executable path and $PATH are Windows concepts. dlopen
>>> doesn't do that on POSIX systems and we're not doing that either.
>> Agreed, but POSIX also does have the concept of embedded RUNPATH,
>> which is completely missing in Cygwin as far as I can see.
> RPATH and RUNPATH are ELF dynamic loader features, not supported by
In any case, to me it does feel quite important to have the (almost) same
dll search algorithm with dlopen() as with CreateProcess().
>> However, when dlopen is about to search some path list, I can imagine to
>> search the list of already loaded dlls first as well, but I'd prefer to
>> leave this up to LoadLibrary...
> This problem would only occur if dlopen is not called with a path. If
> the given pathname is a plain filename, we could simply add a call to
> GetModuleHandle and if it succeeds, return the handle (after checking
> for RTLD_NODELETE).
But indeed this might lower the need for same search algorithms...
>> Side note:
>> We also use some cl.exe/link.exe wrapper that supports LD_PRELOAD,
>> LD_LIBRARY_PATH, embedded RUNPATH, as well as lazy loading for both
>> LoadLibrary and CreateProcess: https://github.com/haubi/parity
>> Basically I'm wondering why Cygwin doesn't provide that (yet?)...
> We discussed implementing our own dynamic loader once, but gave up due
> to workload. Parity is LGPLed and thus can't be included into Cygwin
've mentioned Parity more as proof-of-concept than for inclusion,
and accepting workload as reasoning.
Let's see if I can live without the ELF dynloader features.