bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/31761] Linker deletes output file even if linking fails


From: jwakely.gcc at gmail dot com
Subject: [Bug ld/31761] Linker deletes output file even if linking fails
Date: Tue, 18 Jun 2024 14:24:14 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=31761

--- Comment #10 from Jonathan Wakely <jwakely.gcc at gmail dot com> ---
(In reply to Alan Modra from comment #6)
> I agree with Nick's comment.  Consider too that if the link had succeeded,
> your source file would have been overwritten (assuming of course that write
> access was allowed to the file).

For the record, gcc won't even allow you to set the output to the name of an
input file:

$ gcc foo.c -o foo.c
gcc: fatal error: input file ‘foo.c’ is the same as output file
compilation terminated.

That simple mistake also used to trash the source file, but it was fixed in gcc
more than a decade ago, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36312

So now you need to be a bit smarter/dumber to trash the input file. It's no
longer enough to typo "foo.c" instead of "foo.o", you need to forget the name
of the output file entirely, or use an unset variable as in: gcc -o $objfile
foo.c -lm

That's harder to fix in GCC, but would be easy to fix in binutils by not
overwriting the output on failure.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]