OSDN Git Service

2014-05-07 Richard Biener <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / gcc-ar.c
index fc7e4a2..5f78378 100644 (file)
@@ -1,5 +1,5 @@
 /* Wrapper for ar/ranlib/nm to pass the LTO plugin.
-   Copyright (C) 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011, 2012 Free Software Foundation, Inc.
    Contributed by Andi Kleen.
 
 This file is part of GCC.
@@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-#include <stdio.h>
 #include "config.h"
 #include "system.h"
 #include "libiberty.h"
@@ -29,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 
 static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
 static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
+static const char *const target_machine = TARGET_MACHINE;
 
 static const char dir_separator[] = { DIR_SEPARATOR, 0 };
 
@@ -42,6 +42,7 @@ main(int ac, char **av)
   const char *err_msg;
   const char **nargv;
   bool is_ar = !strcmp (PERSONALITY, "ar");
+  int exit_code = FATAL_EXIT_CODE;
 
   exe_name = PERSONALITY;
 #ifdef CROSS_DIRECTORY_STRUCTURE
@@ -52,11 +53,16 @@ main(int ac, char **av)
   /* XXX implement more magic from gcc.c? */
   nprefix = getenv ("GCC_EXEC_PREFIX");
   if (!nprefix)
+    nprefix = av[0];
+  else
+    nprefix = concat (nprefix, "gcc-" PERSONALITY, NULL);
+
+  nprefix = make_relative_prefix (nprefix,
+                                 standard_bin_prefix,
+                                 standard_libexec_prefix);
+  if (nprefix == NULL)
     nprefix = standard_libexec_prefix;
 
-  nprefix = make_relative_prefix (av[0], 
-                                 standard_bin_prefix, 
-                                 nprefix);
   plugin = concat (nprefix,
                   dir_separator,
                    DEFAULT_TARGET_MACHINE, 
@@ -65,7 +71,7 @@ main(int ac, char **av)
                   dir_separator,
                   LTOPLUGINSONAME,
                   NULL);
-  if (access (plugin, X_OK))
+  if (access (plugin, R_OK))
     {
       fprintf (stderr, "%s: Cannot find plugin %s\n", av[0], plugin);
       exit (1);
@@ -91,6 +97,20 @@ main(int ac, char **av)
                     NULL,NULL,  &status, &err);
   if (err_msg) 
     fprintf(stderr, "Error running %s: %s\n", exe_name, err_msg);
+  else if (status)
+    {
+      if (WIFSIGNALED (status))
+       {
+         int sig = WTERMSIG (status);
+         fprintf (stderr, "%s terminated with signal %d [%s]%s\n",
+                  exe_name, sig, strsignal(sig),
+                  WCOREDUMP(status) ? ", core dumped" : "");
+       }
+      else if (WIFEXITED (status))
+       exit_code = WEXITSTATUS (status);
+    }
+  else
+    exit_code = SUCCESS_EXIT_CODE;
 
-  return err;
+  return exit_code;
 }