This is the mail archive of the cygwin-developers 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: RFC: Cygwin 64 bit?


On Jul  3 11:21, Corinna Vinschen wrote:
> On Jul  2 22:52, Charles Wilson wrote:
> > Anyway, that's why I suggested that we add, now, a "fix" to cygwin64's
> > dlopen to 'substitute' dlopen("cyg64*") for requests to dlopen("cyg*")
> 
> Good point.
> 
> IMHO the order should be something like this:
> 
>   Is suffix ".so"?
>     Yes -> Does the file exist?
>       Yes -> Done
>       No  -> Replace ".so" with ".dll"
> #ifdef __X86_64__
>   Does the filename start with "cyg"?
>     Yes -> Replace "cyg" with "cyg64"
>       Does the file exist?
>       	No -> Revert back to "cyg"
> #endif
>   Does the filename start with "lib"?
>     Yes -> Replace "lib" with "cyg"/"cyg64"
>       Does the file exist?
>         No -> Revert back to "lib"
>   Does the file exist?
>     Yes -> Done
>   return ENOENT

I implemented the above algorithm for 32 bit Cygwin now, so DLLs are
searched for in dlopen using the above algorithm.

The patch also changes the default search path.  As before, it first
checks for LD_LIBRARY_PATH.  However, given the fact that all shared
libs which are usually in /usr/lib on other systems, are in /usr/bin
on Cygwin, it makes a lot of sense to add /usr/bin to the search path.

Is that something we should do now?


Corinna

	* dlfcn.cc (gfpod_helper): Helper function to search DLL using
	a given DLL name.  Change default search path to allow /usr/bin.
	(get_full_path_of_dll): Find DLLs even if the caller used a ".so"
	suffix or a "lib" prefix for the DLL.

Index: dlfcn.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dlfcn.cc,v
retrieving revision 1.50
diff -u -p -r1.50 dlfcn.cc
--- dlfcn.cc	6 Jun 2011 05:02:09 -0000	1.50
+++ dlfcn.cc	15 Aug 2011 17:13:01 -0000
@@ -38,6 +38,18 @@ check_path_access (const char *mywinenv,
 
 /* Search LD_LIBRARY_PATH for dll, if it exists.
    Return Windows version of given path. */
+static inline bool
+gfpod_helper (const char *name, path_conv &real_filename)
+{
+  if (isabspath (name) ||
+      (check_path_access ("LD_LIBRARY_PATH=", name, real_filename)
+       ?: check_path_access ("/usr/bin:/usr/lib", name, real_filename)) == NULL)
+    real_filename.check (name, PC_SYM_FOLLOW | PC_NULLEMPTY);
+  if (!real_filename.exists ())
+    real_filename.error = ENOENT;
+  return !real_filename.error;
+}
+
 static bool __stdcall
 get_full_path_of_dll (const char* str, path_conv &real_filename)
 {
@@ -55,12 +67,33 @@ get_full_path_of_dll (const char* str, p
 
   strcpy (name, str);	/* Put it somewhere where we can manipulate it. */
 
-  if (isabspath (name) ||
-      (check_path_access ("LD_LIBRARY_PATH=", name, real_filename)
-       ?: check_path_access ("/usr/lib", name, real_filename)) == NULL)
-    real_filename.check (name, PC_SYM_FOLLOW | PC_NOFULL | PC_NULLEMPTY);
+  char *basename = strrchr (name, '/');
+  basename = basename ? basename + 1 : name;
+  char *suffix = strrchr (name, '.');
+  if (suffix && suffix < basename)
+    suffix = NULL;
 
-  if (!real_filename.error)
+  /* Is suffix ".so"? */
+  if (suffix && !strcmp (suffix, ".so"))
+    {
+      /* Does the file exist? */
+      if (gfpod_helper (name, real_filename))
+	return true;
+      /* No, replace ".so" with ".dll". */
+      strcpy (suffix, ".dll");
+    }
+  /* Does the filename start with "lib"? */
+  if (!strncmp (basename, "lib", 3))
+    {
+      /* Yes, replace "lib" with "cyg". */
+      strncpy (basename, "cyg", 3);
+      /* Does the file exist? */
+      if (gfpod_helper (name, real_filename))
+	return true;
+      /* No, revert back to "lib". */
+      strncpy (basename, "lib", 3);
+    }
+  if (gfpod_helper (name, real_filename))
     return true;
 
   set_errno (real_filename.error);

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


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