I noticed today that:
gcc -c -o hw.o hw.c
removes hw.o if failure occurs during the compilation, but:
gcc -c -ohw.o hw.c
does not.
The reason turns out to be that, in the latter case, we record the name
"-ohw.o" as a temporary file, rather than "hw.o". Our confusion comes
from the handling of "%W" specs:
/* If any args were output, mark the last one for
deletion
on failure. */
if (argbuf_index != cur_index)
record_temp_file (argbuf[argbuf_index - 1], 0, 1);
in the handling of the spec "%W{o*}", which is supposed to mean that we
generate all of the "-o" options, and then remember that the last one is
a temporary file we should delete. However, the generation of the
output (which is what argbuf contains) is faithful to the input, so if
the user writes "-ofoo.o" instead of "-o foo.o", then the output is
again "-ofoo.o", leading to the bug. I guess this matters if your
assembler, for example, only accepts the "-ofoo.o" form. Are there such
tools? (It looks like the opposite is sometimes true; we have
SWITCHES_NEED_SPACES, which indicates that some options must be split,
no matter how the user writes them, and that is set to indicate that
"-ofoo.o" must be split on IRIX and OSF.)
We can't just check in the code above for the last argument starting
with "-o", since then "-o -ofoo.o" wouldn't work right. And, besides,
although "%W" seems to be used only with "%W{o*}" it could in theory be
used in other ways as well. And we can't blindly try deleting both
"-ofoo.o" and plain "foo.o" because then if the user said "-ofoo.o", and
that was missing, we'd delete "foo.o" which we should not. (There is
already some code involving have_o_argbuf_index which looks like it may
mishandle things like "gcc -c -x c -- -o", but that's another matter.)
This idea of going back and looking at argbuf is, therefore, broken by
design. I don't see a way to really make %W make sense, in this context.
Ideas?
--
Mark Mitchell
CodeSourcery
[EMAIL PROTECTED]
(650) 331-3385 x713