This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, driver] -Wl, passing empty strings to ld
- From: Jim Wilson <wilson at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 14 Apr 2010 20:34:44 -0700
- Subject: [PATCH, driver] -Wl, passing empty strings to ld
We ran into this problem at Cisco.
% touch tmp.o
% ./xgcc -B./ -Wl, --whole-archive tmp.o
/usr/bin/ld: : No such file: No such file or directory
collect2: ld returned 1 exit status
% ./xgcc -B./ -Wl,--whole-archive, tmp.o
/usr/bin/ld: : No such file: No such file or directory
collect2: ld returned 1 exit status
% ./xgcc -B./ -Wl,,--whole-archive tmp.o
/usr/bin/ld: : No such file: No such file or directory
collect2: ld returned 1 exit status
The problem here is that the gcc driver is parsing the invalid -Wl,
options and ending up with empty strings "" which it then passes on to
ld as input file names. ld fails to open a file named "", and then
prints an error that contains the string "". All very useless, and very
confusing if you have a 1000+ character long link command and can't
figure out what is wrong.
The gcc driver should be giving an error for the invalid -Wl, option.
The -Wa, and -Wp, options have the same problem, though I don't see any
way to generate a failure there, since the empty strings get passed
through do_spec which silently drops them. But I figure these should
still get the same fix anyways for consistency.
This was tested with a make check-gcc, and tested by hand to verify that
it has the right effect.
khazaddum$ sh -x tmp.script
+ touch tmp.o
+ ./xgcc -B./ -Wl, --whole-archive tmp.o
xgcc: argument to '-Wl,' is missing
+ ./xgcc -B./ -Wl,--whole-archive, tmp.o
xgcc: argument to '-Wl,' is missing
+ ./xgcc -B./ -Wl,,--whole-archive tmp.o
xgcc: argument to '-Wl,' is missing
+ touch tmp.s
+ ./xgcc -B./ -Wa, --verbose tmp.s
xgcc: argument to '-Wa,' is missing
+ ./xgcc -B./ -Wa,--verbose, tmp.s
xgcc: argument to '-Wa,' is missing
+ ./xgcc -B./ -Wa,,--verbose tmp.s
xgcc: argument to '-Wa,' is missing
+ touch tmp.c
+ ./xgcc -B./ -Wp, --verbose tmp.c
xgcc: argument to '-Wp,' is missing
+ ./xgcc -B./ -Wp,--verbose, tmp.c
xgcc: argument to '-Wp,' is missing
+ ./xgcc -B./ -Wp,,--verbose tmp.c
xgcc: argument to '-Wp,' is missing
khazaddum$
Jim
2010-04-14 James E. Wilson <wilson@codesourcery.com>
* gcc.c (process_command): In option parsing for "-Wl,", "-Wa,", and
"-Wp," , call fatal if we have an empty string as argument.
Index: gcc.c
===================================================================
--- gcc.c (revision 157804)
+++ gcc.c (working copy)
@@ -3936,10 +3936,18 @@ process_command (int argc, const char **
for (j = 4; argv[i][j]; j++)
if (argv[i][j] == ',')
{
+ /* Reject empty strings. */
+ if (j == prev)
+ fatal ("argument to '-Wa,' is missing");
+
add_assembler_option (argv[i] + prev, j - prev);
prev = j + 1;
}
+ /* Reject empty strings. */
+ if (j == prev)
+ fatal ("argument to '-Wa,' is missing");
+
/* Record the part after the last comma. */
add_assembler_option (argv[i] + prev, j - prev);
}
@@ -3953,10 +3961,18 @@ process_command (int argc, const char **
for (j = 4; argv[i][j]; j++)
if (argv[i][j] == ',')
{
+ /* Reject empty strings. */
+ if (j == prev)
+ fatal ("argument to '-Wp,' is missing");
+
add_preprocessor_option (argv[i] + prev, j - prev);
prev = j + 1;
}
+ /* Reject empty strings. */
+ if (j == prev)
+ fatal ("argument to '-Wp,' is missing");
+
/* Record the part after the last comma. */
add_preprocessor_option (argv[i] + prev, j - prev);
}
@@ -4451,11 +4467,20 @@ process_command (int argc, const char **
for (j = 4; argv[i][j]; j++)
if (argv[i][j] == ',')
{
+ /* Reject empty strings. */
+ if (j == prev)
+ fatal ("argument to '-Wl,' is missing");
+
infiles[n_infiles].language = "*";
infiles[n_infiles++].name
= save_string (argv[i] + prev, j - prev);
prev = j + 1;
}
+
+ /* Reject empty strings. */
+ if (j == prev)
+ fatal ("argument to '-Wl,' is missing");
+
/* Record the part after the last comma. */
infiles[n_infiles].language = "*";
infiles[n_infiles++].name = argv[i] + prev;