[PATCH v3] ld: Rename a file on Windows fails if target already exists
Andreas Schwab
schwab@suse.de
Tue Jul 22 13:18:31 GMT 2025
On Jul 22 2025, Torbjörn SVENSSON wrote:
> @@ -10840,10 +10841,21 @@ cmdline_add_object_only_section (bfd_byte *contents, size_t size)
> fatal (_("%P: failed to finish output with object-only section\n"));
> }
>
> + if (!bfd_close (ibfd))
> + {
> + einfo (_("%P%F: failed to close input\n"));
> + }
> +
> /* Must be freed after bfd_close (). */
Is this comment ...
> free (isympp);
> free (osympp);
>
> + /* Must unlink to ensure rename works on Windows. */
> + if (unlink (output_filename) && errno != ENOENT)
> + {
> + einfo (_("%P%F: failed to unlink %s\n"), output_filename);
> + }
> +
> if (rename (ofilename, output_filename))
> {
> unlink (ofilename);
> @@ -10858,6 +10870,8 @@ loser:
> free (osympp);
> if (obfd)
> bfd_close (obfd);
> + if (ibfd)
> + bfd_close (ibfd);
... also relevant for this?
Perhaps the function should use bfd_alloc instead of xmalloc for isympp
and osympp.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
More information about the Binutils
mailing list