aboutsummaryrefslogtreecommitdiff
path: root/binutils/dlltool.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2015-03-05 15:13:08 +0000
committerNick Clifton <nickc@redhat.com>2015-03-05 15:13:08 +0000
commit81fb971a3d8626d7e051ff5df807442c8d233329 (patch)
tree9bb545e12b6842bd274239e9171be7de501a652f /binutils/dlltool.c
parentca3fe95e469b9daec153caa2c90665f5daaec2b5 (diff)
downloadgdb-81fb971a3d8626d7e051ff5df807442c8d233329.zip
gdb-81fb971a3d8626d7e051ff5df807442c8d233329.tar.gz
gdb-81fb971a3d8626d7e051ff5df807442c8d233329.tar.bz2
Fixes PR 17994 - which reported that dlltool was not deleting temporary files if it encounters a fatal error.
PR binutils/17994 * dlltool.c (temp_file_to_remove): New local array. (unlink_temp_files): New functions - unlinks any file in the temp_file_to_remove array, unless dotdeltemps is set. (gen_exp_file): Add temp files to array. (make_head): Likewise. (make_delay_head): Likewise. (make_tail): Likewise. (gen_lib_file): Call unlink_temp_files.
Diffstat (limited to 'binutils/dlltool.c')
-rw-r--r--binutils/dlltool.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index b5b3aff..be08227 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -1994,6 +1994,31 @@ assemble_file (const char * source, const char * dest)
run (as_name, cmd);
}
+static const char * temp_file_to_remove[5];
+#define TEMP_EXPORT_FILE 0
+#define TEMP_HEAD_FILE 1
+#define TEMP_TAIL_FILE 2
+#define TEMP_HEAD_O_FILE 3
+#define TEMP_TAIL_O_FILE 4
+
+static void
+unlink_temp_files (void)
+{
+ unsigned i;
+
+ if (dontdeltemps > 0)
+ return;
+
+ for (i = 0; i < ARRAY_SIZE (temp_file_to_remove); i++)
+ {
+ if (temp_file_to_remove[i])
+ {
+ unlink (temp_file_to_remove[i]);
+ temp_file_to_remove[i] = NULL;
+ }
+ }
+}
+
static void
gen_exp_file (void)
{
@@ -2010,6 +2035,8 @@ gen_exp_file (void)
/* xgettext:c-format */
fatal (_("Unable to open temporary assembler file: %s"), TMP_ASM);
+ temp_file_to_remove[TEMP_EXPORT_FILE] = TMP_ASM;
+
/* xgettext:c-format */
inform (_("Opened temporary file: %s"), TMP_ASM);
@@ -2146,7 +2173,6 @@ gen_exp_file (void)
}
}
-
/* Add to the output file a way of getting to the exported names
without using the import library. */
if (add_indirect)
@@ -2234,7 +2260,10 @@ gen_exp_file (void)
assemble_file (TMP_ASM, exp_name);
if (dontdeltemps == 0)
- unlink (TMP_ASM);
+ {
+ temp_file_to_remove[TEMP_EXPORT_FILE] = NULL;
+ unlink (TMP_ASM);
+ }
inform (_("Generated exports file"));
}
@@ -2939,6 +2968,8 @@ make_head (void)
return NULL;
}
+ temp_file_to_remove[TEMP_HEAD_FILE] = TMP_HEAD_S;
+
fprintf (f, "%s IMAGE_IMPORT_DESCRIPTOR\n", ASM_C);
fprintf (f, "\t.section\t.idata$2\n");
@@ -3000,6 +3031,7 @@ make_head (void)
fatal (_("failed to open temporary head file: %s: %s"),
TMP_HEAD_O, bfd_get_errmsg ());
+ temp_file_to_remove[TEMP_HEAD_O_FILE] = TMP_HEAD_O;
return abfd;
}
@@ -3015,6 +3047,8 @@ make_delay_head (void)
return NULL;
}
+ temp_file_to_remove[TEMP_HEAD_FILE] = TMP_HEAD_S;
+
/* Output the __tailMerge__xxx function */
fprintf (f, "%s Import trampoline\n", ASM_C);
fprintf (f, "\t.section\t.text\n");
@@ -3083,6 +3117,7 @@ make_delay_head (void)
fatal (_("failed to open temporary head file: %s: %s"),
TMP_HEAD_O, bfd_get_errmsg ());
+ temp_file_to_remove[TEMP_HEAD_O_FILE] = TMP_HEAD_O;
return abfd;
}
@@ -3098,6 +3133,8 @@ make_tail (void)
return NULL;
}
+ temp_file_to_remove[TEMP_TAIL_FILE] = TMP_TAIL_S;
+
if (!no_idata4)
{
fprintf (f, "\t.section\t.idata$4\n");
@@ -3154,6 +3191,7 @@ make_tail (void)
fatal (_("failed to open temporary tail file: %s: %s"),
TMP_TAIL_O, bfd_get_errmsg ());
+ temp_file_to_remove[TEMP_TAIL_O_FILE] = TMP_TAIL_O;
return abfd;
}
@@ -3179,6 +3217,8 @@ gen_lib_file (int delay)
/* xgettext:c-format */
inform (_("Creating library file: %s"), imp_name);
+ xatexit (unlink_temp_files);
+
bfd_set_format (outarch, bfd_archive);
outarch->has_armap = 1;
outarch->is_thin_archive = 0;
@@ -3248,13 +3288,7 @@ gen_lib_file (int delay)
}
/* Delete all the temp files. */
- if (dontdeltemps == 0)
- {
- unlink (TMP_HEAD_O);
- unlink (TMP_HEAD_S);
- unlink (TMP_TAIL_O);
- unlink (TMP_TAIL_S);
- }
+ unlink_temp_files ();
if (dontdeltemps < 2)
{