RFC: PR 31761: Stop the linker from overwriting source files

Nick Clifton nickc@redhat.com
Tue Jun 18 17:04:25 GMT 2024


Hi Guys,

  Attached is a proposed patch to address one of the issues raised in
  PR 31761 - namely that the linker will happily overwrite a source file
  if it was invoked by mistake.  eg:

    ld -o foo.c foo.o

  The patch does not change the linker's behaviour of deleting the
  output file before writing to it, even if errors occur during the
  link.  I still consider this to be the correct behaviour.

  With the patch applied the linker will now behave like this:

    $ touch foo.c foo.o
    $ ld -o foo.c foo.o
    ld: fatal: output file 'foo.c' exists and is a known input file type
    You can suppress this error by linking with --noinhibit-exec
    $ echo $?
    1

  Any comments or suggestions ?

Cheers
  Nick

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr31761.patch
Type: text/x-patch
Size: 4272 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20240618/ce085ef3/attachment-0001.bin>


More information about the Binutils mailing list