Commit 608508a6 by Bernd Schmidt Committed by Bernd Schmidt

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
parent a185856a
2014-06-26 Bernd Schmidt <bernds@codesourcery.com> 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. * Makefile.in (ALL_HOST_BACKEND_OBJS): Add collect-utils.o.
(lto-wrapper$(exeext)): Link with collect-utils.o. (lto-wrapper$(exeext)): Link with collect-utils.o.
* collect-utils.c: New file. * collect-utils.c: New file.
......
...@@ -33,6 +33,7 @@ static char *response_file; ...@@ -33,6 +33,7 @@ static char *response_file;
bool debug; bool debug;
bool verbose; bool verbose;
bool save_temps;
/* Delete tempfiles. */ /* Delete tempfiles. */
...@@ -159,12 +160,9 @@ do_wait (const char *prog, struct pex_obj *pex) ...@@ -159,12 +160,9 @@ do_wait (const char *prog, struct pex_obj *pex)
{ {
int ret = collect_wait (prog, pex); int ret = collect_wait (prog, pex);
if (ret != 0) if (ret != 0)
{ fatal_error ("%s returned %d exit status", prog, ret);
error ("%s returned %d exit status", prog, ret);
exit (ret);
}
if (response_file && !debug) if (response_file && !save_temps)
{ {
unlink (response_file); unlink (response_file);
response_file = NULL; response_file = NULL;
......
...@@ -30,6 +30,7 @@ extern void utils_cleanup (void); ...@@ -30,6 +30,7 @@ extern void utils_cleanup (void);
extern bool debug; extern bool debug;
extern bool verbose; extern bool verbose;
extern bool save_temps;
/* Provided by the tool itself. */ /* Provided by the tool itself. */
......
...@@ -175,7 +175,7 @@ struct head ...@@ -175,7 +175,7 @@ struct head
int number; int number;
}; };
bool vflag; /* true if -v or --version */ bool verbose; /* true if -v or --version */
static int rflag; /* true if -r */ static int rflag; /* true if -r */
static int strip_flag; /* true if -s */ static int strip_flag; /* true if -s */
#ifdef COLLECT_EXPORT_LIST #ifdef COLLECT_EXPORT_LIST
...@@ -383,7 +383,7 @@ static void scan_prog_file (const char *, scanpass, scanfilter); ...@@ -383,7 +383,7 @@ static void scan_prog_file (const char *, scanpass, scanfilter);
/* Delete tempfiles and exit function. */ /* Delete tempfiles and exit function. */
static void static void
collect_atexit (void) tool_cleanup (bool from_signal)
{ {
if (c_file != 0 && c_file[0]) if (c_file != 0 && c_file[0])
maybe_unlink (c_file); maybe_unlink (c_file);
...@@ -401,20 +401,33 @@ collect_atexit (void) ...@@ -401,20 +401,33 @@ collect_atexit (void)
if (ldout != 0 && ldout[0]) if (ldout != 0 && ldout[0])
{ {
if (!from_signal)
dump_ld_file (ldout, stdout); dump_ld_file (ldout, stdout);
maybe_unlink (ldout); maybe_unlink (ldout);
} }
if (lderrout != 0 && lderrout[0]) if (lderrout != 0 && lderrout[0])
{ {
if (!from_signal)
dump_ld_file (lderrout, stderr); dump_ld_file (lderrout, stderr);
maybe_unlink (lderrout); maybe_unlink (lderrout);
} }
}
if (response_file) static void
maybe_unlink (response_file); 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. */ /* Notify user of a non-error. */
void void
...@@ -438,37 +451,6 @@ notice_translated (const char *cmsgid, ...) ...@@ -438,37 +451,6 @@ notice_translated (const char *cmsgid, ...)
va_end (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 int
file_exists (const char *name) file_exists (const char *name)
{ {
...@@ -1056,7 +1038,7 @@ main (int argc, char **argv) ...@@ -1056,7 +1038,7 @@ main (int argc, char **argv)
aixlazy_flag = 1; aixlazy_flag = 1;
#endif #endif
} }
vflag = debug; verbose = debug;
find_file_set_debug (debug); find_file_set_debug (debug);
if (use_plugin) if (use_plugin)
lto_mode = LTO_MODE_NONE; lto_mode = LTO_MODE_NONE;
...@@ -1451,7 +1433,7 @@ main (int argc, char **argv) ...@@ -1451,7 +1433,7 @@ main (int argc, char **argv)
case 'v': case 'v':
if (arg[2] == '\0') if (arg[2] == '\0')
vflag = true; verbose = true;
break; break;
case '-': case '-':
...@@ -1483,7 +1465,7 @@ main (int argc, char **argv) ...@@ -1483,7 +1465,7 @@ main (int argc, char **argv)
else if (strncmp (arg, "--sysroot=", 10) == 0) else if (strncmp (arg, "--sysroot=", 10) == 0)
target_system_root = arg + 10; target_system_root = arg + 10;
else if (strcmp (arg, "--version") == 0) else if (strcmp (arg, "--version") == 0)
vflag = true; verbose = true;
else if (strcmp (arg, "--help") == 0) else if (strcmp (arg, "--help") == 0)
helpflag = true; helpflag = true;
break; break;
...@@ -1578,7 +1560,7 @@ main (int argc, char **argv) ...@@ -1578,7 +1560,7 @@ main (int argc, char **argv)
*c_ptr++ = c_file; *c_ptr++ = c_file;
*c_ptr = *ld1 = *object = (char *) 0; *c_ptr = *ld1 = *object = (char *) 0;
if (vflag) if (verbose)
notice ("collect2 version %s\n", version_string); notice ("collect2 version %s\n", version_string);
if (helpflag) if (helpflag)
...@@ -1947,7 +1929,7 @@ collect_execute (const char *prog, char **argv, const char *outname, ...@@ -1947,7 +1929,7 @@ collect_execute (const char *prog, char **argv, const char *outname,
argv = response_argv; argv = response_argv;
} }
if (vflag || debug) if (verbose || debug)
{ {
char **p_argv; char **p_argv;
const char *str; const char *str;
...@@ -2509,7 +2491,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, ...@@ -2509,7 +2491,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
nm_argv[argc++] = (char *) 0; nm_argv[argc++] = (char *) 0;
/* Trace if needed. */ /* Trace if needed. */
if (vflag) if (verbose)
{ {
const char **p_argv; const char **p_argv;
const char *str; const char *str;
...@@ -2706,7 +2688,7 @@ scan_libraries (const char *prog_name) ...@@ -2706,7 +2688,7 @@ scan_libraries (const char *prog_name)
ldd_argv[argc++] = (char *) 0; ldd_argv[argc++] = (char *) 0;
/* Trace if needed. */ /* Trace if needed. */
if (vflag) if (verbose)
{ {
const char **p_argv; const char **p_argv;
const char *str; const char *str;
......
...@@ -36,7 +36,7 @@ extern const char *lderrout; ...@@ -36,7 +36,7 @@ extern const char *lderrout;
extern const char *c_file_name; 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 verbose, debug;
extern bool may_unlink_output_file; extern bool may_unlink_output_file;
extern void notice_translated (const char *, ...) ATTRIBUTE_PRINTF_1; extern void notice_translated (const char *, ...) ATTRIBUTE_PRINTF_1;
......
...@@ -99,7 +99,7 @@ lto_wrapper_cleanup (void) ...@@ -99,7 +99,7 @@ lto_wrapper_cleanup (void)
void void
maybe_unlink (const char *file) maybe_unlink (const char *file)
{ {
if (! debug) if (!save_temps)
{ {
if (unlink_if_ordinary (file) if (unlink_if_ordinary (file)
&& errno != ENOENT) && errno != ENOENT)
...@@ -540,7 +540,7 @@ run_gcc (unsigned argc, char *argv[]) ...@@ -540,7 +540,7 @@ run_gcc (unsigned argc, char *argv[])
continue; continue;
case OPT_save_temps: case OPT_save_temps:
debug = 1; save_temps = 1;
break; break;
case OPT_v: case OPT_v:
...@@ -647,7 +647,7 @@ run_gcc (unsigned argc, char *argv[]) ...@@ -647,7 +647,7 @@ run_gcc (unsigned argc, char *argv[])
obstack_ptr_grow (&argv_obstack, dumpbase); obstack_ptr_grow (&argv_obstack, dumpbase);
} }
if (linker_output && debug) if (linker_output && save_temps)
{ {
ltrans_output_file = (char *) xmalloc (strlen (linker_output) ltrans_output_file = (char *) xmalloc (strlen (linker_output)
+ sizeof (".ltrans.out") + 1); + sizeof (".ltrans.out") + 1);
...@@ -785,7 +785,7 @@ cont: ...@@ -785,7 +785,7 @@ cont:
/* If we are not preserving the ltrans input files then /* If we are not preserving the ltrans input files then
truncate them as soon as we have processed it. This truncate them as soon as we have processed it. This
reduces temporary disk-space usage. */ reduces temporary disk-space usage. */
if (! debug) if (! save_temps)
fprintf (mstream, "\t@-touch -r %s %s.tem > /dev/null 2>&1 " fprintf (mstream, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
"&& mv %s.tem %s\n", "&& mv %s.tem %s\n",
input_name, input_name, input_name, input_name); input_name, input_name, input_name, input_name);
......
...@@ -275,7 +275,7 @@ tlink_init (void) ...@@ -275,7 +275,7 @@ tlink_init (void)
else else
{ {
tlink_verbose = 1; tlink_verbose = 1;
if (vflag) if (verbose)
tlink_verbose = 2; tlink_verbose = 2;
if (debug) if (debug)
tlink_verbose = 3; tlink_verbose = 3;
......
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