OSDN Git Service

* config/avr/avr-protos.h (avr_output_addr_vec_elt): Prototype.
[pf3gnuchains/gcc-fork.git] / gcc / collect2.c
index f69d56a..49cb0e7 100644 (file)
@@ -1,6 +1,7 @@
 /* Collect static initialization info into data structures that can be
    traversed by C++ initialization and finalization routines.
-   Copyright (C) 1992, 93-99, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000 Free Software Foundation, Inc.
    Contributed by Chris Smith (csmith@convex.com).
    Heavily modified by Michael Meissner (meissner@cygnus.com),
    Per Bothner (bothner@cygnus.com), and John Gilmore (gnu@cygnus.com).
@@ -201,7 +202,6 @@ static const char *c_file;          /* <xxx>.c for constructor/destructor list.  */
 static const char *o_file;             /* <xxx>.o for constructor/destructor list.  */
 #ifdef COLLECT_EXPORT_LIST
 static const char *export_file;                /* <xxx>.x for AIX export list.  */
-static const char *import_file;                /* <xxx>.p for AIX import list.  */
 #endif
 const char *ldout;                     /* File for ld errors.  */
 static const char *output_file;                /* Output file for ld.  */
@@ -217,8 +217,6 @@ static struct head constructors;    /* list of constructors found */
 static struct head destructors;                /* list of destructors found */
 #ifdef COLLECT_EXPORT_LIST
 static struct head exports;            /* list of exported symbols */
-static struct head imports;            /* list of imported symbols */
-static struct head undefined;          /* list of undefined symbols */
 #endif
 static struct head frame_tables;       /* list of frame unwind info tables */
 
@@ -295,7 +293,6 @@ static void scan_libraries  PARAMS ((const char *));
 static int is_in_list          PARAMS ((const char *, struct id *));
 static void write_aix_file     PARAMS ((FILE *, struct id *));
 static char *resolve_lib_name  PARAMS ((const char *));
-static int use_import_list     PARAMS ((const char *));
 static int ignore_library      PARAMS ((const char *));
 #endif
 static char *extract_string    PARAMS ((const char **));
@@ -337,9 +334,6 @@ collect_exit (status)
 #ifdef COLLECT_EXPORT_LIST
   if (export_file != 0 && export_file[0])
     maybe_unlink (export_file);
-
-  if (import_file != 0 && import_file[0])
-    maybe_unlink (import_file);
 #endif
 
   if (ldout != 0 && ldout[0])
@@ -470,9 +464,6 @@ handler (signo)
 #ifdef COLLECT_EXPORT_LIST
   if (export_file != 0 && export_file[0])
     maybe_unlink (export_file);
-
-  if (import_file != 0 && import_file[0])
-    maybe_unlink (import_file);
 #endif
 
   signal (signo, SIG_DFL);
@@ -875,7 +866,7 @@ main (argc, argv)
   int num_c_args       = argc+9;
 
 #if defined (COLLECT2_HOST_INITIALIZATION)
-  /* Perform system dependant initialization, if neccessary.  */
+  /* Perform system dependent initialization, if neccessary.  */
   COLLECT2_HOST_INITIALIZATION;
 #endif
 
@@ -1072,7 +1063,6 @@ main (argc, argv)
   o_file = make_temp_file (".o");
 #ifdef COLLECT_EXPORT_LIST
   export_file = make_temp_file (".x");
-  import_file = make_temp_file (".p");
 #endif
   ldout = make_temp_file (".ld");
   *c_ptr++ = c_file_name;
@@ -1106,6 +1096,15 @@ main (argc, argv)
        *c_ptr++ = obstack_copy0 (&permanent_obstack, q, strlen (q));
       if (strncmp (q, "-shared", sizeof ("-shared") - 1) == 0)
        shared_obj = 1;
+      if (*q == '-' && q[1] == 'B')
+       {
+         *c_ptr++ = obstack_copy0 (&permanent_obstack, q, strlen (q));
+         if (q[2] == 0)
+           {
+             q = extract_string (&p);
+             *c_ptr++ = obstack_copy0 (&permanent_obstack, q, strlen (q));
+           }
+       }
     }
   obstack_free (&temporary_obstack, temporary_firstobj);
   *c_ptr++ = "-fno-exceptions";
@@ -1164,14 +1163,6 @@ main (argc, argv)
                /* Resolving full library name.  */
                const char *s = resolve_lib_name (arg+2);
 
-               /* If we will use an import list for this library,
-                  we should exclude it from ld args.  */
-               if (use_import_list (s))
-                 {
-                   ld1--;
-                   ld2--;
-                 }
-
                /* Saving a full library name.  */
                add_to_list (&libs, s);
              }
@@ -1190,7 +1181,7 @@ main (argc, argv)
                output_file = *ld1++ = *ld2++ = *++argv;
              else if (1
 #ifdef SWITCHES_NEED_SPACES
-                      && ! index (SWITCHES_NEED_SPACES, arg[1])
+                      && ! strchr (SWITCHES_NEED_SPACES, arg[1])
 #endif
                       )
 
@@ -1219,9 +1210,9 @@ main (argc, argv)
              break;
            }
        }
-      else if ((p = rindex (arg, '.')) != (char *) 0
+      else if ((p = strrchr (arg, '.')) != (char *) 0
               && (strcmp (p, ".o") == 0 || strcmp (p, ".a") == 0
-                  || strcmp (p, ".so") == 0))
+                  || strcmp (p, ".so") == 0 || strcmp (p, ".lo") == 0))
        {
          if (first_file)
            {
@@ -1236,20 +1227,12 @@ main (argc, argv)
                  *ld2++ = arg;
                }
            }
-         if (p[1] == 'o')
+         if (p[1] == 'o' || p[1] == 'l')
            *object++ = arg;
 #ifdef COLLECT_EXPORT_LIST
          /* libraries can be specified directly, i.e. without -l flag.  */
                  else
                    { 
-             /* If we will use an import list for this library,
-                we should exclude it from ld args.  */
-             if (use_import_list (arg))
-               {
-                 ld1--;
-                 ld2--;
-               }
-
              /* Saving a full library name.  */
               add_to_list (&libs, arg);
             }
@@ -1280,14 +1263,6 @@ main (argc, argv)
       scan_prog_file (list->name, PASS_FIRST);
   }
 
-  if (frame_tables.number > 0 && shared_obj)
-    {
-      /* If there are any frames, then we will need
-         the frame table handling functions.  */
-      add_to_list (&imports, "__register_frame_info_table");
-      add_to_list (&imports, "__deregister_frame_info");
-    }
-
   if (exports.first)
     {
       char *buf = xmalloc (strlen (export_file) + 5);
@@ -1303,23 +1278,6 @@ main (argc, argv)
       if (fclose (exportf))
        fatal_perror ("fclose %s", export_file);
     }
-
-  if (imports.first)
-    {
-      char *buf = xmalloc (strlen (import_file) + 5);
-
-      sprintf (buf, "-bI:%s", import_file);
-      *ld1++ = buf;
-      *ld2++ = buf;
-
-      importf = fopen (import_file, "w");
-      if (importf == (FILE *) 0)
-       fatal_perror ("%s", import_file);
-      fputs ("#! .\n", importf);
-      write_aix_file (importf, imports.first);
-      if (fclose (importf))
-       fatal_perror ("fclose %s", import_file);
-    }
 #endif
 
   *c_ptr++ = c_file;
@@ -1396,8 +1354,6 @@ main (argc, argv)
       /* But make sure we delete the export file we may have created.  */
       if (export_file != 0 && export_file[0])
        maybe_unlink (export_file);
-      if (import_file != 0 && import_file[0])
-       maybe_unlink (import_file);
 #endif
       maybe_unlink (c_file);
       maybe_unlink (o_file);
@@ -1452,7 +1408,6 @@ main (argc, argv)
 
 #ifdef COLLECT_EXPORT_LIST
       maybe_unlink (export_file);
-      maybe_unlink (import_file);
 #endif
       maybe_unlink (c_file);
       maybe_unlink (o_file);
@@ -1554,7 +1509,6 @@ main (argc, argv)
 
 #ifdef COLLECT_EXPORT_LIST
   maybe_unlink (export_file);
-  maybe_unlink (import_file);
 #endif
 
   return 0;
@@ -1884,7 +1838,7 @@ write_c_file_stat (stream, name)
   int frames = (frame_tables.number > 0);
 
   /* Figure out name of output_file, stripping off .so version.  */
-  p = rindex (output_file, '/');
+  p = strrchr (output_file, '/');
   if (p == 0)
     p = output_file;
   else
@@ -1892,7 +1846,7 @@ write_c_file_stat (stream, name)
   q = p;
   while (q)
     {
-      q = index (q,'.');
+      q = strchr (q,'.');
       if (q == 0)
        {
          q = p + strlen (p);
@@ -2746,10 +2700,6 @@ scan_prog_file (prog_name, which_pass)
   LDFILE *ldptr = NULL;
   int sym_index, sym_count;
   int is_shared = 0;
-#ifdef COLLECT_EXPORT_LIST
-  /* Should we generate an import list for given prog_name?  */
-  int import_flag = (which_pass == PASS_OBJ ? 0 : use_import_list (prog_name));
-#endif
 
   if (which_pass != PASS_FIRST && which_pass != PASS_OBJ)
     return;
@@ -2814,13 +2764,6 @@ scan_prog_file (prog_name, which_pass)
 #ifdef COLLECT_EXPORT_LIST
                          if (which_pass == PASS_OBJ)
                            add_to_list (&exports, name);
-                         /* If this symbol was undefined and we are building
-                            an import list, we should add a symbol to this
-                            list.  */
-                         else
-                           if (import_flag
-                               && is_in_list (name, undefined.first))
-                             add_to_list (&imports, name);
 #endif
                          break;
 
@@ -2830,13 +2773,6 @@ scan_prog_file (prog_name, which_pass)
 #ifdef COLLECT_EXPORT_LIST
                          if (which_pass == PASS_OBJ)
                            add_to_list (&exports, name);
-                         /* If this symbol was undefined and we are building
-                            an import list, we should add a symbol to this
-                            list.  */
-                         else
-                           if (import_flag
-                               && is_in_list (name, undefined.first))
-                             add_to_list (&imports, name);
 #endif
                          break;
 
@@ -2862,33 +2798,17 @@ scan_prog_file (prog_name, which_pass)
 #ifdef COLLECT_EXPORT_LIST
                          if (which_pass == PASS_OBJ)
                            add_to_list (&exports, name);
-                         /* If we are building an import list, we
-                            should add the symbol to the list.  
-                            We'd like to do it only if the symbol
-                            is not defined, but we can't tell
-                            that here (it is only known whether a symbol
-                            is referenced and not defined, but who
-                            would reference an EH table entry?).  */
-                         else
-                           if (import_flag)
-                             add_to_list (&imports, name);
 #endif
                          break;
 
                        default:        /* not a constructor or destructor */
 #ifdef COLLECT_EXPORT_LIST
                          /* If we are building a shared object on AIX we need
-                            to explicitly export all global symbols or add
-                            them to import list.  */
+                            to explicitly export all global symbols.  */
                          if (shared_obj) 
                            {
                              if (which_pass == PASS_OBJ && (! export_flag))
                                add_to_list (&exports, name);
-                             else if (! is_shared
-                                      && which_pass == PASS_FIRST
-                                      && import_flag
-                                      && is_in_list(name, undefined.first))
-                               add_to_list (&imports, name);
                            }
 #endif
                          continue;
@@ -2906,24 +2826,6 @@ scan_prog_file (prog_name, which_pass)
                                 symbol.iss, (long) symbol.value, symbol.index, name);
 #endif
                    }
-#ifdef COLLECT_EXPORT_LIST
-                 /* If we are building a shared object we should collect
-                    information about undefined symbols for later
-                    import list generation.  */
-                 else if (shared_obj && GCC_UNDEF_SYMBOL (symbol))
-                   {
-                     char *name;
-
-                     if ((name = ldgetname (ldptr, &symbol)) == NULL)
-                       continue;               /* should never happen */
-
-                     /* All AIX function names have a duplicate entry
-                        beginning with a dot.  */
-                     if (*name == '.')
-                       ++name;
-                     add_to_list (&undefined, name);
-                   }
-#endif
                }
            }
 #ifdef COLLECT_EXPORT_LIST
@@ -2953,25 +2855,6 @@ scan_prog_file (prog_name, which_pass)
 
 
 #ifdef COLLECT_EXPORT_LIST
-
-/* This new function is used to decide whether we should
-   generate import list for an object or to use it directly.  */
-static int
-use_import_list (prog_name)
-     const char *prog_name;
-{
-  char *p;
-
-  /* If we do not build a shared object then import list should not be used.  */
-  if (! shared_obj) return 0;
-
-  /* Currently we check only for libgcc, but this can be changed in future.  */
-  p = strstr (prog_name, "libgcc.a");
-  if (p != 0 && (strlen (p) == sizeof ("libgcc.a") - 1))
-    return 1;
-  return 0;
-}
-
 /* Given a library name without "lib" prefix, this function
    returns a full library name including a path.  */
 static char *
@@ -2992,14 +2875,14 @@ resolve_lib_name (name)
       struct prefix_list *list = libpaths[i]->plist;
       for (; list; list = list->next)
        {
+         /* The following lines are needed because path_prefix list
+            may contain directories both with trailing '/' and
+            without it.  */
+         const char *p = "";
+         if (list->prefix[strlen(list->prefix)-1] != '/')
+           p = "/";
          for (j = 0; libexts[j]; j++)
            {
-              /* The following lines are needed because path_prefix list
-                 may contain directories both with trailing '/' and
-                 without it.  */
-              const char *p = "";
-              if (list->prefix[strlen(list->prefix)-1] != '/')
-                p = "/";
                      sprintf (lib_buf, "%s%slib%s.%s",
                       list->prefix, p, name, libexts[j]);
 if (debug) fprintf (stderr, "searching for: %s\n", lib_buf);
@@ -3043,7 +2926,6 @@ ignore_library (name)
     if (! strcmp (name, *p)) return 1;
   return 0;
 }
-
 #endif
 
 #endif /* OBJECT_FORMAT_COFF */
@@ -3184,7 +3066,7 @@ scan_prog_file (prog_name, which_pass)
       if (rw)
        {
          load_union_t *ptr = (load_union_t *) xmalloc (load_hdr->hdr.ldci_cmd_size);
-         bcopy ((char *)load_hdr, (char *)ptr, load_hdr->hdr.ldci_cmd_size);
+         memcpy ((char *)ptr, (char *)load_hdr, load_hdr->hdr.ldci_cmd_size);
          load_hdr = ptr;
 
          /* null out old command map, because we will rewrite at the end.  */