This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

PATCH : enhance win32 libiberty pex-win32.c for combo install dirs


The attached patch fixes a problem in collect2 when you have a $PREFIX/bin directory where both MINGW32 and X86 linux binaries reside in the same place. Some of those files do not have an extension and some have the ".exe" extension. This fix makes it so that the .exe files will be found in preference to the ones with no extension when running on Windows only.

Patch was built from released, pristine version 4.2.0


--- gcc-4.2.0/libiberty/pex-win32.c.orig	2007-07-07 12:48:50.000000000 -0500
+++ gcc-4.2.0/libiberty/pex-win32.c	2007-07-07 14:01:24.000000000 -0500
@@ -388,11 +388,12 @@
   ".exe",
   ".bat",
   ".cmd",
-  0
-};
-static const char *const
-no_suffixes[] = {
-  "",
+  "",		/*	there might not be any extensions, but search for 
+  			this one last!  because in a combo Windows and 
+			Linux install tree, with both executable types in the
+			same directory, we want the Windows binaries
+			to be found when running under windows, and not the 
+			linux ones which have no extension */
   0
 };
 
@@ -409,7 +410,6 @@
   const char *const *ext;
   const char *p, *q;
   size_t proglen = strlen (program);
-  int has_extension = !!strchr (program, '.');
   int has_slash = (strchr (program, '/') || strchr (program, '\\'));
   HANDLE h;
 
@@ -432,7 +432,7 @@
       if (*q == ';')
 	q++;
     }
-  fe_len = fe_len + 1 + proglen + (has_extension ? 1 : 5);
+  fe_len += proglen + 5;		/* + nul terminated extension */ 
   full_executable = xmalloc (fe_len);
 
   p = path;
@@ -458,9 +458,9 @@
 
       /* At this point, e points to the terminating NUL character for
          full_executable.  */
-      for (ext = has_extension ? no_suffixes : std_suffixes; *ext; ext++)
+      for (ext = std_suffixes; *ext; ext++)
 	{
-	  /* Remove any current extension.  */
+	  /* Remove any current extension from previous iterations of this loop.  */
 	  *e = '\0';
 	  /* Add the new one.  */
 	  strcat (full_executable, *ext);
@@ -591,6 +591,27 @@
 		      si,
 		      pi))
     {
+      DWORD   syserr = GetLastError();
+
+      fprintf(stderr, "failed: win32_spawn:\nexecutable=\"%s\"\nfull_executable=\"%s\"\ncmdline=\"%s\"\n",
+	executable, full_executable, cmdline );
+
+      DWORD_PTR args[2] = { full_executable, NULL };
+      
+      char errtxt[200];
+      
+      FormatMessage( 
+	FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, /* DWORD dwFlags, */
+	0,        /* LPCVOID lpSource, */
+	syserr,   /* dwMessageId, */
+	0,        /* DWORD dwLanguageId, */
+	errtxt,   /* LPTSTR lpBuffer, */
+	sizeof(errtxt),   /* DWORD nSize, */
+	args      /* va_list* Arguments */
+	);
+
+      fprintf(stderr,"GetLastError(): \"%s\"\n", errtxt );      
+        
       if (env_block)
         free (env_block);
 

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