#include "collect2.h"
#include "collect2-aix.h"
+#include "diagnostic.h"
#include "demangle.h"
#include "obstack.h"
#include "intl.h"
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);
-}
\f
static void
handler (int signo)
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++;
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)
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. */
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)
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
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
#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
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)
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;
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);
if (err != 0)
{
errno = err;
- fatal_perror (errmsg);
+ fatal_error ("%s: %m", _(errmsg));
}
else
- fatal (errmsg);
+ fatal_error (errmsg);
}
free (response_arg);
/* 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')
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);
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);
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)
{
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
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
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)
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);
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");
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;
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);
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))
{
}
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. */
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 */