This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 4/4] dlopen: on unspecified lib dir search exe dir


Hi Corinna,

On 09/01/2016 04:05 PM, Corinna Vinschen wrote:
> On Aug 31 20:07, Michael Haubenwallner wrote:
>> Applications installed to some prefix like /opt/application do expect
>> dlopen("libAPP.so") to load "/opt/application/bin/cygAPP.dll", which
>> is similar to "/opt/application/lib/libAPP.so" on Linux.
>>
>> See also https://cygwin.com/ml/cygwin-developers/2016-08/msg00020.html
>>
>> * dlfcn.cc (dlopen): For dlopen("N"), search directory where the
>> application executable is in.
>> ---
>>  winsup/cygwin/dlfcn.cc | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/winsup/cygwin/dlfcn.cc b/winsup/cygwin/dlfcn.cc
>> index f8b8743..974092e 100644
>> --- a/winsup/cygwin/dlfcn.cc
>> +++ b/winsup/cygwin/dlfcn.cc
>> @@ -232,6 +232,12 @@ dlopen (const char *name, int flags)
>>  	     not use the LD_LIBRARY_PATH environment variable. */
>>  	  finder.add_envsearchpath ("LD_LIBRARY_PATH");
>>  
>> +	  /* Search the current executable's directory like
>> +	     the Windows loader does for linked dlls. */
>> +	  int exedirlen = get_exedir (cpath, wpath);
>> +	  if (exedirlen)
>> +	    finder.add_searchdir (cpath, exedirlen);
>> +
>>  	  /* Finally we better have some fallback. */
>>  	  finder.add_searchdir ("/usr/bin", 8);
>>  	  finder.add_searchdir ("/usr/lib", 8);
>> -- 
>> 2.7.3
> 
> Still not quite sure if that's the right thing to do...

Hmm... dlopen ought to be an API to the "runtime loader",
and as such it ought to use the same search algorithm as
exec (=CreateProcess) when searching for the linked dlls.

So as far as I understand: The Windows loader uses the main
executable's directory as kinda "embedded runpath" for process
startup, and dlopen is not the right place to change this - even
if LoadLibrary provides such mechanisms (Set/AddDllDirectory).

btw: Patch 4 updated to follow the update of patch 3.

Thanks!
/haubi/
>From a94e55a6ba366e960533c610464043afa0e8bff0 Mon Sep 17 00:00:00 2001
From: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
Date: Wed, 31 Aug 2016 18:25:13 +0200
Subject: [PATCH 4/4] dlopen: on unspecified lib dir search exe dir

Applications installed to some prefix like /opt/application do expect
dlopen("libAPP.so") to load "/opt/application/bin/cygAPP.dll", which
is similar to "/opt/application/lib/libAPP.so" on Linux.

See also https://cygwin.com/ml/cygwin-developers/2016-08/msg00020.html

* dlfcn.cc (dlopen): For dlopen("N"), search directory where the
application executable is in.
---
 winsup/cygwin/dlfcn.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/winsup/cygwin/dlfcn.cc b/winsup/cygwin/dlfcn.cc
index 3b07208..c5839a7 100644
--- a/winsup/cygwin/dlfcn.cc
+++ b/winsup/cygwin/dlfcn.cc
@@ -232,6 +232,12 @@ dlopen (const char *name, int flags)
 	     not use the LD_LIBRARY_PATH environment variable. */
 	  finder.add_envsearchpath ("LD_LIBRARY_PATH");
 
+	  /* Search the current executable's directory like
+	     the Windows loader does for linked dlls. */
+	  int exedirlen = get_exedir (cpath);
+	  if (exedirlen)
+	    finder.add_searchdir (cpath, exedirlen);
+
 	  /* Finally we better have some fallback. */
 	  finder.add_searchdir ("/usr/bin", 8);
 	  finder.add_searchdir ("/usr/lib", 8);
-- 
2.8.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]