From 11091b4d06907a117524c3ac2b2a221d18cbb8dc Mon Sep 17 00:00:00 2001 From: jsm28 Date: Thu, 19 May 2011 16:25:12 +0000 Subject: [PATCH] * collect2.c: Include diagnostic.h. (fatal_perror, fatal, error, fancy_abort): Remove. (main): Set progname. Call xmalloc_set_program_name and diagnostic_initialize. (maybe_run_lto_and_relink, main, collect_execute, scan_prog_file, scan_libraries, resolve_lib_name): Call fatal_error instead of fatal and fatal_perror. * collect2.h (error, fatal, fatal_perror): Don't declare. * tlink.c: Include diagnostic-core.h. (recompile_files): Call fatal_error instead of fatal_perror. * Makefile.in (COLLECT2_OBJS): Include diagnostic.o, pretty-print.o and input.o. (collect2.o, tlink.o): Update dependencies. testsuite: * lib/prune.exe (prune_gcc_output): Expect "error:" in collect2 output. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@173915 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 16 ++++++ gcc/Makefile.in | 8 ++- gcc/collect2.c | 130 ++++++++++++++------------------------------ gcc/collect2.h | 6 +- gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/lib/prune.exp | 4 +- gcc/tlink.c | 7 ++- 7 files changed, 75 insertions(+), 101 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5a58ad5b505..8dddfb46c54 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2011-05-19 Joseph Myers + + * collect2.c: Include diagnostic.h. + (fatal_perror, fatal, error, fancy_abort): Remove. + (main): Set progname. Call xmalloc_set_program_name and + diagnostic_initialize. + (maybe_run_lto_and_relink, main, collect_execute, scan_prog_file, + scan_libraries, resolve_lib_name): Call fatal_error instead of + fatal and fatal_perror. + * collect2.h (error, fatal, fatal_perror): Don't declare. + * tlink.c: Include diagnostic-core.h. + (recompile_files): Call fatal_error instead of fatal_perror. + * Makefile.in (COLLECT2_OBJS): Include diagnostic.o, + pretty-print.o and input.o. + (collect2.o, tlink.o): Update dependencies. + 2011-05-19 Rainer Orth * config/i386/i386.md (tls_initial_exec_64_sun): Add semicolon. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 3be33a2b54a..27ffbbc9df1 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2089,7 +2089,8 @@ sbitmap.o: sbitmap.c sbitmap.h $(CONFIG_H) $(SYSTEM_H) coretypes.h $(BASIC_BLOCK ebitmap.o: ebitmap.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(EBITMAP_H) sparseset.o: sparseset.c $(SYSTEM_H) sparseset.h $(CONFIG_H) -COLLECT2_OBJS = collect2.o collect2-aix.o tlink.o intl.o version.o +COLLECT2_OBJS = collect2.o collect2-aix.o tlink.o intl.o version.o \ + diagnostic.o pretty-print.o input.o COLLECT2_LIBS = @COLLECT2_LIBS@ collect2$(exeext): $(COLLECT2_OBJS) $(LIBDEPS) # Don't try modifying collect2 (aka ld) in place--it might be linking this. @@ -2098,7 +2099,8 @@ collect2$(exeext): $(COLLECT2_OBJS) $(LIBDEPS) mv -f T$@ $@ collect2.o : collect2.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) intl.h \ - $(OBSTACK_H) $(DEMANGLE_H) collect2.h collect2-aix.h version.h + $(OBSTACK_H) $(DEMANGLE_H) collect2.h collect2-aix.h version.h \ + $(DIAGNOSTIC_H) $(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \ -DTARGET_MACHINE=\"$(target_noncanonical)\" \ -c $(srcdir)/collect2.c $(OUTPUT_OPTION) @TARGET_SYSTEM_ROOT_DEFINE@ @@ -2107,7 +2109,7 @@ collect2-aix.o : collect2-aix.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ collect2-aix.h tlink.o: tlink.c $(DEMANGLE_H) $(HASHTAB_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ - $(OBSTACK_H) collect2.h intl.h + $(OBSTACK_H) collect2.h intl.h $(DIAGNOSTIC_CORE_H) lto-wrapper$(exeext): lto-wrapper.o intl.o $(LIBDEPS) +$(COMPILER) $(ALL_COMPILERFLAGS) $(LDFLAGS) -o T$@ lto-wrapper.o intl.o $(LIBS) diff --git a/gcc/collect2.c b/gcc/collect2.c index 0c554f05346..dadf82d34b1 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -44,6 +44,7 @@ along with GCC; see the file COPYING3. If not see #include "collect2.h" #include "collect2-aix.h" +#include "diagnostic.h" #include "demangle.h" #include "obstack.h" #include "intl.h" @@ -444,62 +445,6 @@ notice_translated (const char *cmsgid, ...) vfprintf (stderr, cmsgid, ap); va_end (ap); } - -/* Die when sys call fails. */ - -void -fatal_perror (const char * cmsgid, ...) -{ - int e = errno; - va_list ap; - - va_start (ap, cmsgid); - fprintf (stderr, "collect2: "); - vfprintf (stderr, _(cmsgid), ap); - fprintf (stderr, ": %s\n", xstrerror (e)); - va_end (ap); - - collect_exit (FATAL_EXIT_CODE); -} - -/* Just die. */ - -void -fatal (const char * cmsgid, ...) -{ - va_list ap; - - va_start (ap, cmsgid); - fprintf (stderr, "collect2: "); - vfprintf (stderr, _(cmsgid), ap); - fprintf (stderr, "\n"); - va_end (ap); - - collect_exit (FATAL_EXIT_CODE); -} - -/* Write error message. */ - -void -error (const char * gmsgid, ...) -{ - va_list ap; - - va_start (ap, gmsgid); - fprintf (stderr, "collect2: "); - vfprintf (stderr, _(gmsgid), ap); - fprintf (stderr, "\n"); - va_end(ap); -} - -/* In case obstack is linked in, and abort is defined to fancy_abort, - provide a default entry. */ - -void -fancy_abort (const char *file, int line, const char *func) -{ - fatal ("internal gcc abort in %s, at %s:%d", func, file, line); -} static void handler (int signo) @@ -953,7 +898,7 @@ maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, size_t num_files; if (!lto_wrapper) - fatal ("COLLECT_LTO_WRAPPER must be set"); + fatal_error ("COLLECT_LTO_WRAPPER must be set"); num_lto_c_args++; @@ -1151,6 +1096,13 @@ main (int argc, char **argv) int num_c_args; char **old_argv; + p = argv[0] + strlen (argv[0]); + while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])) + --p; + progname = p; + + xmalloc_set_program_name (progname); + old_argv = argv; expandargv (&argc, &argv); if (argv != old_argv) @@ -1181,6 +1133,8 @@ main (int argc, char **argv) gcc_init_libintl (); + diagnostic_initialize (global_dc, 0); + /* Do not invoke xcalloc before this point, since locale needs to be set first, in case a diagnostic is issued. */ @@ -1270,7 +1224,7 @@ main (int argc, char **argv) c_ptr = CONST_CAST2 (const char **, char **, c_argv); if (argc < 2) - fatal ("no arguments"); + fatal_error ("no arguments"); #ifdef SIGQUIT if (signal (SIGQUIT, SIG_IGN) != SIG_IGN) @@ -1671,10 +1625,10 @@ main (int argc, char **argv) exportf = fopen (export_file, "w"); if (exportf == (FILE *) 0) - fatal_perror ("fopen %s", export_file); + fatal_error ("fopen %s: %m", export_file); write_aix_file (exportf, exports.first); if (fclose (exportf)) - fatal_perror ("fclose %s", export_file); + fatal_error ("fclose %s: %m", export_file); } #endif @@ -1854,12 +1808,12 @@ main (int argc, char **argv) maybe_unlink(output_file); outf = fopen (c_file, "w"); if (outf == (FILE *) 0) - fatal_perror ("fopen %s", c_file); + fatal_error ("fopen %s: %m", c_file); write_c_file (outf, c_file); if (fclose (outf)) - fatal_perror ("fclose %s", c_file); + fatal_error ("fclose %s: %m", c_file); /* Tell the linker that we have initializer and finalizer functions. */ #ifdef LD_INIT_SWITCH @@ -1889,10 +1843,10 @@ main (int argc, char **argv) #endif exportf = fopen (export_file, "w"); if (exportf == (FILE *) 0) - fatal_perror ("fopen %s", export_file); + fatal_error ("fopen %s: %m", export_file); write_aix_file (exportf, exports.first); if (fclose (exportf)) - fatal_perror ("fclose %s", export_file); + fatal_error ("fclose %s: %m", export_file); } #endif @@ -1956,7 +1910,7 @@ collect_wait (const char *prog, struct pex_obj *pex) int status; if (!pex_get_status (pex, 1, &status)) - fatal_perror ("can't get program status"); + fatal_error ("can't get program status: %m"); pex_free (pex); if (status) @@ -2025,17 +1979,17 @@ collect_execute (const char *prog, char **argv, const char *outname, f = fopen (response_file, "w"); if (f == NULL) - fatal ("could not open response file %s", response_file); + fatal_error ("could not open response file %s", response_file); status = writeargv (current_argv, f); if (status) - fatal ("could not write to response file %s", response_file); + fatal_error ("could not write to response file %s", response_file); status = fclose (f); if (EOF == status) - fatal ("could not close response file %s", response_file); + fatal_error ("could not close response file %s", response_file); response_arg = concat ("@", response_file, NULL); response_argv[0] = argv0; @@ -2068,11 +2022,11 @@ collect_execute (const char *prog, char **argv, const char *outname, since we might not end up needing something that we could not find. */ if (argv[0] == 0) - fatal ("cannot find '%s'", prog); + fatal_error ("cannot find '%s'", prog); pex = pex_init (0, "collect2", NULL); if (pex == NULL) - fatal_perror ("pex_init failed"); + fatal_error ("pex_init failed: %m"); errmsg = pex_run (pex, flags, argv[0], argv, outname, errname, &err); @@ -2081,10 +2035,10 @@ collect_execute (const char *prog, char **argv, const char *outname, if (err != 0) { errno = err; - fatal_perror (errmsg); + fatal_error ("%s: %m", _(errmsg)); } else - fatal (errmsg); + fatal_error (errmsg); } free (response_arg); @@ -2582,7 +2536,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, /* If we do not have an `nm', complain. */ if (nm_file_name == 0) - fatal ("cannot find 'nm'"); + fatal_error ("cannot find 'nm'"); nm_argv[argc++] = nm_file_name; if (NM_FLAGS[0] != '\0') @@ -2608,7 +2562,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, pex = pex_init (PEX_USE_PIPES, "collect2", NULL); if (pex == NULL) - fatal_perror ("pex_init failed"); + fatal_error ("pex_init failed: %m"); errmsg = pex_run (pex, 0, nm_file_name, real_nm_argv, NULL, HOST_BIT_BUCKET, &err); @@ -2617,10 +2571,10 @@ scan_prog_file (const char *prog_name, scanpass which_pass, if (err != 0) { errno = err; - fatal_perror (errmsg); + fatal_error ("%s: %m", _(errmsg)); } else - fatal (errmsg); + fatal_error (errmsg); } int_handler = (void (*) (int)) signal (SIGINT, SIG_IGN); @@ -2630,7 +2584,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, inf = pex_read_output (pex, 0); if (inf == NULL) - fatal_perror ("can't open nm output"); + fatal_error ("can't open nm output: %m"); if (debug) { @@ -2713,7 +2667,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, if (! (filter & SCAN_INIT)) break; if (which_pass != PASS_LIB) - fatal ("init function found in object %s", prog_name); + fatal_error ("init function found in object %s", prog_name); #ifndef LD_INIT_SWITCH add_to_list (&constructors, name); #endif @@ -2723,7 +2677,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, if (! (filter & SCAN_FINI)) break; if (which_pass != PASS_LIB) - fatal ("fini function found in object %s", prog_name); + fatal_error ("fini function found in object %s", prog_name); #ifndef LD_FINI_SWITCH add_to_list (&destructors, name); #endif @@ -2804,7 +2758,7 @@ scan_libraries (const char *prog_name) pex = pex_init (PEX_USE_PIPES, "collect2", NULL); if (pex == NULL) - fatal_perror ("pex_init failed"); + fatal_error ("pex_init failed: %m"); errmsg = pex_run (pex, 0, ldd_file_name, real_ldd_argv, NULL, NULL, &err); if (errmsg != NULL) @@ -2812,10 +2766,10 @@ scan_libraries (const char *prog_name) if (err != 0) { errno = err; - fatal_perror (errmsg); + fatal_error ("%s: %m", _(errmsg)); } else - fatal (errmsg); + fatal_error (errmsg); } int_handler = (void (*) (int)) signal (SIGINT, SIG_IGN); @@ -2825,7 +2779,7 @@ scan_libraries (const char *prog_name) inf = pex_read_output (pex, 0); if (inf == NULL) - fatal_perror ("can't open ldd output"); + fatal_error ("can't open ldd output: %m"); if (debug) notice ("\nldd output with constructors/destructors.\n"); @@ -2843,7 +2797,7 @@ scan_libraries (const char *prog_name) name = p; if (strncmp (name, "not found", sizeof ("not found") - 1) == 0) - fatal ("dynamic dependency %s not found", buf); + fatal_error ("dynamic dependency %s not found", buf); /* Find the end of the symbol name. */ for (end = p; @@ -2855,7 +2809,7 @@ scan_libraries (const char *prog_name) if (access (name, R_OK) == 0) add_to_list (&libraries, name); else - fatal ("unable to open dynamic dependency '%s'", buf); + fatal_error ("unable to open dynamic dependency '%s'", buf); if (debug) fprintf (stderr, "\t%s\n", buf); @@ -3016,7 +2970,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, if ((ldptr = ldopen (CONST_CAST (char *, prog_name), ldptr)) != NULL) { if (! MY_ISCOFF (HEADER (ldptr).f_magic)) - fatal ("%s: not a COFF file", prog_name); + fatal_error ("%s: not a COFF file", prog_name); if (GCC_CHECK_HDR (ldptr)) { @@ -3146,7 +3100,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, } else { - fatal ("%s: cannot open as COFF file", prog_name); + fatal_error ("%s: cannot open as COFF file", prog_name); } #ifdef COLLECT_EXPORT_LIST /* On AIX loop continues while there are more members in archive. */ @@ -3204,7 +3158,7 @@ resolve_lib_name (const char *name) if (debug) fprintf (stderr, "not found\n"); else - fatal ("library lib%s not found", name); + fatal_error ("library lib%s not found", name); return (NULL); } #endif /* COLLECT_EXPORT_LIST */ diff --git a/gcc/collect2.h b/gcc/collect2.h index e20cc43017a..e18892d3a55 100644 --- a/gcc/collect2.h +++ b/gcc/collect2.h @@ -1,5 +1,5 @@ /* Header file for collect/tlink routines. - Copyright (C) 1998, 2003, 2004, 2005, 2007, 2010 + Copyright (C) 1998, 2003, 2004, 2005, 2007, 2010, 2011 Free Software Foundation, Inc. This file is part of GCC. @@ -41,11 +41,7 @@ extern struct obstack temporary_obstack; extern char *temporary_firstobj; extern bool vflag, debug; -extern void error (const char *, ...) ATTRIBUTE_PRINTF_1; extern void notice_translated (const char *, ...) ATTRIBUTE_PRINTF_1; extern void notice (const char *, ...) ATTRIBUTE_PRINTF_1; -extern void fatal (const char *, ...) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; -extern void fatal_perror (const char *, ...) - ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; #endif /* ! GCC_COLLECT2_H */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a1919099fac..7a9dacdf9a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-05-19 Joseph Myers + + * lib/prune.exe (prune_gcc_output): Expect "error:" in collect2 + output. + 2011-05-19 Richard Guenther PR testsuite/49063 diff --git a/gcc/testsuite/lib/prune.exp b/gcc/testsuite/lib/prune.exp index 7e4f9ce1621..29d69b97341 100644 --- a/gcc/testsuite/lib/prune.exp +++ b/gcc/testsuite/lib/prune.exp @@ -1,4 +1,4 @@ -# Copyright (C) 1997, 1999, 2000, 2002, 2004, 2007, 2008, 2010 +# Copyright (C) 1997, 1999, 2000, 2002, 2004, 2007, 2008, 2010, 2011 # Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify @@ -25,7 +25,7 @@ proc prune_gcc_output { text } { regsub -all "(^|\n)\[^\n\]*: (recursively )?instantiated from \[^\n\]*" $text "" text regsub -all "(^|\n)\[^\n\]*: . skipping \[0-9\]* instantiation contexts \[^\n\]*" $text "" text regsub -all "(^|\n) inlined from \[^\n\]*" $text "" text - regsub -all "(^|\n)collect2: ld returned \[^\n\]*" $text "" text + regsub -all "(^|\n)collect2: error: ld returned \[^\n\]*" $text "" text regsub -all "(^|\n)collect: re(compiling|linking)\[^\n\]*" $text "" text regsub -all "(^|\n)Please submit.*instructions\[^\n\]*" $text "" text regsub -all "(^|\n)\[0-9\]\[0-9\]* errors\." $text "" text diff --git a/gcc/tlink.c b/gcc/tlink.c index 883aa0f0281..f0540478e72 100644 --- a/gcc/tlink.c +++ b/gcc/tlink.c @@ -2,7 +2,7 @@ them. Copyright (C) 1995, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2007, 2008, - 2009, 2010 Free Software Foundation, Inc. + 2009, 2010, 2011 Free Software Foundation, Inc. Contributed by Jason Merrill (jason@cygnus.com). This file is part of GCC. @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see #include "demangle.h" #include "collect2.h" #include "filenames.h" +#include "diagnostic-core.h" /* TARGET_64BIT may be defined to use driver specific functionality. */ #undef TARGET_64BIT @@ -477,9 +478,9 @@ recompile_files (void) the new file name already exists. Therefore, we explicitly remove the old file first. */ if (remove (f->key) == -1) - fatal_perror ("removing .rpo file"); + fatal_error ("removing .rpo file: %m"); if (rename (outname, f->key) == -1) - fatal_perror ("renaming .rpo file"); + fatal_error ("renaming .rpo file: %m"); if (!f->args) { -- 2.11.4.GIT