Commit 9178a345 by Olivier Hainque Committed by Olivier Hainque

collect2.c (may_unlink_output_file): New global.

        * collect2.c (may_unlink_output_file): New global.
        (maybe_unlink): Honor it.
        * collect2.h: Add extern for it.
        * tlink.c (do_tlink): Set it to true if the link succeeded.

From-SVN: r187148
parent b50ff8bb
2012-05-04 Olivier Hainque <hainque@adacore.com> 2012-05-04 Olivier Hainque <hainque@adacore.com>
* collect2.c (may_unlink_output_file): New global.
(maybe_unlink): Honor it.
* collect2.h: Add extern for it.
* tlink.c (do_tlink): Set it to true if the link succeeded.
2012-05-04 Olivier Hainque <hainque@adacore.com>
* gcc.c (eval_spec_function): Finalize/restore the current string * gcc.c (eval_spec_function): Finalize/restore the current string
obstack state as part of the context push/pop operations. obstack state as part of the context push/pop operations.
......
...@@ -237,6 +237,12 @@ static const char *target_system_root = TARGET_SYSTEM_ROOT; ...@@ -237,6 +237,12 @@ static const char *target_system_root = TARGET_SYSTEM_ROOT;
static const char *target_system_root = ""; static const char *target_system_root = "";
#endif #endif
/* Whether we may unlink the output file, which should be set as soon as we
know we have successfully produced it. This is typically useful to prevent
blindly attempting to unlink a read-only output that the target linker
would leave untouched. */
bool may_unlink_output_file = false;
/* Structure to hold all the directories in which to search for files to /* Structure to hold all the directories in which to search for files to
execute. */ execute. */
...@@ -2095,15 +2101,22 @@ fork_execute (const char *prog, char **argv) ...@@ -2095,15 +2101,22 @@ fork_execute (const char *prog, char **argv)
do_wait (prog, pex); do_wait (prog, pex);
} }
/* Unlink a file unless we are debugging. */ /* Unlink FILE unless we are debugging or this is the output_file
and we may not unlink it. */
static void static void
maybe_unlink (const char *file) maybe_unlink (const char *file)
{ {
if (!debug) if (debug)
unlink_if_ordinary (file); {
else notice ("[Leaving %s]\n", file);
notice ("[Leaving %s]\n", file); return;
}
if (file == output_file && !may_unlink_output_file)
return;
unlink_if_ordinary (file);
} }
/* Call maybe_unlink on the NULL-terminated list, FILE_LIST. */ /* Call maybe_unlink on the NULL-terminated list, FILE_LIST. */
......
...@@ -40,6 +40,7 @@ extern const char *c_file_name; ...@@ -40,6 +40,7 @@ extern const char *c_file_name;
extern struct obstack temporary_obstack; extern struct obstack temporary_obstack;
extern char *temporary_firstobj; extern char *temporary_firstobj;
extern bool vflag, debug; extern bool vflag, debug;
extern bool may_unlink_output_file;
extern void notice_translated (const char *, ...) ATTRIBUTE_PRINTF_1; extern void notice_translated (const char *, ...) ATTRIBUTE_PRINTF_1;
extern void notice (const char *, ...) ATTRIBUTE_PRINTF_1; extern void notice (const char *, ...) ATTRIBUTE_PRINTF_1;
......
...@@ -859,4 +859,10 @@ do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED) ...@@ -859,4 +859,10 @@ do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
error ("ld returned %d exit status", exit); error ("ld returned %d exit status", exit);
collect_exit (exit); collect_exit (exit);
} }
else
{
/* We have just successfully produced an output file, so assume that we
may unlink it if need be for now on. */
may_unlink_output_file = true;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment