aboutsummaryrefslogtreecommitdiff
path: root/gcc/collect2.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2011-05-19 16:25:12 +0000
committerJoseph Myers <joseph@codesourcery.com>2011-05-19 16:25:12 +0000
commit5c0759f4d31f97a4eac4efa6d0b25a924087f07c (patch)
treed058c00dc1d7bc91f5480576092941a860ad9b64 /gcc/collect2.c
parente62965306d667ab4d392c085b8faf9d4439095b9 (diff)
* 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: https://gcc.gnu.org/svn/gcc/trunk@173915 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/collect2.c')
-rw-r--r--gcc/collect2.c130
1 files changed, 42 insertions, 88 deletions
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 */