public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows
@ 2022-01-17 16:32 sundeep.kokkonda
  2022-01-18  3:51 ` Andrew Pinski
  0 siblings, 1 reply; 5+ messages in thread
From: sundeep.kokkonda @ 2022-01-17 16:32 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 207 bytes --]

Hello,

 

The '-MF' option cannot deal with path size >256 characters in Windows. This
patch is to fix this long path issue with -MF option.

Let me know is it ok to commit?

 

 

--

Thanks,

Sundeep K.


[-- Attachment #2: c-opts.patch --]
[-- Type: application/octet-stream, Size: 2375 bytes --]

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index aa6801fa811..b8269548bf3 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -41,6 +41,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "mkdeps.h"
 #include "dumpfile.h"
 #include "file-prefix-map.h"    /* add_*_prefix_map()  */
+#include "filenames.h"
+
+#if defined (_WIN32)
+#include <windows.h>
+#endif
 
 #ifndef DOLLARS_IN_IDENTIFIERS
 # define DOLLARS_IN_IDENTIFIERS true
@@ -1291,10 +1296,53 @@ c_common_finish (void)
 	deps_stream = stdout;
       else
 	{
-	  deps_stream = fopen (deps_file, deps_append ? "a": "w");
-	  if (!deps_stream)
-	    fatal_error (input_location, "opening dependency file %s: %m",
-			 deps_file);
+	  #if defined (_WIN32)
+          size_t filelen;
+	  
+	  /* PR 25713: Handle extra long path names.
+	   * * For relative paths, convert them to absolute, in case that version is too long.  */
+	  
+	  if (! IS_ABSOLUTE_PATH (deps_file))
+	  {
+                char cwd[1024];
+
+                getcwd (cwd, sizeof (cwd));
+                filelen = strlen (cwd) + 1;
+                strncat (cwd, "\\", sizeof (cwd) - filelen);
+                ++ filelen;
+                strncat (cwd, deps_file, sizeof (cwd) - filelen);
+                deps_file = cwd;
+	  }
+	  
+	  filelen = strlen (deps_file) + 1;
+	  
+	  if (filelen > MAX_PATH - 1)
+	  {
+                char * fullpath;
+	       
+		fullpath = (char *) xmalloc (filelen + 8);
+
+                /* Add a Microsoft recommended prefix that will allow the extra-long path to work. */
+                strcpy (fullpath, "\\\\?\\");
+                strcat (fullpath, deps_file);
+
+                for (int i = 0; fullpath[i]; i++)
+                {
+                        if (IS_UNIX_DIR_SEPARATOR (fullpath[i]))
+				fullpath[i] = '\\';
+                }
+
+                deps_stream = fopen (fullpath, deps_append ? "a": "w");
+                free (fullpath);
+	  }
+	  else
+		  deps_stream = fopen (deps_file, deps_append ? "a": "w");
+	#else
+        deps_stream = fopen (deps_file, deps_append ? "a": "w");
+        #endif
+        if (!deps_stream)
+                fatal_error (input_location, "opening dependency file %s: %m",
+                                deps_file);
 	}
     }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows
  2022-01-17 16:32 [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows sundeep.kokkonda
@ 2022-01-18  3:51 ` Andrew Pinski
  2022-01-19  5:09   ` sundeep.kokkonda
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Pinski @ 2022-01-18  3:51 UTC (permalink / raw)
  To: sundeep.kokkonda; +Cc: GCC Patches

On Mon, Jan 17, 2022 at 8:35 AM Sundeep KOKKONDA via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hello,
>
>
>
> The '-MF' option cannot deal with path size >256 characters in Windows. This
> patch is to fix this long path issue with -MF option.
>
> Let me know is it ok to commit?

I don't think this is the right place to put this.
Maybe a better way to implement this is to have a wrapper around fopen
for windows and do it that way.
Does open have the same issue?

Thanks,
Andrew Pinski

>
>
>
>
>
> --
>
> Thanks,
>
> Sundeep K.
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows
  2022-01-18  3:51 ` Andrew Pinski
@ 2022-01-19  5:09   ` sundeep.kokkonda
  2022-02-04  3:59     ` sundeep.kokkonda
  0 siblings, 1 reply; 5+ messages in thread
From: sundeep.kokkonda @ 2022-01-19  5:09 UTC (permalink / raw)
  To: 'Andrew Pinski'; +Cc: 'GCC Patches'

[-- Attachment #1: Type: text/plain, Size: 975 bytes --]

Hello Andrew,

I updated the patch. Please see attached patch files and let me know your feedback.



Thanks,
Sundeep K.

-----Original Message-----
From: Andrew Pinski <pinskia@gmail.com> 
Sent: Tuesday, January 18, 2022 9:22 AM
To: sundeep.kokkonda@gmail.com
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows

On Mon, Jan 17, 2022 at 8:35 AM Sundeep KOKKONDA via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>
> Hello,
>
>
>
> The '-MF' option cannot deal with path size >256 characters in 
> Windows. This patch is to fix this long path issue with -MF option.
>
> Let me know is it ok to commit?

I don't think this is the right place to put this.
Maybe a better way to implement this is to have a wrapper around fopen for windows and do it that way.
Does open have the same issue?

Thanks,
Andrew Pinski

>
>
>
>
>
> --
>
> Thanks,
>
> Sundeep K.
>

[-- Attachment #2: lrealpath.patch --]
[-- Type: application/octet-stream, Size: 1219 bytes --]

diff --git a/libiberty/lrealpath.c b/libiberty/lrealpath.c
index 3c7053b0b70..593b51c2d96 100644
--- a/libiberty/lrealpath.c
+++ b/libiberty/lrealpath.c
@@ -36,6 +36,8 @@ components will be simplified.  The returned value will be allocated using
 #include "config.h"
 #include "ansidecl.h"
 #include "libiberty.h"
+#include <malloc.h>
+#include "filenames.h"
 
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
@@ -138,6 +140,32 @@ lrealpath (const char *filename)
   {
     char buf[MAX_PATH];
     char* basename;
+
+    size_t filelen;
+    
+    filelen = strlen (filename) + 1;
+
+    if (filelen > MAX_PATH - 1)
+    {
+	    char * fullpath;
+	    fullpath = (char *) malloc (filelen+8);
+
+	    filelen = strlen (filename)+1;
+	    strcpy(fullpath,"\\\\?\\");
+	    strcat(fullpath,filename);
+
+	    for (int i = 0; fullpath[i]; i++)
+	    {
+		    if (IS_UNIX_DIR_SEPARATOR (fullpath[i]))
+			    fullpath[i] = '\\';
+	    }
+
+	    strcpy(filename,fullpath);
+	    free(fullpath);
+
+	    return (strdup(filename));
+    }
+
     DWORD len = GetFullPathName (filename, MAX_PATH, buf, &basename);
     if (len == 0 || len > MAX_PATH - 1)
       return strdup (filename);

[-- Attachment #3: c-opts.patch --]
[-- Type: application/octet-stream, Size: 492 bytes --]

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index aa6801fa811..0f019fb1caa 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1291,7 +1291,7 @@ c_common_finish (void)
 	deps_stream = stdout;
       else
 	{
-	  deps_stream = fopen (deps_file, deps_append ? "a": "w");
+	  deps_stream = fopen (lrealpath(deps_file), deps_append ? "a": "w");
 	  if (!deps_stream)
 	    fatal_error (input_location, "opening dependency file %s: %m",
 			 deps_file);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows
  2022-01-19  5:09   ` sundeep.kokkonda
@ 2022-02-04  3:59     ` sundeep.kokkonda
  2022-02-22  5:21       ` sundeep.kokkonda
  0 siblings, 1 reply; 5+ messages in thread
From: sundeep.kokkonda @ 2022-02-04  3:59 UTC (permalink / raw)
  To: 'Andrew Pinski'; +Cc: 'GCC Patches'

Hello Andrew,

Can you please let me know your feedback on the patch?


Thanks,
Sundeep K.

-----Original Message-----
From: sundeep.kokkonda@gmail.com <sundeep.kokkonda@gmail.com> 
Sent: Wednesday, January 19, 2022 10:40 AM
To: 'Andrew Pinski' <pinskia@gmail.com>
Cc: 'GCC Patches' <gcc-patches@gcc.gnu.org>
Subject: RE: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows

Hello Andrew,

I updated the patch. Please see attached patch files and let me know your feedback.



Thanks,
Sundeep K.

-----Original Message-----
From: Andrew Pinski <pinskia@gmail.com>
Sent: Tuesday, January 18, 2022 9:22 AM
To: sundeep.kokkonda@gmail.com
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows

On Mon, Jan 17, 2022 at 8:35 AM Sundeep KOKKONDA via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>
> Hello,
>
>
>
> The '-MF' option cannot deal with path size >256 characters in 
> Windows. This patch is to fix this long path issue with -MF option.
>
> Let me know is it ok to commit?

I don't think this is the right place to put this.
Maybe a better way to implement this is to have a wrapper around fopen for windows and do it that way.
Does open have the same issue?

Thanks,
Andrew Pinski

>
>
>
>
>
> --
>
> Thanks,
>
> Sundeep K.
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows
  2022-02-04  3:59     ` sundeep.kokkonda
@ 2022-02-22  5:21       ` sundeep.kokkonda
  0 siblings, 0 replies; 5+ messages in thread
From: sundeep.kokkonda @ 2022-02-22  5:21 UTC (permalink / raw)
  To: 'GCC Patches', 'Andrew Pinski'

Hello,

Can you please review the patch and let me know the feedback?



Thanks,
Sundeep K.

-----Original Message-----
From: sundeep.kokkonda@gmail.com <sundeep.kokkonda@gmail.com> 
Sent: Friday, February 4, 2022 9:30 AM
To: 'Andrew Pinski' <pinskia@gmail.com>
Cc: 'GCC Patches' <gcc-patches@gcc.gnu.org>
Subject: RE: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows

Hello Andrew,

Can you please let me know your feedback on the patch?


Thanks,
Sundeep K.

-----Original Message-----
From: sundeep.kokkonda@gmail.com <sundeep.kokkonda@gmail.com>
Sent: Wednesday, January 19, 2022 10:40 AM
To: 'Andrew Pinski' <pinskia@gmail.com>
Cc: 'GCC Patches' <gcc-patches@gcc.gnu.org>
Subject: RE: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows

Hello Andrew,

I updated the patch. Please see attached patch files and let me know your feedback.



Thanks,
Sundeep K.

-----Original Message-----
From: Andrew Pinski <pinskia@gmail.com>
Sent: Tuesday, January 18, 2022 9:22 AM
To: sundeep.kokkonda@gmail.com
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows

On Mon, Jan 17, 2022 at 8:35 AM Sundeep KOKKONDA via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>
> Hello,
>
>
>
> The '-MF' option cannot deal with path size >256 characters in 
> Windows. This patch is to fix this long path issue with -MF option.
>
> Let me know is it ok to commit?

I don't think this is the right place to put this.
Maybe a better way to implement this is to have a wrapper around fopen for windows and do it that way.
Does open have the same issue?

Thanks,
Andrew Pinski

>
>
>
>
>
> --
>
> Thanks,
>
> Sundeep K.
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-22  5:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 16:32 [PATCH] Fix for GCC '-MF' option cannot deal with long paths in Windows sundeep.kokkonda
2022-01-18  3:51 ` Andrew Pinski
2022-01-19  5:09   ` sundeep.kokkonda
2022-02-04  3:59     ` sundeep.kokkonda
2022-02-22  5:21       ` sundeep.kokkonda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).