Closed billziss-gh closed 1 year ago
thanks for the report!
will try to deal with this...
it looks like the issue happens because the GCC driver doesnt check gcc.exe
for hardlink and because of that it doesnt follow the hardlink...
the mklink
without /h
doesnt want to create anything with error message like insufficient privileges
.
with /h
option I can create the hard link and confirm the issue.
Thank you for looking into this:
The mklink
command works to create symbolic links in two cases:
with /h option I can create the hard link and confirm the issue.
Actually if gcc.exe
is accessed via a hard link the behavior described in this issue should be considered correct (IMO), because gcc cannot resolve the hard link and find the "real" path it points to (there is no readlink
for hard links). It is only when gcc.exe
is accessed via a symbolic link that the behavior described in this issue should be considered incorrect (IMO).
When I first reported this issue I did a bit of investigation and found out that gcc appears to handle prefixes in process_command
:
-no-canonical-prefixes
option is set, then it resolves prefixes using make_relative_prefix_ignore_links
(without considering symbolic links).make_relative_prefix
.I do not know if something in the mingw gcc build process forces the -no-canonical-prefixes
option.
The code for make_relative_prefix
is here. It uses lrealpath
, which on Windows uses GetFullPathName
, which should work.
I have not had the chance to run this under a debugger yet (as I would have to rebuild gcc with debug info, etc.), but I suspect that a debugging session around these functions would be very illuminating.
I setup a build of GCC with debug symbols and ran it under GDB. Indeed make_relative_prefix
, lrealpath
and GetFullPathName
were called as expected.
Turns out that I had a thinko when I said: "on Windows uses GetFullPathName
, which should work". GetFullPathName
did not resolve the symbolic link during my debugging session and indeed the GetFullPathName
documentation makes no mention of symbolic link resolution.
The correct API to use is GetFinalPathNameByHandle
.
In any case this is not a problem of the mingw-builds project but rather a problem of the upstream gcc project. I will have to report it to them and possibly provide a patch.
Thank you @billziss-gh , it would be great!
Reported to gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108350
thank you!
Actually if gcc.exe is accessed via a hard link the behavior described in this issue should be considered correct (IMO)
just to be sure: as I reported on bugzilla, I have fixed the behavior for symlinks, but it still doesn't work correctly for hardlinks.
or im wrong?
@billziss-gh
Sorry for the late response. For some reason email notifications from the bugzilla do not seem to work for me, even though I think I have them enabled in my mail preferences.
as example:
Thank you. The behavior is same as in Linux:
billziss@xps ⟩ /home/billziss/t $ touch a.c
billziss@xps ⟩ /home/billziss/t $ ln -s /usr/bin/x86_64-linux-gnu-gcc-9 sgcc
billziss@xps ⟩ /home/billziss/t $ ln /usr/bin/x86_64-linux-gnu-gcc-9 hgcc
billziss@xps ⟩ /home/billziss/t $ ./sgcc a.c
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
billziss@xps ⟩ /home/billziss/t $ ./hgcc a.c
hgcc: fatal error: cannot execute ‘cc1’: execvp: No such file or directory
compilation terminated.
The soft linked sgcc
is able to find its prefix and the hard linked hgcc
is not:
billziss@xps ⟩ /home/billziss/t $ ./sgcc -print-search-dirs
install: /usr/lib/gcc/x86_64-linux-gnu/9/
programs: =/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/9/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/9/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/
billziss@xps ⟩ /home/billziss/t $ ./hgcc -print-search-dirs
install: /home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/
programs: =/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/:/home/billziss/t/../lib/gcc/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/9/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/
libraries: =/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/:/home/billziss/t/../lib/gcc/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/../lib/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/9/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/9/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/:/home/billziss/t/../lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/
the hard linked hgcc is not
so, should I try to deal which this? is the direction specified at the link correct?
so, should I try to deal which this?
In my opinion, no, you should not need to do anything about the hard link.
then OK, will publish the patch!
then OK, will publish the patch!
Please see some of my comments in bugzilla about the patch.
yeah, I see. I fix it.
@billziss-gh
could you look at the updated patch please?: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108350#c29
I am closing this as it will be addressed in GCC 13. Thanks again for your patch.
Problem
If I invoke gcc via a symlink, then it is unable to work. This appears to happen because it computes the wrong prefix.
Steps to reproduce
Create a symlink to the installed
gcc
:Create an empty file
a.c
:Attempt to build
a.c
via the symlink:Print the search directories via the symlink. The reported paths are relative to the symlink and incorrect:
Attempt to build
a.c
directly via thegcc
found in thePATH
(this fails becausea.c
is an empty file, but a compilation is attempted):Print the search directories directly via the
gcc
found in thePATH
. The reported paths are relative to the real location ofgcc
and correct:Expected behavior
I expected
gcc
to work regardless of whether it was invoked via a symlink or not, because I did not supply the-no-canonical-prefixes
option.For example, on Linux:
Environment
gcc
version: