https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96027

            Bug ID: 96027
           Summary: Windows: gcc does not resolve long relative header
                    paths correctly
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kai.koehne at qt dot io
  Target Milestone: ---

Created attachment 48823
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48823&action=edit
Test case with directory structure; should be extracted to C:\

In some scenarios gcc on Windows does not resolve includes of headers
correctly, resulting in errors like:

> fatal error: 
> ../../../../../src/BBBBBBBBBBBBBBB/BBBBBBBBBBBBB/BBBBBBBB/BBBBBBBBBBBBBBBBBBBBBBB.h:
>  No such file or directory

The exact circumstances are unclear, but both the length of the (relative)
header path and the length of the absolute paths in the file system play a
role.

Attached you can find a somewhat minimal example, which you need to extract
into a top-level directory (e.g. C:\).

# HOW TO REPRODUCE

Open Windows command line. Extract attachment into C:\, navigate into AAAAAAA,
run e.g. mingw32-make:

> C:\AAAAAAA>mingw32-make
> cd 
> AAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AAAAAA/src/AAAAAAA/AAAAAAAAA/AAAAAAAAA
>  && mingw32-make
> mingw32-make[1]: Entering directory 
> 'C:/AAAAAAA/AAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AAAAAA/src/AAAAAAA/AAAAAAAAA/AAAAAAAAA'
> gcc.exe -I../../../../include/CCCCCCCCCCCCCCCCCCCCC\CCCCCC test.cpp
> In file included from test.cpp:1:
> ../../../../include/CCCCCCCCCCCCCCCCCCCCC\CCCCCC/BBBBBBBBBBBBBBBBBBBBB/BBBBBBB/BBBBBBBBBBBBBBBBBBBBBBB.h:1:10:
>  fatal error: 
> ../../../../../src/BBBBBBBBBBBBBBB/BBBBBBBBBBBBB/BBBBBBBB/BBBBBBBBBBBBBBBBBBBBBBB.h:
>  No such file or directory
> #include 
> "../../../../../src/BBBBBBBBBBBBBBB/BBBBBBBBBBBBB/BBBBBBBB/BBBBBBBBBBBBBBBBBBBBBBB.h"
>          > 
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> compilation terminated.

# WHAT IS THE EXPECTED OUPUT

If using clang, the header file is found:

> clang.exe -I../../../../include/CCCCCCCCCCCCCCCCCCCCC\CCCCCC test.cpp
> In file included from test.cpp:1:
> In file included from 
> ../../../../include/CCCCCCCCCCCCCCCCCCCCC\CCCCCC\BBBBBBBBBBBBBBBBBBBBB/BBBBBBB/BBBBBBBBBBBBBBBBBBBBBBB.h:1:
> ../../../../include/CCCCCCCCCCCCCCCCCCCCC\CCCCCC\BBBBBBBBBBBBBBBBBBBBB/BBBBBBB/../../../../../src/BBBBBBBBBBBBBBB/BBBBBBBBBBBBB/BBBBBBBB/BBBBBBBBBBBBBBBBBBBBBBB.h:1:9:
>  warning:
>       HEADER FILE WAS FOUND, ALL GOOD! [-W#pragma-messages]
> #pragma message "HEADER FILE WAS FOUND, ALL GOOD!"
>        ^
> 1 warning generated.

The same is also true for gcc if the path is shortened, e.g. by shortening the
very first path:

> C:\AAAAAAA>subst X: .
> 
> C:\AAAAAAA>X:
> 
> X:\>mingw32-make
> cd 
> AAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AAAAAA/src/AAAAAAA/AAAAAAAAA/AAAAAAAAA
>  && mingw32-make
> mingw32-make[1]: Entering directory 
> 'X:/AAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AAAAAA/src/AAAAAAA/AAAAAAAAA/AAAAAAAAA'
> gcc.exe -I../../../../include/CCCCCCCCCCCCCCCCCCCCC\CCCCCC test.cpp
> In file included from 
> ../../../../include/CCCCCCCCCCCCCCCCCCCCC\CCCCCC/BBBBBBBBBBBBBBBBBBBBB/BBBBBBB/BBBBBBBBBBBBBBBBBBBBBBB.h:1,
>                 from test.cpp:1:
> x:\aaaaaaaaa\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\aaaaaa\src\bbbbbbbbbbbbbbb\bbbbbbbbbbbbb\bbbbbbbb\bbbbbbbbbbbbbbbbbbbbbbb.h:1:17:
>  note: '#pragma message: HEADER FILE WAS FOUND, ALL GOOD!'
>    1 | #pragma message "HEADER FILE WAS FOUND, ALL GOOD!"
>      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> mingw32-make[1]: Leaving directory 
> 'X:/AAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AAAAAA/src/AAAAAAA/AAAAAAAAA/AAAAAAAAA'

# FURTHER INSIGHTS

If monitoring the Windows API it becomes clear that gcc somehow tries a wrong
path:

> 10:52:44,2386745      cc1plus.exe     20520   CreateFile      
> C:\aaaaaaa\aaaaaaaaa\src\bbbbbbbbbbbbbbb\bbbbbbbbbbbbb\bbbbbbbb\bbbbbbbbbbbbbbbbbbbbbbb.h
>        PATH NOT FOUND  Desired Access: Generic Read, Disposition: Open, 
> Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, 
> ShareMode: Read, Write, AllocationSize: n/a
> 10:52:44,2387339      cc1plus.exe     20520   CreateFile      
> C:\src\bbbbbbbbbbbbbbb\bbbbbbbbbbbbb\bbbbbbbb\bbbbbbbbbbbbbbbbbbbbbbb.h PATH 
> NOT FOUND  Desired Access: Generic Read, Disposition: Open, Options: 
> Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, 
> Write, AllocationSize: n/a
> 10:52:44,2387899      cc1plus.exe     20520   CreateFile      
> C:\winlibs\src\bbbbbbbbbbbbbbb\bbbbbbbbbbbbb\bbbbbbbb\bbbbbbbbbbbbbbbbbbbbbbb.h
>  PATH NOT FOUND  Desired Access: Generic Read, Disposition: Open, Options: 
> Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, 
> Write, AllocationSize: n/a
> 10:52:44,2388532      cc1plus.exe     20520   CreateFile      
> C:\winlibs\winlibs-x86_64-posix-seh-gcc-10.1.0-llvm-10.0.0-mingw-w64-7.0.0-r3\src\bbbbbbbbbbbbbbb\bbbbbbbbbbbbb\bbbbbbbb\bbbbbbbbbbbbbbbbbbbbbbb.h
>       PATH NOT FOUND  Desired Access: Generic Read, Disposition: Open, 
> Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, 
> ShareMode: Read, Write, AllocationSize: n/a

# GCC VERSIONS TESTED

> Using built-in specs.
> COLLECT_GCC=C:\winlibs\winlibs-x86_64-posix-seh-gcc-10.1.0-llvm-10.0.0-mingw-w64-7.0.0-r3\bin\gcc.exe
> COLLECT_LTO_WRAPPER=c:/winlibs/winlibs-x86_64-posix-seh-gcc-10.1.0-llvm-10.0.0-mingw-w64-7.0.0-r3/bin/../libexec/gcc/x86_64-w64-mingw32/10.1.0/lto-wrapper.exe
> Target: x86_64-w64-mingw32
> Configured with: ../configure 
> --prefix=/R/winlibs64_10.1.0/inst_gcc-10.1.0/share/gcc 
> --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 
> --with-pkgversion='MinGW-W64 x86_64-posix-seh, built by Brecht Sanders' 
> --with-tune=generic --enable-checking=release --enable-threads=posix 
> --disable-sjlj-exceptions --disable-libunwind-exceptions 
> --enable-serial-configure --disable-bootstrap --enable-host-shared 
> --enable-plugin --enable-default-ssp --disable-rpath --disable-libstdcxx-pch 
> --enable-libstdcxx-time=yes --disable-libstdcxx-debug 
> --disable-version-specific-runtime-libs --with-stabs --disable-symvers 
> --enable-languages=c,c++,fortran,lto,objc,obj-c++,d --disable-gold 
> --disable-nls --disable-stage1-checking --disable-win32-registry 
> --disable-multilib --enable-ld --enable-libquadmath --enable-libada 
> --enable-libssp --enable-libstdcxx --enable-lto --enable-fully-dynamic-string 
> --enable-libgomp --enable-graphite --enable-mingw-wildcard 
> --with-mpc=/d/winlibs64_10.1.0/custombuilt 
> --with-mpfr=/d/winlibs64_10.1.0/custombuilt 
> --with-gmp=/d/winlibs64_10.1.0/custombuilt 
> --with-isl=/d/winlibs64_10.1.0/custombuilt --enable-install-libiberty 
> --enable-__cxa_atexit --without-included-gettext 
> --with-diagnostics-color=auto --with-libiconv --with-system-zlib 
> --with-build-sysroot=/R/winlibs64_10.1.0/gcc-10.1.0/build_mingw/mingw-w64
> Thread model: posix
> Supported LTO compression algorithms: zlib zstd
> gcc version 10.1.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders)

> Using built-in specs.
> COLLECT_GCC=C:\mingw-builds\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\bin\gcc
> COLLECT_LTO_WRAPPER=C:/mingw-builds/i686-8.1.0-release-posix-dwarf-rt_v6-rev0/bin/../libexec/gcc/i686-w64-mingw32/8.1.0/lto-wrapper.exe
> Target: i686-w64-mingw32
> Configured with: ../../../src/gcc-8.1.0/configure --host=i686-w64-mingw32 
> --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 
> --with-sysroot=/c/mingw810/i686-810-posix-dwarf-rt_v6-rev0/mingw32 
> --enable-shared --enable-static --disable-multilib 
> --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes 
> --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto 
> --enable-graphite --enable-checking=release --enable-fully-dynamic-string 
> --enable-version-specific-runtime-libs --disable-sjlj-exceptions 
> --with-dwarf2 --disable-libstdcxx-pch --disable-libstdcxx-debug 
> --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls 
> --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld 
> --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib 
> --with-gmp=/c/mingw810/prerequisites/i686-w64-mingw32-static 
> --with-mpfr=/c/mingw810/prerequisites/i686-w64-mingw32-static 
> --with-mpc=/c/mingw810/prerequisites/i686-w64-mingw32-static 
> --with-isl=/c/mingw810/prerequisites/i686-w64-mingw32-static 
> --with-pkgversion='i686-posix-dwarf-rev0, Built by MinGW-W64 project' 
> --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe 
> -fno-ident -I/c/mingw810/i686-810-posix-dwarf-rt_v6-rev0/mingw32/opt/include 
> -I/c/mingw810/prerequisites/i686-zlib-static/include 
> -I/c/mingw810/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 
> -pipe -fno-ident 
> -I/c/mingw810/i686-810-posix-dwarf-rt_v6-rev0/mingw32/opt/include 
> -I/c/mingw810/prerequisites/i686-zlib-static/include 
> -I/c/mingw810/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS=' 
> -I/c/mingw810/i686-810-posix-dwarf-rt_v6-rev0/mingw32/opt/include 
> -I/c/mingw810/prerequisites/i686-zlib-static/include 
> -I/c/mingw810/prerequisites/i686-w64-mingw32-static/include' LDFLAGS='-pipe 
> -fno-ident -L/c/mingw810/i686-810-posix-dwarf-rt_v6-rev0/mingw32/opt/lib 
> -L/c/mingw810/prerequisites/i686-zlib-static/lib 
> -L/c/mingw810/prerequisites/i686-w64-mingw32-static/lib 
> -Wl,--large-address-aware'
> Thread model: posix
> gcc version 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project)

> gcc (MinGW.org GCC Build-20200227-1) 9.2.0
> Copyright (C) 2019 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Reply via email to