Bug 86039 - Compiler placed in deep/long folder cannot open/run needed files on Windows
Summary: Compiler placed in deep/long folder cannot open/run needed files on Windows
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 6.3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-04 13:01 UTC by Samuel Hultgren
Modified: 2018-06-05 13:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
output of compilation with compiler in directories with different length (1.33 KB, text/plain)
2018-06-04 13:01 UTC, Samuel Hultgren
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel Hultgren 2018-06-04 13:01:02 UTC
Created attachment 44229 [details]
output of compilation with compiler in directories with different length

If the compiler file structure is placed in a folder with a name that is 163 characters or longer, the GCC will fail to include certain files and/or run sub-programs (cc1.exe etc).

Tested on Windows 7, and Windows 10, with GCC based on 6.3.1.

How to reproduce:
Create a simple file c:\test.c:
#include <stdio.h>
int main()
{
  return 0;
}

Place a Windows native GCC toolchain in a folder called c:\1 which includes the bin, lib, share and target folders directly in it.

Use cygwin or other environment to run help script to try with different folder name lengths:
cd /cygdrive/c
str=""
for i in `seq 1 256`; 
do 
echo "Testing length $i";
str="1$str"; 
mv 1* $str; 
1*/bin/arm-none-eabi-gcc test.c -o test.o --specs=nano.specs -specs=nosys.specs;
done

Adjust above script as necessary for your environment, but you should get similar results to the attached output.

In the attached output we can see that when the folder name is 163 characters or longer, we see the first type of error, GCC can no longer find all the header files in the compiler structure.
At folder length 180, GCC can no longer find stdio.h.
At folder length 214, GCC no longer can CreateProcess cc1.exe.

After that length specs files can not be found.
Comment 1 Jim Wilson 2018-06-04 17:46:14 UTC
Windows has a 260 character default maximum path length.  See for instance
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath

This looks like an OS problem not a gcc problem.
Comment 2 Samuel Hultgren 2018-06-05 11:58:38 UTC
(In reply to Jim Wilson from comment #1)
> Windows has a 260 character default maximum path length.  See for instance
> https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).
> aspx#maxpath
> 
> This looks like an OS problem not a gcc problem.

Maybe both.

It is possible to read/write files that have longer paths than 260 characters if you use UNC paths by prefixing absolute paths with "\\?\" on Windows.

For executing files on Windows we can improve the situation by using a combination of UNC paths together with GetShortPathNameW before sending the path to CreateProcessW. Only restriction here is that the resulting shorted path must still be shorter than 260 characters.