Bug 40548

Summary: If a dir on PATH contains a directory named "gcc", badness ensues
Product: gcc Reporter: Paul Smith <psmith>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: dfeldstern, dickie, gcc-bugs, mvanier, psmith
Priority: P3    
Version: 4.3.2   
Target Milestone: ---   
Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu Known to work:
Known to fail: Last reconfirmed:

Description Paul Smith 2009-06-25 00:10:37 UTC
I have a directory on my PATH that contains a subdirectory named "gcc".  When I run "gcc" (not fully-qualified) I get all sorts of very bizarre behavior.  For example:

$ cat t.c
#include <limits.h>

$ mkdir gcc

$ PATH=.:$PATH gcc -E t.c >/dev/null
In file included from /tmp/t.c:1:
/usr/include/limits.h:125:26: error: no include path in which to search for limits.h

But, if I don't have a local directory "gcc" then all is fine:

$ rmdir gcc
$ PATH=.:$PATH gcc -E t.c >/dev/null
$

If I use a fully-qualified path for GCC (/usr/bin/gcc) then it also does not fail.

It looks to me like the test GCC performs when looking for itself through PATH just checks for executability (if I have a non-executable file in a directory on PATH this doesn't happen) but doesn't check for directory-ness.  This is wrong, because the shell's PATH search algorithm DOES check for directory-ness and skips directories that appear in directories on your PATH.
Comment 1 Andrew Pinski 2009-06-25 01:25:03 UTC

*** This bug has been marked as a duplicate of 38966 ***
Comment 2 Paul Smith 2009-06-25 05:00:02 UTC
Ah, thanks for the pointer.  I did search before I created a new bug but wasn't successful in narrowing down my search to something reasonable.  It would be nice if the "real" bug mentioned PATH in the summary; I was trying to use case-sensitive searches for PATH but searching comments turned up >150 bugs.