mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-13 04:42:44 +08:00
ld: Rename a file on Windows fails if target already exists
To rename a file on Windows, the target name cannot exist. Removing file prior to renaming ensures this is handled. To remove a file on Windows, the file cannot be open. Closing the bfd handle ensures this is handled. Moved call to free on isympp / osympp to after bfd is closed to align with comment earlier in the cmdline_add_object_only_section function. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> (cherry picked from commit 233cd5946413108bf4902b22a9cb23ad0a468f5e)
This commit is contained in:
18
ld/ldlang.c
18
ld/ldlang.c
@@ -43,6 +43,7 @@
|
|||||||
#include "hashtab.h"
|
#include "hashtab.h"
|
||||||
#include "elf-bfd.h"
|
#include "elf-bfd.h"
|
||||||
#include "bfdver.h"
|
#include "bfdver.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#if BFD_SUPPORTS_PLUGINS
|
#if BFD_SUPPORTS_PLUGINS
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
@@ -10840,10 +10841,19 @@ cmdline_add_object_only_section (bfd_byte *contents, size_t size)
|
|||||||
fatal (_("%P: failed to finish output with object-only section\n"));
|
fatal (_("%P: failed to finish output with object-only section\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ibfd needs to be closed *after* obfd, otherwise ld may crash with a
|
||||||
|
segmentation fault. */
|
||||||
|
if (!bfd_close (ibfd))
|
||||||
|
einfo (_("%P%F: failed to close input\n"));
|
||||||
|
|
||||||
/* Must be freed after bfd_close (). */
|
/* Must be freed after bfd_close (). */
|
||||||
free (isympp);
|
free (isympp);
|
||||||
free (osympp);
|
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))
|
if (rename (ofilename, output_filename))
|
||||||
{
|
{
|
||||||
unlink (ofilename);
|
unlink (ofilename);
|
||||||
@@ -10854,10 +10864,14 @@ cmdline_add_object_only_section (bfd_byte *contents, size_t size)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
loser:
|
loser:
|
||||||
free (isympp);
|
|
||||||
free (osympp);
|
|
||||||
if (obfd)
|
if (obfd)
|
||||||
bfd_close (obfd);
|
bfd_close (obfd);
|
||||||
|
/* ibfd needs to be closed *after* obfd, otherwise ld may crash with a
|
||||||
|
segmentation fault. */
|
||||||
|
if (ibfd)
|
||||||
|
bfd_close (ibfd);
|
||||||
|
free (isympp);
|
||||||
|
free (osympp);
|
||||||
if (ofilename)
|
if (ofilename)
|
||||||
{
|
{
|
||||||
unlink (ofilename);
|
unlink (ofilename);
|
||||||
|
|||||||
Reference in New Issue
Block a user