Small cleanups before making collect2 use collect-utils.

* collect-utils.c (save_temps): New variable.
	(do_wait): Use it instead of debug.  Use fatal_error.
	* collect-utils.h (save_temps): Declare.
	* collect2.c (verbose): Rename from vflag.  All uses changed.
	(tool_cleanup): New function, copied from collect_atexit.
	(collect_atexit, handler): Just call it.
	* collect2.h (verbose): Declaration renamed from vflag.
	* lto-wrapper.c (maybe_unlink, run_gcc): Use save_temps instead of
	debug.

From-SVN: r212019
This commit is contained in:
Bernd Schmidt 2014-06-26 09:16:19 +00:00 committed by Bernd Schmidt
parent a185856a06
commit 608508a677
7 changed files with 47 additions and 56 deletions

View File

@ -1,5 +1,15 @@
2014-06-26 Bernd Schmidt <bernds@codesourcery.com>
* collect-utils.c (save_temps): New variable.
(do_wait): Use it instead of debug. Use fatal_error.
* collect-utils.h (save_temps): Declare.
* collect2.c (verbose): Rename from vflag. All uses changed.
(tool_cleanup): New function, copied from collect_atexit.
(collect_atexit, handler): Just call it.
* collect2.h (verbose): Declaration renamed from vflag.
* lto-wrapper.c (maybe_unlink, run_gcc): Use save_temps instead of
debug.
* Makefile.in (ALL_HOST_BACKEND_OBJS): Add collect-utils.o.
(lto-wrapper$(exeext)): Link with collect-utils.o.
* collect-utils.c: New file.

View File

@ -33,6 +33,7 @@ static char *response_file;
bool debug;
bool verbose;
bool save_temps;
/* Delete tempfiles. */
@ -159,12 +160,9 @@ do_wait (const char *prog, struct pex_obj *pex)
{
int ret = collect_wait (prog, pex);
if (ret != 0)
{
error ("%s returned %d exit status", prog, ret);
exit (ret);
}
fatal_error ("%s returned %d exit status", prog, ret);
if (response_file && !debug)
if (response_file && !save_temps)
{
unlink (response_file);
response_file = NULL;

View File

@ -30,6 +30,7 @@ extern void utils_cleanup (void);
extern bool debug;
extern bool verbose;
extern bool save_temps;
/* Provided by the tool itself. */

View File

@ -175,7 +175,7 @@ struct head
int number;
};
bool vflag; /* true if -v or --version */
bool verbose; /* true if -v or --version */
static int rflag; /* true if -r */
static int strip_flag; /* true if -s */
#ifdef COLLECT_EXPORT_LIST
@ -383,7 +383,7 @@ static void scan_prog_file (const char *, scanpass, scanfilter);
/* Delete tempfiles and exit function. */
static void
collect_atexit (void)
tool_cleanup (bool from_signal)
{
if (c_file != 0 && c_file[0])
maybe_unlink (c_file);
@ -401,20 +401,33 @@ collect_atexit (void)
if (ldout != 0 && ldout[0])
{
dump_ld_file (ldout, stdout);
if (!from_signal)
dump_ld_file (ldout, stdout);
maybe_unlink (ldout);
}
if (lderrout != 0 && lderrout[0])
{
dump_ld_file (lderrout, stderr);
if (!from_signal)
dump_ld_file (lderrout, stderr);
maybe_unlink (lderrout);
}
if (response_file)
maybe_unlink (response_file);
}
static void
collect_atexit (void)
{
tool_cleanup (false);
}
static void
handler (int signo)
{
tool_cleanup (true);
signal (signo, SIG_DFL);
raise (signo);
}
/* Notify user of a non-error. */
void
@ -437,37 +450,6 @@ notice_translated (const char *cmsgid, ...)
vfprintf (stderr, cmsgid, ap);
va_end (ap);
}
static void
handler (int signo)
{
if (c_file != 0 && c_file[0])
maybe_unlink (c_file);
if (o_file != 0 && o_file[0])
maybe_unlink (o_file);
if (ldout != 0 && ldout[0])
maybe_unlink (ldout);
if (lderrout != 0 && lderrout[0])
maybe_unlink (lderrout);
#ifdef COLLECT_EXPORT_LIST
if (export_file != 0 && export_file[0])
maybe_unlink (export_file);
#endif
if (lto_o_files)
maybe_unlink_list (lto_o_files);
if (response_file)
maybe_unlink (response_file);
signal (signo, SIG_DFL);
raise (signo);
}
int
file_exists (const char *name)
@ -1056,7 +1038,7 @@ main (int argc, char **argv)
aixlazy_flag = 1;
#endif
}
vflag = debug;
verbose = debug;
find_file_set_debug (debug);
if (use_plugin)
lto_mode = LTO_MODE_NONE;
@ -1451,7 +1433,7 @@ main (int argc, char **argv)
case 'v':
if (arg[2] == '\0')
vflag = true;
verbose = true;
break;
case '-':
@ -1483,7 +1465,7 @@ main (int argc, char **argv)
else if (strncmp (arg, "--sysroot=", 10) == 0)
target_system_root = arg + 10;
else if (strcmp (arg, "--version") == 0)
vflag = true;
verbose = true;
else if (strcmp (arg, "--help") == 0)
helpflag = true;
break;
@ -1578,7 +1560,7 @@ main (int argc, char **argv)
*c_ptr++ = c_file;
*c_ptr = *ld1 = *object = (char *) 0;
if (vflag)
if (verbose)
notice ("collect2 version %s\n", version_string);
if (helpflag)
@ -1947,7 +1929,7 @@ collect_execute (const char *prog, char **argv, const char *outname,
argv = response_argv;
}
if (vflag || debug)
if (verbose || debug)
{
char **p_argv;
const char *str;
@ -2509,7 +2491,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
nm_argv[argc++] = (char *) 0;
/* Trace if needed. */
if (vflag)
if (verbose)
{
const char **p_argv;
const char *str;
@ -2706,7 +2688,7 @@ scan_libraries (const char *prog_name)
ldd_argv[argc++] = (char *) 0;
/* Trace if needed. */
if (vflag)
if (verbose)
{
const char **p_argv;
const char *str;

View File

@ -36,7 +36,7 @@ extern const char *lderrout;
extern const char *c_file_name;
extern struct obstack temporary_obstack;
extern char *temporary_firstobj;
extern bool vflag, debug;
extern bool verbose, debug;
extern bool may_unlink_output_file;
extern void notice_translated (const char *, ...) ATTRIBUTE_PRINTF_1;

View File

@ -99,7 +99,7 @@ lto_wrapper_cleanup (void)
void
maybe_unlink (const char *file)
{
if (! debug)
if (!save_temps)
{
if (unlink_if_ordinary (file)
&& errno != ENOENT)
@ -540,7 +540,7 @@ run_gcc (unsigned argc, char *argv[])
continue;
case OPT_save_temps:
debug = 1;
save_temps = 1;
break;
case OPT_v:
@ -647,7 +647,7 @@ run_gcc (unsigned argc, char *argv[])
obstack_ptr_grow (&argv_obstack, dumpbase);
}
if (linker_output && debug)
if (linker_output && save_temps)
{
ltrans_output_file = (char *) xmalloc (strlen (linker_output)
+ sizeof (".ltrans.out") + 1);
@ -785,7 +785,7 @@ cont:
/* If we are not preserving the ltrans input files then
truncate them as soon as we have processed it. This
reduces temporary disk-space usage. */
if (! debug)
if (! save_temps)
fprintf (mstream, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
"&& mv %s.tem %s\n",
input_name, input_name, input_name, input_name);

View File

@ -275,7 +275,7 @@ tlink_init (void)
else
{
tlink_verbose = 1;
if (vflag)
if (verbose)
tlink_verbose = 2;
if (debug)
tlink_verbose = 3;