OSDN Git Service

* Makefile.in (gcc.o, gccspec.o, cppspec.o): Depend on gcc.h.
[pf3gnuchains/gcc-fork.git] / gcc / gcc.c
index 287641a..ff61c1c 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -30,14 +30,15 @@ and deleting the temporary files at the end.
 CC recognizes how to compile each input file by suffixes in the file names.
 Once it knows which kind of compilation to perform, the procedure for
 compilation is specified by a string called a "spec".  */
-\f
+
+
 #include "config.h"
 #include "system.h"
 #include <signal.h>
-
 #include "obstack.h"
 #include "intl.h"
 #include "prefix.h"
+#include "gcc.h"
 
 #ifdef VMS
 #define exit __posix_exit
@@ -177,6 +178,7 @@ static void set_spec                PROTO((const char *, const char *));
 static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *));
 static char *build_search_list PROTO((struct path_prefix *, const char *, int));
 static void putenv_from_prefixes PROTO((struct path_prefix *, const char *));
+static int access_check                PROTO((const char *, int));
 static char *find_a_file       PROTO((struct path_prefix *, const char *, int));
 static void add_prefix         PROTO((struct path_prefix *, const char *,
                                       const char *, int, int, int *));
@@ -189,7 +191,6 @@ static void clear_failure_queue PROTO((void));
 static int check_live_switch   PROTO((int, int));
 static const char *handle_braces PROTO((const char *));
 static char *save_string       PROTO((const char *, int));
-extern int do_spec             PROTO((const char *));
 static int do_spec_1           PROTO((const char *, int, const char *));
 static const char *find_file   PROTO((const char *));
 static int is_directory                PROTO((const char *, const char *, int));
@@ -217,18 +218,6 @@ static int execute                 PROTO ((void));
 static void unused_prefix_warnings     PROTO ((struct path_prefix *));
 static void clear_args                 PROTO ((void));
 static void fatal_error                        PROTO ((int));
-
-void fancy_abort               PROTO((void)) ATTRIBUTE_NORETURN;
-
-/* Called before processing to change/add/remove arguments. */
-extern void lang_specific_driver PROTO ((void (*) PVPROTO((const char *, ...)),
-                                        int *, char ***, int *));
-
-/* Called before linking.  Returns 0 on success and -1 on failure. */
-extern int lang_specific_pre_link ();
-
-/* Number of extra output files that lang_specific_pre_link may generate. */
-extern int lang_specific_extra_outfiles;
 \f
 /* Specs are strings containing lines, each of which (if not blank)
 is made up of a program name, and arguments separated by spaces.
@@ -500,7 +489,7 @@ static char *multilib_defaults;
 #define MULTILIB_DEFAULTS { "" }
 #endif
 
-static char *multilib_defaults_raw[] = MULTILIB_DEFAULTS;
+static const  char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
 
 struct user_specs {
   struct user_specs *next;
@@ -694,7 +683,7 @@ static struct compiler default_compilers[] =
    {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
                        %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
                        %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
-                       %{aux-info*} %{Qn:-fno-ident}\
+                       %{aux-info*} %{Qn:-fno-ident} -fpreprocessed\
                        %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
                        %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
                     %{!S:as %a %Y\
@@ -1053,26 +1042,6 @@ translate_options (argcp, argvp)
   *argcp = newindex;
 }
 \f
-char *
-xstrerror(e)
-     int e;
-{
-#ifdef HAVE_STRERROR
-
-  return strerror(e);
-
-#else
-
-  if (!e)
-    return "errno = 0";
-
-  if (e > 0 && e < sys_nerr)
-    return sys_errlist[e];
-
-  return "errno = ?";
-#endif
-}
-\f
 static char *
 skip_whitespace (p)
      char *p;
@@ -1178,10 +1147,8 @@ init_spec ()
 
 #ifdef EXTRA_SPECS
   extra_specs = (struct spec_list *)
-    xmalloc (sizeof(struct spec_list) *
+    xcalloc (sizeof(struct spec_list),
             (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
-  bzero ((PTR) extra_specs, sizeof(struct spec_list) *
-        (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
   
   for (i = (sizeof(extra_specs_1) / sizeof(extra_specs_1[0])) - 1; i >= 0; i--)
     {
@@ -1243,7 +1210,7 @@ set_spec (name, spec)
     {
       /* Not found - make it */
       sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
-      sl->name = save_string (name, strlen (name));
+      sl->name = xstrdup (name);
       sl->name_len = name_len;
       sl->ptr_spec = &sl->ptr;
       sl->alloc_p = 0;
@@ -1255,7 +1222,7 @@ set_spec (name, spec)
   old_spec = *(sl->ptr_spec);
   *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
                     ? concat (old_spec, spec + 1, NULL_PTR)
-                    : save_string (spec, strlen (spec)));
+                    : xstrdup (spec));
 
 #ifdef DEBUG_SPECS
   if (verbose_flag)
@@ -1676,12 +1643,11 @@ read_specs (filename, main_p)
                         (n_compilers + 2) * sizeof (struct compiler)));
 
          compilers[n_compilers].suffix = suffix;
-         bzero ((char *) compilers[n_compilers].spec,
-                sizeof compilers[n_compilers].spec);
+         memset (compilers[n_compilers].spec, 0,
+                 sizeof compilers[n_compilers].spec);
          compilers[n_compilers].spec[0] = spec;
          n_compilers++;
-         bzero ((char *) &compilers[n_compilers],
-                sizeof compilers[n_compilers]);
+         memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
        }
 
       if (*suffix == 0)
@@ -1737,9 +1703,7 @@ record_temp_file (filename, always_delete, fail_delete)
      int always_delete;
      int fail_delete;
 {
-  register char *name;
-  name = xmalloc (strlen (filename) + 1);
-  strcpy (name, filename);
+  register char * const name = xstrdup (filename);
 
   if (always_delete)
     {
@@ -1954,6 +1918,26 @@ putenv_from_prefixes (paths, env_var)
   putenv (build_search_list (paths, env_var, 1));
 }
 \f
+/* Check whether NAME can be accessed in MODE.  This is like access,
+   except that it never considers directories to be executable.  */
+
+static int
+access_check (name, mode)
+     const char *name;
+     int mode;
+{
+  if (mode == X_OK)
+    {
+      struct stat st;
+
+      if (stat (name, &st) < 0
+         || S_ISDIR (st.st_mode))
+       return -1;
+    }
+
+  return access (name, mode);
+}
+
 /* Search for NAME using the prefix list PREFIXES.  MODE is passed to
    access to check permissions.
    Return 0 if not found, otherwise return its name, allocated with malloc.  */
@@ -1970,23 +1954,13 @@ find_a_file (pprefix, name, mode)
   int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
 
 #ifdef DEFAULT_ASSEMBLER
-  if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) {
-    name = DEFAULT_ASSEMBLER;
-    len = strlen(name)+1;
-    temp = xmalloc (len);
-    strcpy (temp, name);
-    return temp;
-  }
+  if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
+    return xstrdup (DEFAULT_ASSEMBLER);
 #endif
 
 #ifdef DEFAULT_LINKER
-  if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) {
-    name = DEFAULT_LINKER;
-    len = strlen(name)+1;
-    temp = xmalloc (len);
-    strcpy (temp, name);
-    return temp;
-  }
+  if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0)
+    return xstrdup (DEFAULT_LINKER);
 #endif
 
   if (machine_suffix)
@@ -2022,7 +1996,7 @@ find_a_file (pprefix, name, mode)
                strcat (temp, machine_suffix);
                strcat (temp, name);
                strcat (temp, file_suffix);
-               if (access (temp, mode) == 0)
+               if (access_check (temp, mode) == 0)
                  {
                    if (pl->used_flag_ptr != 0)
                      *pl->used_flag_ptr = 1;
@@ -2034,7 +2008,7 @@ find_a_file (pprefix, name, mode)
            strcpy (temp, pl->prefix);
            strcat (temp, machine_suffix);
            strcat (temp, name);
-           if (access (temp, mode) == 0)
+           if (access_check (temp, mode) == 0)
              {
                if (pl->used_flag_ptr != 0)
                  *pl->used_flag_ptr = 1;
@@ -2054,7 +2028,7 @@ find_a_file (pprefix, name, mode)
                strcat (temp, just_machine_suffix);
                strcat (temp, name);
                strcat (temp, file_suffix);
-               if (access (temp, mode) == 0)
+               if (access_check (temp, mode) == 0)
                  {
                    if (pl->used_flag_ptr != 0)
                      *pl->used_flag_ptr = 1;
@@ -2065,7 +2039,7 @@ find_a_file (pprefix, name, mode)
            strcpy (temp, pl->prefix);
            strcat (temp, just_machine_suffix);
            strcat (temp, name);
-           if (access (temp, mode) == 0)
+           if (access_check (temp, mode) == 0)
              {
                if (pl->used_flag_ptr != 0)
                  *pl->used_flag_ptr = 1;
@@ -2084,7 +2058,7 @@ find_a_file (pprefix, name, mode)
                strcpy (temp, pl->prefix);
                strcat (temp, name);
                strcat (temp, file_suffix);
-               if (access (temp, mode) == 0)
+               if (access_check (temp, mode) == 0)
                  {
                    if (pl->used_flag_ptr != 0)
                      *pl->used_flag_ptr = 1;
@@ -2094,7 +2068,7 @@ find_a_file (pprefix, name, mode)
 
            strcpy (temp, pl->prefix);
            strcat (temp, name);
-           if (access (temp, mode) == 0)
+           if (access_check (temp, mode) == 0)
              {
                if (pl->used_flag_ptr != 0)
                  *pl->used_flag_ptr = 1;
@@ -2587,8 +2561,8 @@ process_command (argc, argv)
 
   /* Figure compiler version from version string.  */
 
-  compiler_version = temp1 =
-    save_string (version_string, strlen (version_string));
+  compiler_version = temp1 = xstrdup (version_string); 
+
   for (; *temp1; ++temp1)
     {
       if (*temp1 == ' ')
@@ -2725,7 +2699,7 @@ process_command (argc, argv)
   translate_options (&argc, &argv);
 
   /* Do language-specific adjustment/addition of flags.  */
-  lang_specific_driver (fatal, &argc, &argv, &added_libraries);
+  lang_specific_driver (&argc, &argv, &added_libraries);
 
   /* Scan argv twice.  Here, the first time, just count how many switches
      there will be in their vector, and how many input files in theirs.
@@ -4925,26 +4899,26 @@ main (argc, argv)
       printf ("install: %s%s\n", standard_exec_prefix, machine_suffix);
       printf ("programs: %s\n", build_search_list (&exec_prefixes, "", 0));
       printf ("libraries: %s\n", build_search_list (&startfile_prefixes, "", 0));
-      exit (0);
+      return (0);
     }
 
   if (print_file_name)
     {
       printf ("%s\n", find_file (print_file_name));
-      exit (0);
+      return (0);
     }
 
   if (print_prog_name)
     {
       char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK);
       printf ("%s\n", (newname ? newname : print_prog_name));
-      exit (0);
+      return (0);
     }
 
   if (print_multi_lib)
     {
       print_multilib_info ();
-      exit (0);
+      return (0);
     }
 
   if (print_multi_directory)
@@ -4953,7 +4927,7 @@ main (argc, argv)
        printf (".\n");
       else
        printf ("%s\n", multilib_dir);
-      exit (0);
+      return (0);
     }
 
   if (print_help_list)
@@ -4963,9 +4937,9 @@ main (argc, argv)
       if (! verbose_flag)
        {
          printf ("\nFor bug reporting instructions, please see:\n");
-         printf ("<URL:http://gcc.gnu.org/faq.html#bugreport>.\n");
+         printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>.\n");
          
-         exit (0);
+         return (0);
        }
 
       /* We do not exit here.  Instead we have created a fake input file
@@ -4992,7 +4966,7 @@ main (argc, argv)
                version_string, compiler_version);
 
       if (n_infiles == 0)
-       exit (0);
+       return (0);
     }
 
   if (n_infiles == added_libraries)
@@ -5003,13 +4977,11 @@ main (argc, argv)
 
   i = n_infiles;
   i += lang_specific_extra_outfiles;
-  outfiles = (const char **) xmalloc (i * sizeof (char *));
-  bzero ((char *) outfiles, i * sizeof (char *));
+  outfiles = (const char **) xcalloc (i, sizeof (char *));
 
   /* Record which files were specified explicitly as link input.  */
 
-  explicit_link_files = xmalloc (n_infiles);
-  bzero (explicit_link_files, n_infiles);
+  explicit_link_files = xcalloc (1, n_infiles);
 
   for (i = 0; (int)i < n_infiles; i++)
     {
@@ -5156,12 +5128,10 @@ main (argc, argv)
   if (print_help_list)
     {
       printf ("\nFor bug reporting instructions, please see:\n");
-      printf ("<URL:http://gcc.gnu.org/faq.html#bugreport>\n");
+      printf ("<URL:http://www.gnu.org/software/gcc/faq.html#bugreport>\n");
     }
   
-  exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
-  /* NOTREACHED */
-  return 0;
+  return (error_count > 0 ? (signal_count ? 2 : 1) : 0);
 }
 
 /* Find the proper compilation spec for the file name NAME,
@@ -5221,8 +5191,9 @@ lookup_compiler (name, length, language)
              language = cp->spec[0] + 1;
              new = (struct compiler *) xmalloc (sizeof (struct compiler));
              new->suffix = cp->suffix;
-             bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
-                    (char *) new->spec, sizeof new->spec);
+             memcpy (new->spec,
+                     lookup_compiler (NULL_PTR, 0, language)->spec,
+                     sizeof new->spec);
              return new;
            }
 
@@ -5234,31 +5205,6 @@ lookup_compiler (name, length, language)
   return 0;
 }
 \f
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR value = (PTR) malloc (size);
-  if (value == 0)
-    fatal ("virtual memory exhausted");
-  return value;
-}
-
-PTR
-xrealloc (old, size)
-  PTR old;
-  size_t size;
-{
-  register PTR ptr;
-  if (old)
-    ptr = (PTR) realloc (old, size);
-  else
-    ptr = (PTR) malloc (size);
-  if (ptr == 0)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
-
 static char *
 save_string (s, len)
   const char *s;