aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc-ar.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2011-10-29 00:10:36 +0000
committerAndi Kleen <ak@gcc.gnu.org>2011-10-29 00:10:36 +0000
commitb6b892151587d3e270566a5a67d7688bb8fe055d (patch)
tree8c32f7bc56485636cece052310c0804fb09db95a /gcc/gcc-ar.c
parentd6b0f0f14f2e90a368476bf6b90820ed9ea09ec8 (diff)
downloadgcc-b6b892151587d3e270566a5a67d7688bb8fe055d.zip
gcc-b6b892151587d3e270566a5a67d7688bb8fe055d.tar.gz
gcc-b6b892151587d3e270566a5a67d7688bb8fe055d.tar.bz2
Add gcc-ar/nm/ranlib wrappers for slim LTO v2
gcc/: 2011-10-19 Andi Kleen <ak@linux.intel.com> * Makefile.in (MOSTLYCLEANFILES): Add gcc-ar/nm/ranlib. (native): Add gcc-ar, gcc-nm, gcc-ranlib. (AR_LIBS, gcc-ar, gcc-ar.o, gcc-ranlib, gcc-ranlib.o, gcc-nm, gcc-nm.o, gcc-ranlib.c, gcc-nm.c): Add. (install): Depend on install-gcc-ar. (install-gcc-ar): Add. (uninstall): Uninstall gcc-ar, gcc-nm, gcc-ranlib. * gcc-ar.c: Add new file. From-SVN: r180642
Diffstat (limited to 'gcc/gcc-ar.c')
-rw-r--r--gcc/gcc-ar.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
new file mode 100644
index 0000000..fc7e4a2
--- /dev/null
+++ b/gcc/gcc-ar.c
@@ -0,0 +1,96 @@
+/* Wrapper for ar/ranlib/nm to pass the LTO plugin.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+ Contributed by Andi Kleen.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+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"
+
+#ifndef PERSONALITY
+#error "Please set personality"
+#endif
+
+static const char standard_libexec_prefix[] = STANDARD_LIBEXEC_PREFIX;
+static const char standard_bin_prefix[] = STANDARD_BINDIR_PREFIX;
+
+static const char dir_separator[] = { DIR_SEPARATOR, 0 };
+
+int
+main(int ac, char **av)
+{
+ const char *nprefix;
+ const char *exe_name;
+ char *plugin;
+ int k, status, err;
+ const char *err_msg;
+ const char **nargv;
+ bool is_ar = !strcmp (PERSONALITY, "ar");
+
+ exe_name = PERSONALITY;
+#ifdef CROSS_DIRECTORY_STRUCTURE
+ exe_name = concat (target_machine, "-", exe_name, NULL);
+#endif
+
+ /* Find plugin */
+ /* XXX implement more magic from gcc.c? */
+ nprefix = getenv ("GCC_EXEC_PREFIX");
+ if (!nprefix)
+ nprefix = standard_libexec_prefix;
+
+ nprefix = make_relative_prefix (av[0],
+ standard_bin_prefix,
+ nprefix);
+ plugin = concat (nprefix,
+ dir_separator,
+ DEFAULT_TARGET_MACHINE,
+ dir_separator,
+ DEFAULT_TARGET_VERSION,
+ dir_separator,
+ LTOPLUGINSONAME,
+ NULL);
+ if (access (plugin, X_OK))
+ {
+ fprintf (stderr, "%s: Cannot find plugin %s\n", av[0], plugin);
+ exit (1);
+ }
+
+ /* Create new command line with plugin */
+ nargv = XCNEWVEC (const char *, ac + 4);
+ nargv[0] = exe_name;
+ nargv[1] = "--plugin";
+ nargv[2] = plugin;
+ if (is_ar && av[1] && av[1][0] != '-')
+ av[1] = concat("-", av[1], NULL);
+ for (k = 1; k < ac; k++)
+ nargv[2 + k] = av[k];
+ nargv[2 + k] = NULL;
+
+ /* Run utility */
+ /* ??? the const is misplaced in pex_one's argv? */
+ err_msg = pex_one (PEX_LAST|PEX_SEARCH,
+ exe_name,
+ CONST_CAST2 (char * const *, const char **, nargv),
+ concat("gcc-", exe_name, NULL),
+ NULL,NULL, &status, &err);
+ if (err_msg)
+ fprintf(stderr, "Error running %s: %s\n", exe_name, err_msg);
+
+ return err;
+}