*** empty log message ***
authorRichard Stallman <rms@gnu.org>
Wed, 1 Apr 1992 05:06:34 +0000 (05:06 +0000)
committerRichard Stallman <rms@gnu.org>
Wed, 1 Apr 1992 05:06:34 +0000 (05:06 +0000)
From-SVN: r656

gcc/collect2.c

index 320ac7d47df909cadd8979c908b959d787ad7fcc..292ee3690d80fba9edd33c946e22d3a310cf60d9 100644 (file)
@@ -45,12 +45,10 @@ extern int errno;
 #include "config.h"
 
 #ifndef __STDC__
-#include "gvarargs.h"
 #define generic char
 #define const
 
 #else
-#include "gstdarg.h"
 #define generic void
 #endif
 
@@ -198,11 +196,8 @@ static void  choose_temp_base ();
 generic *xcalloc ();
 generic *xmalloc ();
 \f
-
-#if !defined(HAVE_STRERROR) && !defined(_OSF_SOURCE)
-
 char *
-strerror (e)
+my_strerror (e)
      int e;
 {
   extern char *sys_errlist[];
@@ -218,9 +213,6 @@ strerror (e)
   sprintf (buffer, "Unknown error %d", e);
   return buffer;
 }
-
-#endif
-
 \f
 /* Delete tempfiles and exit function.  */
 
@@ -238,109 +230,43 @@ my_exit (status)
 }
 
 \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.  */
 
@@ -374,7 +300,7 @@ xcalloc (size1, size2)
   if (ptr)
     return ptr;
 
-  fatal ("Out of memory.");
+  fatal ("out of memory");
   return (generic *)0;
 }
 
@@ -386,7 +312,7 @@ xmalloc (size)
   if (ptr)
     return ptr;
 
-  fatal ("Out of memory.");
+  fatal ("out of memory");
   return (generic *)0;
 }
 
@@ -398,7 +324,8 @@ savestring (input, size)
      int size;
 {
   char *output = (char *) xmalloc (size + 1);
-  strcpy (output, input);
+  bcopy (input, output, size);
+  output[size] = 0;
   return output;
 }
 \f
@@ -792,12 +719,12 @@ main (argc, argv)
 
   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)
     {
@@ -897,7 +824,7 @@ fork_execute (prog, argv)
   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);
@@ -1070,16 +997,16 @@ scan_prog_file (prog_name, which_pass)
     {
       /* 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.  */
@@ -1087,7 +1014,7 @@ scan_prog_file (prog_name, which_pass)
   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");
@@ -1351,7 +1278,7 @@ scan_prog_file (prog_name, which_pass)
 
   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;
@@ -1374,7 +1301,7 @@ scan_prog_file (prog_name, which_pass)
       || 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
 
@@ -1505,7 +1432,7 @@ scan_prog_file (prog_name, which_pass)
     }
 
   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
@@ -1518,10 +1445,15 @@ scan_prog_file (prog_name, which_pass)
       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)
@@ -1583,7 +1515,7 @@ scan_prog_file (prog_name, which_pass)
   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");