#include "config.h"
#ifndef __STDC__
-#include "gvarargs.h"
#define generic char
#define const
#else
-#include "gstdarg.h"
#define generic void
#endif
generic *xcalloc ();
generic *xmalloc ();
\f
-
-#if !defined(HAVE_STRERROR) && !defined(_OSF_SOURCE)
-
char *
-strerror (e)
+my_strerror (e)
int e;
{
extern char *sys_errlist[];
sprintf (buffer, "Unknown error %d", e);
return buffer;
}
-
-#endif
-
\f
/* Delete tempfiles and exit function. */
}
\f
-#ifndef __STDC__
-
/* Die when sys call fails. */
-/*VARARGS*/
static void
-fatal_perror (va_alist)
+fatal_perror (string, arg1, arg2, arg3)
+ char *string;
{
- char *string;
- va_list vptr;
int e = errno;
- va_start (vptr);
- string = va_arg (vptr, char *);
fprintf (stderr, "collect: ");
- vfprintf (stderr, string, vptr);
- fprintf (stderr, ": %s\n", strerror (e));
- va_end (vptr);
+ fprintf (stderr, string, arg1, arg2, arg3);
+ fprintf (stderr, ": %s\n", my_strerror (e));
my_exit (1);
}
/* Just die. */
-/*VARARGS*/
static void
-fatal (va_alist)
+fatal (string, arg1, arg2, arg3)
+ char *string;
{
- char *string;
- va_list vptr;
-
- va_start (vptr);
- string = va_arg (vptr, char *);
fprintf (stderr, "collect: ");
- vfprintf (stderr, string, vptr);
+ fprintf (stderr, string, arg1, arg2, arg3);
fprintf (stderr, "\n");
- va_end (vptr);
my_exit (1);
}
/* Write error message. */
-/*VARARGS*/
static void
-error (va_alist)
+error (string, arg1, arg2, arg3, arg4)
+ char *string;
{
- char *string;
- va_list vptr;
-
- va_start (vptr);
- string = va_arg (vptr, char *);
fprintf (stderr, "collect: ");
- vfprintf (stderr, string, vptr);
+ fprintf (stderr, string, arg1, arg2, arg3, arg4);
fprintf (stderr, "\n");
- va_end (vptr);
}
-#else
-
-static void
-fatal_perror (char *string, ...)
-{
- va_list vptr;
- int e = errno;
-
- va_start (vptr, string);
- fprintf (stderr, "collect: ");
- vfprintf (stderr, string, vptr);
- fprintf (stderr, ": %s\n", strerror (e));
- va_end (vptr);
- my_exit (1);
-}
-
-/* Just die. */
-
-static void
-fatal (char *string, ...)
-{
- va_list vptr;
-
- va_start (vptr, string);
- fprintf (stderr, "collect: ");
- vfprintf (stderr, string, vptr);
- fprintf (stderr, "\n");
- va_end (vptr);
- my_exit (1);
-}
-
-/* Write error message. */
-
-static void
-error (char *string, ...)
-{
- va_list vptr;
-
- va_start (vptr, string);
- fprintf (stderr, "collect: ");
- vfprintf (stderr, string, vptr);
- fprintf (stderr, "\n");
- va_end (vptr);
-}
-#endif
-
-\f
/* In case obstack is linked in, and abort is defined to fancy_abort,
provide a default entry. */
if (ptr)
return ptr;
- fatal ("Out of memory.");
+ fatal ("out of memory");
return (generic *)0;
}
if (ptr)
return ptr;
- fatal ("Out of memory.");
+ fatal ("out of memory");
return (generic *)0;
}
int size;
{
char *output = (char *) xmalloc (size + 1);
- strcpy (output, input);
+ bcopy (input, output, size);
+ output[size] = 0;
return output;
}
\f
outf = fopen (c_file, "w");
if (outf == (FILE *)0)
- fatal_perror ("Can't write %s", c_file);
+ fatal_perror ("%s", c_file);
write_c_file (outf, c_file);
if (fclose (outf))
- fatal_perror ("Can't close %s", c_file);
+ fatal_perror ("closing %s", c_file);
if (debug)
{
if (pid == 0) /* child context */
{
execvp (prog, argv);
- fatal_perror ("Execute %s", prog);
+ fatal_perror ("executing %s", prog);
}
int_handler = (void (*) ())signal (SIGINT, SIG_IGN);
{
/* setup stdout */
if (dup2 (pipe_fd[1], 1) < 0)
- fatal_perror ("Dup2 (%d, 1)", pipe_fd[1]);
+ fatal_perror ("dup2 (%d, 1)", pipe_fd[1]);
if (close (pipe_fd[0]) < 0)
- fatal_perror ("Close (%d)", pipe_fd[0]);
+ fatal_perror ("close (%d)", pipe_fd[0]);
if (close (pipe_fd[1]) < 0)
- fatal_perror ("Close (%d)", pipe_fd[1]);
+ fatal_perror ("close (%d)", pipe_fd[1]);
execv (nm_file_name, nm_argv);
- fatal_perror ("Execute %s", nm_file_name);
+ fatal_perror ("executing %s", nm_file_name);
}
/* Parent context from here on. */
quit_handler = (void (*) ())signal (SIGQUIT, SIG_IGN);
if (close (pipe_fd[1]) < 0)
- fatal_perror ("Close (%d)", pipe_fd[1]);
+ fatal_perror ("close (%d)", pipe_fd[1]);
if (debug)
fprintf (stderr, "\nnm output with constructors/destructors.\n");
prog_fd = open (prog_name, (rw) ? O_RDWR : O_RDONLY);
if (prog_fd < 0)
- fatal_perror ("Can't read %s", prog_name);
+ fatal_perror ("can't read %s", prog_name);
obj_file = read_file (prog_name, prog_fd, rw);
obj = obj_file->start;
|| hdr.moh_cpu_subtype != OUR_CPU_SUBTYPE
|| hdr.moh_vendor_type != OUR_VENDOR_TYPE)
{
- fatal ("incompatibilities exist between object file & expected values.");
+ fatal ("incompatibilities between object file & expected values");
}
#endif
}
if (symbol_load_cmds == 0)
- fatal ("no symbol table found.");
+ fatal ("no symbol table found");
/* Update the program file now, rewrite header and load commands. At present,
we assume that there is enough space after the last load command to insert
size_t size;
if (cmd_strings == -1)
- fatal ("no cmd_strings found.");
+ fatal ("no cmd_strings found");
+
+ /* Add __main to initializer list.
+ If we are building a program instead of a shared library, don't
+ do anything, since in the current version, you cannot do mallocs
+ and such in the constructors. */
- /* Add __main to initializer list. */
- if (main_sym != (symbol_info_t *)0)
+ if (main_sym != (symbol_info_t *)0
+ && ((hdr.moh_flags & MOH_EXECABLE_F) == 0))
add_func_table (&hdr, load_array, main_sym, FNTC_INITIALIZATION);
if (debug)
end_file (obj_file);
if (close (prog_fd))
- fatal_perror ("Can't close %s", prog_name);
+ fatal_perror ("closing %s", prog_name);
if (debug)
fprintf (stderr, "\n");