OSDN Git Service

2001-05-03 David O'Brien <obrien@FreeBSD.org>
[pf3gnuchains/gcc-fork.git] / gcc / collect2.c
index 3f7cba4..83ed200 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, 2001 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).
@@ -28,6 +29,9 @@ Boston, MA 02111-1307, USA.  */
 #include "config.h"
 #include "system.h"
 #include <signal.h>
+#if ! defined( SIGCHLD ) && defined( SIGCLD )
+#  define SIGCHLD SIGCLD
+#endif
 
 #ifdef vfork /* Autoconf may define this to fork for us. */
 # define VFORK_STRING "fork"
@@ -52,6 +56,7 @@ Boston, MA 02111-1307, USA.  */
 #include "demangle.h"
 #include "obstack.h"
 #include "intl.h"
+#include "version.h"
 
 /* Obstack allocation and deallocation routines.  */
 #define obstack_chunk_alloc xmalloc
@@ -184,8 +189,6 @@ enum pass {
   PASS_SECOND                          /* with constructors linked in */
 };
 
-extern char *version_string;
-
 int vflag;                             /* true if -v */
 static int rflag;                      /* true if -r */
 static int strip_flag;                 /* true if -s */
@@ -202,7 +205,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.  */
@@ -218,8 +220,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 */
 
@@ -292,11 +292,13 @@ static void scan_prog_file        PARAMS ((const char *, enum pass));
 #ifdef SCAN_LIBRARIES
 static void scan_libraries     PARAMS ((const char *));
 #endif
+#if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
+static int is_in_args          PARAMS ((const char *, const char **, const char **));
+#endif
 #ifdef COLLECT_EXPORT_LIST
 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 **));
@@ -338,9 +340,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])
@@ -471,9 +470,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);
@@ -580,8 +576,10 @@ dump_file (name)
   fclose (stream);
 }
 \f
-/* Decide whether the given symbol is:
-   a constructor (1), a destructor (2), or neither (0).  */
+/* Decide whether the given symbol is: a constructor (1), a destructor
+   (2), a routine in a shared object that calls all the constructors
+   (3) or destructors (4), a DWARF exception-handling table (5), or
+   nothing special (0).  */
 
 static int
 is_ctor_dtor (s)
@@ -594,21 +592,9 @@ is_ctor_dtor (s)
   register const char *orig_s = s;
 
   static struct names special[] = {
-#ifdef NO_DOLLAR_IN_LABEL
-#ifdef NO_DOT_IN_LABEL
     { "GLOBAL__I_", sizeof ("GLOBAL__I_")-1, 1, 0 },
     { "GLOBAL__D_", sizeof ("GLOBAL__D_")-1, 2, 0 },
     { "GLOBAL__F_", sizeof ("GLOBAL__F_")-1, 5, 0 },
-#else
-    { "GLOBAL_.I.", sizeof ("GLOBAL_.I.")-1, 1, 0 },
-    { "GLOBAL_.D.", sizeof ("GLOBAL_.D.")-1, 2, 0 },
-    { "GLOBAL_.F.", sizeof ("GLOBAL_.F.")-1, 5, 0 },
-#endif
-#else
-    { "GLOBAL_$I$", sizeof ("GLOBAL_$I$")-1, 1, 0 },
-    { "GLOBAL_$D$", sizeof ("GLOBAL_$D$")-1, 2, 0 },
-    { "GLOBAL_$F$", sizeof ("GLOBAL_$F$")-1, 5, 0 },
-#endif
     { "GLOBAL__FI_", sizeof ("GLOBAL__FI_")-1, 3, 0 },
     { "GLOBAL__FD_", sizeof ("GLOBAL__FD_")-1, 4, 0 },
 #ifdef CFRONT_LOSSAGE /* Do not collect cfront initialization functions.
@@ -669,8 +655,8 @@ find_a_file (pprefix, name)
   if (debug)
     fprintf (stderr, "Looking for '%s'\n", name);
   
-#ifdef EXECUTABLE_SUFFIX
-  len += strlen (EXECUTABLE_SUFFIX);
+#ifdef HOST_EXECUTABLE_SUFFIX
+  len += strlen (HOST_EXECUTABLE_SUFFIX);
 #endif
 
   temp = xmalloc (len);
@@ -693,11 +679,11 @@ find_a_file (pprefix, name)
          return temp;
        }
 
-#ifdef EXECUTABLE_SUFFIX
+#ifdef HOST_EXECUTABLE_SUFFIX
        /* Some systems have a suffix for executable files.
           So try appending that.  */
       strcpy (temp, name);
-       strcat (temp, EXECUTABLE_SUFFIX);
+       strcat (temp, HOST_EXECUTABLE_SUFFIX);
        
        if (access (temp, X_OK) == 0)
          return temp;
@@ -719,10 +705,10 @@ find_a_file (pprefix, name)
            && access (temp, X_OK) == 0)
          return temp;
 
-#ifdef EXECUTABLE_SUFFIX
+#ifdef HOST_EXECUTABLE_SUFFIX
        /* Some systems have a suffix for executable files.
           So try appending that.  */
-       strcat (temp, EXECUTABLE_SUFFIX);
+       strcat (temp, HOST_EXECUTABLE_SUFFIX);
        
        if (stat (temp, &st) >= 0
            && ! S_ISDIR (st.st_mode)
@@ -858,7 +844,6 @@ main (argc, argv)
   FILE *outf;
 #ifdef COLLECT_EXPORT_LIST
   FILE *exportf;
-  FILE *importf;
 #endif
   const char *ld_file_name;
   const char *p;
@@ -874,13 +859,26 @@ 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
 
+#ifdef SIGCHLD
+  /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
+     receive the signal.  A different setting is inheritable */
+  signal (SIGCHLD, SIG_DFL);
+#endif
+
+/* LC_CTYPE determines the character set used by the terminal so it has be set
+   to output messages correctly.  */
+
 #ifdef HAVE_LC_MESSAGES
+  setlocale (LC_CTYPE, "");
   setlocale (LC_MESSAGES, "");
+#else
+  setlocale (LC_ALL, "");
 #endif
+
   (void) bindtextdomain (PACKAGE, localedir);
   (void) textdomain (PACKAGE);
 
@@ -917,7 +915,7 @@ main (argc, argv)
   obstack_begin (&permanent_obstack, 0);
   temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
 
-  current_demangling_style = gnu_demangling;
+  current_demangling_style = auto_demangling;
   p = getenv ("COLLECT_GCC_OPTIONS");
   while (p && *p)
     {
@@ -1071,7 +1069,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;
@@ -1105,6 +1102,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";
@@ -1163,14 +1169,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);
              }
@@ -1182,6 +1180,13 @@ main (argc, argv)
                    case 'L':
              add_prefix (&cmdline_lib_dirs, arg+2);
              break;
+#else 
+#if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
+           case 'L':
+             if (is_in_args (arg, (const char **) ld1_argv, ld1-1))
+               --ld1;
+             break;
+#endif /* LINK_ELIMINATE_DUPLICATE_LDIRECTORIES */
 #endif
 
            case 'o':
@@ -1189,7 +1194,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
                       )
 
@@ -1218,9 +1223,10 @@ 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
+                  || strcmp (p, ".obj") == 0))
        {
          if (first_file)
            {
@@ -1235,20 +1241,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);
             }
@@ -1281,9 +1279,8 @@ main (argc, argv)
 
   if (exports.first)
     {
-      char *buf = xmalloc (strlen (export_file) + 5);
-
-      sprintf (buf, "-bE:%s", export_file);
+      char *buf = concat ("-bE:", export_file, NULL);
+      
       *ld1++ = buf;
       *ld2++ = buf;
 
@@ -1294,23 +1291,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;
@@ -1387,8 +1367,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);
@@ -1443,7 +1421,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);
@@ -1467,13 +1444,7 @@ main (argc, argv)
   /* Tell the linker that we have initializer and finalizer functions.  */
 #ifdef LD_INIT_SWITCH
 #ifdef COLLECT_EXPORT_LIST
-  {
-    /* option name + functions + colons + NULL */
-    char *buf = xmalloc (strlen (LD_INIT_SWITCH)
-                        + strlen(initname) + strlen(fininame) + 3);
-    sprintf (buf, "%s:%s:%s", LD_INIT_SWITCH, initname, fininame);
-    *ld2++ = buf;
-  }
+  *ld2++ = concat (LD_INIT_SWITCH, ":", initname, ":", fininame, NULL);
 #else
   *ld2++ = LD_INIT_SWITCH;
   *ld2++ = initname;
@@ -1488,12 +1459,7 @@ main (argc, argv)
       /* If we did not add export flag to link arguments before, add it to
         second link phase now.  No new exports should have been added.  */
       if (! exports.first)
-       {
-         char *buf = xmalloc (strlen (export_file) + 5);
-
-         sprintf (buf, "-bE:%s", export_file);
-         *ld2++ = buf;
-       }
+       *ld2++ = concat ("-bE:", export_file, NULL);
 
       add_to_list (&exports, initname);
       add_to_list (&exports, fininame);
@@ -1545,7 +1511,6 @@ main (argc, argv)
 
 #ifdef COLLECT_EXPORT_LIST
   maybe_unlink (export_file);
-  maybe_unlink (import_file);
 #endif
 
   return 0;
@@ -1801,6 +1766,24 @@ write_list (stream, prefix, list)
     }
 }
 
+#if LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
+/* Given a STRING, return nonzero if it occurs in the list in range
+   [ARGS_BEGIN,ARGS_END).  */
+
+static int
+is_in_args (string, args_begin, args_end)
+     const char *string;
+     const char **args_begin;
+     const char **args_end;
+{
+  const char **args_pointer;
+  for (args_pointer = args_begin; args_pointer != args_end; ++args_pointer)
+    if (strcmp (string, *args_pointer) == 0)
+      return 1;
+  return 0;
+}
+#endif /* LINK_ELIMINATE_DUPLICATE_LDIRECTORIES */
+
 #ifdef COLLECT_EXPORT_LIST
 /* This function is really used only on AIX, but may be useful.  */
 static int
@@ -1875,7 +1858,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
@@ -1883,7 +1866,7 @@ write_c_file_stat (stream, name)
   q = p;
   while (q)
     {
-      q = index (q,'.');
+      q = strchr (q,'.');
       if (q == 0)
        {
          q = p + strlen (p);
@@ -1911,13 +1894,8 @@ write_c_file_stat (stream, name)
     notice ("\nwrite_c_file - output name is %s, prefix is %s\n",
            output_file, prefix);
 
-#define INIT_NAME_FORMAT "_GLOBAL__FI_%s"
-  initname = xmalloc (strlen (prefix) + sizeof (INIT_NAME_FORMAT) - 2);
-  sprintf (initname, INIT_NAME_FORMAT, prefix);
-
-#define FINI_NAME_FORMAT "_GLOBAL__FD_%s"
-  fininame = xmalloc (strlen (prefix) + sizeof (FINI_NAME_FORMAT) - 2);
-  sprintf (fininame, FINI_NAME_FORMAT, prefix);
+  initname = concat ("_GLOBAL__FI_", prefix, NULL);
+  fininame = concat ("_GLOBAL__FD_", prefix, NULL);
 
   free (prefix);
 
@@ -2635,7 +2613,7 @@ scan_libraries (prog_name)
   /* Read each line of ldd output.  */
   while (fgets (buf, sizeof buf, inf) != (char *) 0)
     {
-      int ch, ch2;
+      int ch2;
       char *name, *end, *p = buf;
 
       /* Extract names of libraries and add to list.  */
@@ -2694,13 +2672,16 @@ scan_libraries (prog_name)
 #ifdef OBJECT_FORMAT_COFF
 
 #if defined(EXTENDED_COFF)
+
 #   define GCC_SYMBOLS(X)      (SYMHEADER(X).isymMax + SYMHEADER(X).iextMax)
 #   define GCC_SYMENT          SYMR
 #   define GCC_OK_SYMBOL(X)    ((X).st == stProc || (X).st == stGlobal)
 #   define GCC_SYMINC(X)       (1)
 #   define GCC_SYMZERO(X)      (SYMHEADER(X).isymMax)
 #   define GCC_CHECK_HDR(X)    (PSYMTAB(X) != 0)
+
 #else
+
 #   define GCC_SYMBOLS(X)      (HEADER(ldptr).f_nsyms)
 #   define GCC_SYMENT          SYMENT
 #   define GCC_OK_SYMBOL(X) \
@@ -2713,11 +2694,20 @@ scan_libraries (prog_name)
      (((X).n_sclass == C_EXT) && ((X).n_scnum == N_UNDEF))
 #   define GCC_SYMINC(X)       ((X).n_numaux+1)
 #   define GCC_SYMZERO(X)      0
+
+/* 0757 = U803XTOCMAGIC (AIX 4.3) and 0767 = U64_TOCMAGIC (AIX V5) */
+#ifdef _AIX51
+#   define GCC_CHECK_HDR(X) \
+     ((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \
+      || (HEADER (X).f_magic == 0767 && aix64_flag))
+#else
 #   define GCC_CHECK_HDR(X) \
      ((HEADER (X).f_magic == U802TOCMAGIC && ! aix64_flag) \
       || (HEADER (X).f_magic == 0757 && aix64_flag))
 #endif
 
+#endif
+
 extern char *ldgetname ();
 
 /* COFF version to scan the name list of the loaded program for
@@ -2737,10 +2727,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;
@@ -2805,13 +2791,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;
 
@@ -2821,13 +2800,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;
 
@@ -2850,22 +2822,20 @@ scan_prog_file (prog_name, which_pass)
                        case 5:
                          if (! is_shared)
                            add_to_list (&frame_tables, name);
+#ifdef COLLECT_EXPORT_LIST
+                         if (which_pass == PASS_OBJ)
+                           add_to_list (&exports, 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;
@@ -2883,24 +2853,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
@@ -2930,25 +2882,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 *
@@ -2969,14 +2902,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);
@@ -3000,12 +2933,18 @@ if (debug) fprintf (stderr, "found: %s\n", lib_buf);
 static const char *aix_std_libs[] = {
   "/unix",
   "/lib/libc.a",
+  "/lib/libm.a",
   "/lib/libc_r.a",
+  "/lib/libm_r.a",
   "/usr/lib/libc.a",
+  "/usr/lib/libm.a",
   "/usr/lib/libc_r.a",
+  "/usr/lib/libm_r.a",
   "/usr/lib/threads/libc.a",
   "/usr/ccs/lib/libc.a",
+  "/usr/ccs/lib/libm.a",
   "/usr/ccs/lib/libc_r.a",
+  "/usr/ccs/lib/libm_r.a",
   NULL
 };
 
@@ -3020,7 +2959,6 @@ ignore_library (name)
     if (! strcmp (name, *p)) return 1;
   return 0;
 }
-
 #endif
 
 #endif /* OBJECT_FORMAT_COFF */
@@ -3161,7 +3099,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.  */