This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


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

[patch] ld [pei] add --dll-search-prefix option


In an attempt to minimize dll naming conflicts (AKA 'dll hell') on the
various platforms that coexist simultaneously on Win32, the following
patch adds a new option '--dll-search-prefix=<prefix>'.  If 
specified, AND linking dynamically, then the dynamic library search
order is modified from:

current: lib<basename>.dll.a
         <basename>.dll.a
         lib<basename>.a
         lib<basename>.dll
         <basename>.dll

new:     lib<basename>.dll.a
         <basename>.dll.a
         lib<basename>.a
  >>>    <prefix><basename>.dll
         lib<basename>.dll
         <basename>.dll

In this way, the various win32 platforms (cygwin, mingw, pw, uwin, etc)
can modify their spec file to use an appropriate prefix for dlls (e.g.
--dll-search-prefix=cyg for cygwin).  This allows dlls to be uniquely
named for each platform, even for identical libraries, but still allows
ld to link directly to the given dll without the use of an import lib
when desired.

See the following thread on the cygwin mailing list (really long):
http://sources.redhat.com/ml/cygwin/2000-08/msg01128.html  (DLL naming
conventions)

Also, many of the 'DLL naming conventions' messages were crossposted to
the libtool mailing list, and can be viewed on these three pages: 
http://www.geocrawler.com/archives/3/404/2000/9/0
http://www.geocrawler.com/archives/3/404/2000/9/50
http://www.geocrawler.com/archives/3/404/2000/9/100

A related thread on the libtool list begins here: 'RE: libtool'
http://www.geocrawler.com/archives/3/404/2000/9/0/4321378/

--Charles Wilson

2000-10-07  Charles Wilson <cwilson@ece.gatech.edu>

	* emultempl/pe.em (pe_dll_search_prefix): New variable,
	(longopts): New --dll-search-prefix option.
	(gld_${EMULATION_NAME}_list_options): Document.
	(gld_${EMULATION_NAME}_parse_args): Handle.
	(gld_${EMULATION_NAME}_open_dynamic_archive): When linking
	dynamically, search for a dll named '<prefix><basename>.dll'
	in preference to 'lib<basename>.dll' if --dll-search-prefix
	is specified.
Index: ld/emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.33
diff -u -r1.33  old/ld/emultempl/pe.em new/ld/emultempl/pe.em
--- old/ld/emultempl/pe.em	2000/10/02 14:39:46	1.33
+++ new/ld/emultempl/pe.em	2000/10/07 04:46:18
@@ -119,6 +119,7 @@
 static char *pe_out_def_filename = NULL;
 static char *pe_implib_filename = NULL;
 static int pe_enable_auto_image_base = 0;
+static char *pe_dll_search_prefix = NULL;
 #endif
 
 extern const char *output_filename;
@@ -172,6 +173,7 @@
 #define OPTION_IMP_COMPAT		(OPTION_WARN_DUPLICATE_EXPORTS + 1)
 #define OPTION_ENABLE_AUTO_IMAGE_BASE	(OPTION_IMP_COMPAT + 1)
 #define OPTION_DISABLE_AUTO_IMAGE_BASE	(OPTION_ENABLE_AUTO_IMAGE_BASE + 1)
+#define OPTION_DLL_SEARCH_PREFIX		(OPTION_DISABLE_AUTO_IMAGE_BASE + 1)
 
 static struct option longopts[] =
 {
@@ -208,6 +210,7 @@
   {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
   {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
   {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
+  {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
 #endif
   {NULL, no_argument, NULL, 0}
 };
@@ -290,6 +293,9 @@
   fprintf (file, _("  --enable-auto-image-base           Automatically choose image base for DLLs\n"));
   fprintf (file, _("                                       unless user specifies one\n"));
   fprintf (file, _("  --disable-auto-image-base          Do not auto-choose image base. (default)\n"));
+  fprintf (file, _("  --dll-search-prefix=<string>       When linking dynamically to a dll witout an\n"));
+  fprintf (file, _("                                       importlib, use <string><basename>.dll \n"));
+  fprintf (file, _("                                       in preference to lib<basename>.dll \n"));
 #endif
 }
 
@@ -554,6 +560,9 @@
     case OPTION_DISABLE_AUTO_IMAGE_BASE:
       pe_enable_auto_image_base = 0;
       break;
+    case OPTION_DLL_SEARCH_PREFIX:
+      pe_dll_search_prefix = xstrdup( optarg );
+      break;
 #endif
     }
   return 1;
@@ -1452,6 +1461,7 @@
   string = (char *) xmalloc (strlen (search->name)
                              + strlen (filename) 
                              + sizeof "/lib.a.dll"
+                             + ( pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0 )
                              + 1);
 
   /* Try "libfoo.dll.a" first (preferred explicit import library for dll's */
@@ -1478,19 +1488,44 @@
              take precedence over dll's) */
           sprintf (string, "%s/lib%s.a", search->name, filename);
           if (! ldfile_try_open_bfd (string, entry))
-	    {
-              /* Try "libfoo.dll" (preferred dll name) */
-              sprintf (string, "%s/lib%s.dll", search->name, filename);
-              if (! ldfile_try_open_bfd (string, entry))
-                {
-                  /* Finally, try "foo.dll" (alternate dll name) */
-                  sprintf (string, "%s/%s.dll", search->name, filename);
+            {
+
+              if ( pe_dll_search_prefix )
+                {  
+                  /* Try "<prefix>foo.dll" (preferred dll name, if specified) */
+                  sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
                   if (! ldfile_try_open_bfd (string, entry))
                     {
-                      free (string);
-                      return false;
+                      /* Try "libfoo.dll" (default preferred dll name) */
+                      sprintf (string, "%s/lib%s.dll", search->name, filename);
+                      if (! ldfile_try_open_bfd (string, entry))
+                        {
+                          /* Finally, try "foo.dll" (alternate dll name) */
+                          sprintf (string, "%s/%s.dll", search->name, filename);
+                          if (! ldfile_try_open_bfd (string, entry))
+                            {
+                              free (string);
+                              return false;
+                            }
+                        }
                     }
                 }
+              else /* pe_dll_search_prefix not specified */
+                {
+                  /* Try "libfoo.dll" (preferred dll name) */
+                  sprintf (string, "%s/lib%s.dll", search->name, filename);
+                  if (! ldfile_try_open_bfd (string, entry))
+                    {
+                      /* Finally, try "foo.dll" (alternate dll name) */
+                      sprintf (string, "%s/%s.dll", search->name, filename);
+                      if (! ldfile_try_open_bfd (string, entry))
+                        {
+                          free (string);
+                          return false;
+                        }
+                    }
+                } /* if (pe_dll_search_prefix) */
+					 
             }
         }
     }

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