We used to check all unknown input files, even when passing them to a
compiler. But that caused problems. However, not erroring out on
non-existent would-be-linker inputs confuses configure machinery that
probes the compiler to see if it accepts various inputs. This
restores the access check for things that are thought to be linker
input files, when we're not linking. (If we are linking, we presume
the linker will error out on its own accord.)
We get a warning about not linking, and then an error about the file not
being found. This seemed marginally better than a single error message
conveying both pieces of information.
devvm1702:30>./xg++ -B./ NOTAFILE -x c /dev/null -c
xg++: warning: NOTAFILE: linker input file unused because linking not done
xg++: error: NOTAFILE: linker input file not found: No such file or
directory
PR driver/98943
gcc/
* gcc.c (driver::maybe_run_linker): Check for input file
accessibility if not linking.
gcc/testsuite/
* c-c++-common/pr98943.c: New.
booted & tested on x86_64-linux, ok?
nathan
--
Nathan Sidwell
diff --git c/gcc/gcc.c w/gcc/gcc.c
index aa5774af7e7..96381a77dee 100644
--- c/gcc/gcc.c
+++ w/gcc/gcc.c
@@ -9020,8 +9020,15 @@ driver::maybe_run_linker (const char *argv0) const
for (i = 0; (int) i < n_infiles; i++)
if (explicit_link_files[i]
&& !(infiles[i].language && infiles[i].language[0] == '*'))
- warning (0, "%s: linker input file unused because linking not done",
- outfiles[i]);
+ {
+ warning (0, "%s: linker input file unused because linking not done",
+ outfiles[i]);
+ if (access (outfiles[i], F_OK) < 0)
+ /* This is can be an indication the user specifed an errorneous
+ separated option value, (or used the wrong prefix for an
+ option). */
+ error ("%s: linker input file not found: %m", outfiles[i]);
+ }
}
/* The end of "main". */
diff --git c/gcc/testsuite/c-c++-common/pr98943.c w/gcc/testsuite/c-c++-common/pr98943.c
new file mode 100644
index 00000000000..53d8838f242
--- /dev/null
+++ w/gcc/testsuite/c-c++-common/pr98943.c
@@ -0,0 +1,10 @@
+// { dg-do compile }
+// PR 98943, compiler feature tests can get confused by not linking
+// { dg-options "NOTAFILE" }
+
+int main ()
+{
+ return 0;
+}
+
+// { dg-regexp {[^\n:]*: warning: NOTAFILE: linker input file unused because linking not done\n[^\n:]*: error: NOTAFILE: linker input file not found: [^\n]*\n} }