public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 2/2] Support slim LTO bootstrap
  2014-08-04 14:30 ` [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm Andi Kleen
@ 2014-08-04 14:30   ` Andi Kleen
  0 siblings, 0 replies; 7+ messages in thread
From: Andi Kleen @ 2014-08-04 14:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

Add a new bootstrap-lto-slim config file that enables slim (non-fat) LTO
bootstrap. This improves the performance of the LTO bootstrap.

Speeds up the LTO bootstrap by ~18% on a 4 core system.

This requires using gcc-ar/ranlib in post stage 1 builds, so these
are passed to all sub builds.

I made it a new config file for now because it requires the host to support
linker plugins, which I believe is not supported everywhere yet?

config/:

2014-08-04  Andi Kleen  <ak@linux.intel.com>

	* bootstrap-lto-slim.mk: New file.

/:

2014-08-04  Andi Kleen  <ak@linux.intel.com>

	* Makefile.tpl (POSTSTAGE1_HOST_EXPORTS): Add LTO_EXPORTS.
	POSTSTAGE1_FLAGS_TO_PASS):  Add LTO_FLAGS_TO_PASS.
	* Makefile.in: Regenerate.

gcc/:

2014-08-04  Andi Kleen  <ak@linux.intel.com>

	* doc/install.texi: Documentation bootstrap-lto-slim
---
 Makefile.in                  |  2 ++
 Makefile.tpl                 |  2 ++
 config/bootstrap-lto-slim.mk | 13 +++++++++++++
 gcc/doc/install.texi         |  5 +++++
 4 files changed, 22 insertions(+)
 create mode 100644 config/bootstrap-lto-slim.mk

diff --git a/Makefile.in b/Makefile.in
index 329af7f..af59823 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -256,6 +256,7 @@ POSTSTAGE1_HOST_EXPORTS = \
 	  $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CC; \
 	CC_FOR_BUILD="$$CC"; export CC_FOR_BUILD; \
 	$(POSTSTAGE1_CXX_EXPORT) \
+	$(LTO_EXPORTS) \
 	GNATBIND="$$r/$(HOST_SUBDIR)/prev-gcc/gnatbind"; export GNATBIND; \
 	LDFLAGS="$(POSTSTAGE1_LDFLAGS) $(BOOT_LDFLAGS)"; export LDFLAGS; \
 	HOST_LIBS="$(POSTSTAGE1_LIBS)"; export HOST_LIBS;
@@ -826,6 +827,7 @@ POSTSTAGE1_FLAGS_TO_PASS = \
 	GNATBIND="$${GNATBIND}" \
 	LDFLAGS="$${LDFLAGS}" \
 	HOST_LIBS="$${HOST_LIBS}" \
+	$(LTO_FLAGS_TO_PASS) \
 	"`echo 'ADAFLAGS=$(BOOT_ADAFLAGS)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`"
 
 # Flags to pass down to makes which are built with the target environment.
diff --git a/Makefile.tpl b/Makefile.tpl
index 4822c32..261461a 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -259,6 +259,7 @@ POSTSTAGE1_HOST_EXPORTS = \
 	  $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CC; \
 	CC_FOR_BUILD="$$CC"; export CC_FOR_BUILD; \
 	$(POSTSTAGE1_CXX_EXPORT) \
+	$(LTO_EXPORTS) \
 	GNATBIND="$$r/$(HOST_SUBDIR)/prev-gcc/gnatbind"; export GNATBIND; \
 	LDFLAGS="$(POSTSTAGE1_LDFLAGS) $(BOOT_LDFLAGS)"; export LDFLAGS; \
 	HOST_LIBS="$(POSTSTAGE1_LIBS)"; export HOST_LIBS;
@@ -631,6 +632,7 @@ POSTSTAGE1_FLAGS_TO_PASS = \
 	GNATBIND="$${GNATBIND}" \
 	LDFLAGS="$${LDFLAGS}" \
 	HOST_LIBS="$${HOST_LIBS}" \
+	$(LTO_FLAGS_TO_PASS) \
 	"`echo 'ADAFLAGS=$(BOOT_ADAFLAGS)' | sed -e s'/[^=][^=]*=$$/XFOO=/'`"
 
 # Flags to pass down to makes which are built with the target environment.
diff --git a/config/bootstrap-lto-slim.mk b/config/bootstrap-lto-slim.mk
new file mode 100644
index 0000000..9e065e1
--- /dev/null
+++ b/config/bootstrap-lto-slim.mk
@@ -0,0 +1,13 @@
+# This option enables LTO for stage2 and stage3 in slim mode
+
+STAGE2_CFLAGS += -flto=jobserver -frandom-seed=1
+STAGE3_CFLAGS += -flto=jobserver -frandom-seed=1
+STAGEprofile_CFLAGS += -fno-lto
+
+# assumes the host supports the linker plugin
+LTO_AR = $$r/$(HOST_SUBDIR)/prev-gcc/gcc-ar$(exeext) -B$$r/$(HOST_SUBDIR)/prev-gcc/
+LTO_RANLIB = $$r/$(HOST_SUBDIR)/prev-gcc/gcc-ranlib$(exeext) -B$$r/$(HOST_SUBDIR)/prev-gcc/
+
+LTO_EXPORTS = AR="$(LTO_AR)"; export AR; \
+	      RANLIB="$(LTO_RANLIB)"; export RANLIB;
+LTO_FLAGS_TO_PASS = AR="$(LTO_AR)" RANLIB="$(LTO_RANLIB)"
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 31b8c8b..cac2915 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -2377,6 +2377,11 @@ Enables Link-Time Optimization for host tools during bootstrapping.
 @samp{BUILD_CONFIG=bootstrap-lto} is equivalent to adding
 @option{-flto} to @samp{BOOT_CFLAGS}.
 
+@item @samp{bootstrap-lto-slim}
+Enable slim Link-Time-Optimization for host tools during bootstrapping.
+This is a faster version of @code{bootstrap-lto}, but requires
+the host to support the linker plugin.
+
 @item @samp{bootstrap-debug}
 Verifies that the compiler generates the same executable code, whether
 or not it is asked to emit debug information.  To this end, this
-- 
2.0.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Implement slim LTO bootstrap
@ 2014-08-04 14:30 Andi Kleen
  2014-08-04 14:30 ` [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm Andi Kleen
  0 siblings, 1 reply; 7+ messages in thread
From: Andi Kleen @ 2014-08-04 14:30 UTC (permalink / raw)
  To: gcc-patches

This patchkit implements slim LTO bootstrap to speed up LTO
bootstrap by ~18%. Passes LTO and normal bootstrap on x86_64-linux.
Ok?

-Andi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm
  2014-08-04 14:30 Implement slim LTO bootstrap Andi Kleen
@ 2014-08-04 14:30 ` Andi Kleen
  2014-08-04 14:30   ` [PATCH 2/2] Support slim LTO bootstrap Andi Kleen
  0 siblings, 1 reply; 7+ messages in thread
From: Andi Kleen @ 2014-08-04 14:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

To use gcc-{ar,ranlib} for boot strap we need to add a -B option
to the tool. Since ar has weird and unusual argument conventions
implement the code by hand instead of using any libraries.

gcc/:

2014-08-04  Andi Kleen  <ak@linux.intel.com>

	* gcc-ar.c (main): Support -B option.
---
 gcc/gcc-ar.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
index aebaa92..372e087 100644
--- a/gcc/gcc-ar.c
+++ b/gcc/gcc-ar.c
@@ -132,9 +132,50 @@ main (int ac, char **av)
   const char **nargv;
   bool is_ar = !strcmp (PERSONALITY, "ar");
   int exit_code = FATAL_EXIT_CODE;
+  int i;
 
   setup_prefixes (av[0]);
 
+  /* Not using getopt for now.  */
+  for (i = 0; i < ac; i++)
+      if (!strncmp (av[i], "-B", 2))
+	{
+	  const char *arg = av[i] + 2;
+	  const char *end;
+
+	  memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	  ac--;
+	  if (*arg == 0)
+	    {
+	      arg = av[i] + 1;
+	      if (!arg)
+		{
+		  fprintf (stderr, "Usage: gcc-ar [-B prefix] ar arguments ...\n");
+		  exit (EXIT_FAILURE);
+		}
+	      memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	      ac--;
+	      i++;
+	    }
+
+	  for (end = arg; *end; end++)
+	    ;
+	  end--;
+	  if (end > arg && *end != '/')
+	    {
+	      char *newarg = (char *)xmalloc (strlen(arg) + 2);
+
+	      strcpy (newarg, arg);
+	      strcat (newarg, "/");
+	      arg = newarg;
+	    }
+
+	  add_prefix (&path, arg);
+	  add_prefix (&target_path, arg);
+	  break;
+	}
+
+
   /* Find the GCC LTO plugin */
   plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK);
   if (!plugin)
-- 
2.0.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm
  2014-09-01 11:34   ` Richard Biener
@ 2014-09-01 16:33     ` Andi Kleen
  0 siblings, 0 replies; 7+ messages in thread
From: Andi Kleen @ 2014-09-01 16:33 UTC (permalink / raw)
  To: Richard Biener; +Cc: Andi Kleen, GCC Patches, Andi Kleen

On Mon, Sep 01, 2014 at 01:34:17PM +0200, Richard Biener wrote:
> On Sun, Aug 31, 2014 at 4:51 PM, Andi Kleen <andi@firstfloor.org> wrote:
> > From: Andi Kleen <ak@linux.intel.com>
> >
> > To use gcc-{ar,ranlib} for boot strap we need to add a -B option
> > to the tool. Since ar has weird and unusual argument conventions
> > implement the code by hand instead of using any libraries.
> >
> > v2: Fix typo
> > v3: Improve comments. Use strlen. Use DIR_SEPARATOR. Add prefixes at
> > begin.
> 
> Ok.

Michael Chamberlain pointed out an argument parsing bug privately.
I'm going to commit this v4 version which has a one-liner fix for it,
after it passed rebootstrap.

-Andi

diff --git a/gcc/file-find.c b/gcc/file-find.c
index 87d486d..be608b2 100644
--- a/gcc/file-find.c
+++ b/gcc/file-find.c
@@ -105,15 +105,16 @@ find_a_file (struct path_prefix *pprefix, const char *name, int mode)
   return 0;
 }
 
-/* Add an entry for PREFIX to prefix list PPREFIX.  */
+/* Add an entry for PREFIX to prefix list PREFIX.
+   Add at beginning if FIRST is true.  */
 
 void
-add_prefix (struct path_prefix *pprefix, const char *prefix)
+do_add_prefix (struct path_prefix *pprefix, const char *prefix, bool first)
 {
   struct prefix_list *pl, **prev;
   int len;
 
-  if (pprefix->plist)
+  if (pprefix->plist && !first)
     {
       for (pl = pprefix->plist; pl->next; pl = pl->next)
 	;
@@ -138,6 +139,22 @@ add_prefix (struct path_prefix *pprefix, const char *prefix)
   *prev = pl;
 }
 
+/* Add an entry for PREFIX at the end of prefix list PREFIX.  */
+
+void
+add_prefix (struct path_prefix *pprefix, const char *prefix)
+{
+  do_add_prefix (pprefix, prefix, false);
+}
+
+/* Add an entry for PREFIX at the begin of prefix list PREFIX.  */
+
+void
+add_prefix_begin (struct path_prefix *pprefix, const char *prefix)
+{
+  do_add_prefix (pprefix, prefix, true);
+}
+
 /* Take the value of the environment variable ENV, break it into a path, and
    add of the entries to PPREFIX.  */
 
diff --git a/gcc/file-find.h b/gcc/file-find.h
index b438056..0754d99 100644
--- a/gcc/file-find.h
+++ b/gcc/file-find.h
@@ -40,6 +40,7 @@ struct path_prefix
 extern void find_file_set_debug (bool);
 extern char *find_a_file (struct path_prefix *, const char *, int);
 extern void add_prefix (struct path_prefix *, const char *);
+extern void add_prefix_begin (struct path_prefix *, const char *);
 extern void prefix_from_env (const char *, struct path_prefix *);
 extern void prefix_from_string (const char *, struct path_prefix *);
 
diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
index aebaa92..fdff89c 100644
--- a/gcc/gcc-ar.c
+++ b/gcc/gcc-ar.c
@@ -132,9 +132,52 @@ main (int ac, char **av)
   const char **nargv;
   bool is_ar = !strcmp (PERSONALITY, "ar");
   int exit_code = FATAL_EXIT_CODE;
+  int i;
 
   setup_prefixes (av[0]);
 
+  /* Not using getopt for now.  */
+  for (i = 0; i < ac; i++)
+      if (!strncmp (av[i], "-B", 2))
+	{
+	  const char *arg = av[i] + 2;
+	  const char *end;
+	  size_t len;
+
+	  memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	  ac--;
+	  if (*arg == 0)
+	    {
+	      arg = av[i];
+	      if (!arg)
+		{
+		  fprintf (stderr, "Usage: gcc-ar [-B prefix] ar arguments ...\n");
+		  exit (EXIT_FAILURE);
+		}
+	      memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	      ac--;
+	      i++;
+	    }
+	  /* else it's a joined argument  */
+
+	  len = strlen (arg);
+	  if (len > 0)
+		  len--;
+	  end = arg + len;
+
+	  /* Always add a dir separator for the prefix list.  */
+	  if (end > arg && !IS_DIR_SEPARATOR (*end))
+	    {
+	      static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
+	      arg = concat (arg, dir_separator_str, NULL);
+	    }
+
+	  add_prefix_begin (&path, arg);
+	  add_prefix_begin (&target_path, arg);
+	  break;
+	}
+
+
   /* Find the GCC LTO plugin */
   plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK);
   if (!plugin)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm
  2014-08-31 14:52 ` [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm Andi Kleen
@ 2014-09-01 11:34   ` Richard Biener
  2014-09-01 16:33     ` Andi Kleen
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Biener @ 2014-09-01 11:34 UTC (permalink / raw)
  To: Andi Kleen; +Cc: GCC Patches, Andi Kleen

On Sun, Aug 31, 2014 at 4:51 PM, Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> To use gcc-{ar,ranlib} for boot strap we need to add a -B option
> to the tool. Since ar has weird and unusual argument conventions
> implement the code by hand instead of using any libraries.
>
> v2: Fix typo
> v3: Improve comments. Use strlen. Use DIR_SEPARATOR. Add prefixes at
> begin.

Ok.

Thanks,
Richard.

> gcc/:
>
> 2014-08-31  Andi Kleen  <ak@linux.intel.com>
>
>         * file-find.c (add_prefix_begin): Add.
>         (do_add_prefix): Rename from add_prefix with first argument.
>         (add_prefix): Add new wrapper.
>         * file-find.h (add_prefix_begin): Add.
>         * gcc-ar.c (main): Support -B option.
> ---
>  gcc/file-find.c | 23 ++++++++++++++++++++---
>  gcc/file-find.h |  1 +
>  gcc/gcc-ar.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 64 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/file-find.c b/gcc/file-find.c
> index 87d486d..be608b2 100644
> --- a/gcc/file-find.c
> +++ b/gcc/file-find.c
> @@ -105,15 +105,16 @@ find_a_file (struct path_prefix *pprefix, const char *name, int mode)
>    return 0;
>  }
>
> -/* Add an entry for PREFIX to prefix list PPREFIX.  */
> +/* Add an entry for PREFIX to prefix list PREFIX.
> +   Add at beginning if FIRST is true.  */
>
>  void
> -add_prefix (struct path_prefix *pprefix, const char *prefix)
> +do_add_prefix (struct path_prefix *pprefix, const char *prefix, bool first)
>  {
>    struct prefix_list *pl, **prev;
>    int len;
>
> -  if (pprefix->plist)
> +  if (pprefix->plist && !first)
>      {
>        for (pl = pprefix->plist; pl->next; pl = pl->next)
>         ;
> @@ -138,6 +139,22 @@ add_prefix (struct path_prefix *pprefix, const char *prefix)
>    *prev = pl;
>  }
>
> +/* Add an entry for PREFIX at the end of prefix list PREFIX.  */
> +
> +void
> +add_prefix (struct path_prefix *pprefix, const char *prefix)
> +{
> +  do_add_prefix (pprefix, prefix, false);
> +}
> +
> +/* Add an entry for PREFIX at the begin of prefix list PREFIX.  */
> +
> +void
> +add_prefix_begin (struct path_prefix *pprefix, const char *prefix)
> +{
> +  do_add_prefix (pprefix, prefix, true);
> +}
> +
>  /* Take the value of the environment variable ENV, break it into a path, and
>     add of the entries to PPREFIX.  */
>
> diff --git a/gcc/file-find.h b/gcc/file-find.h
> index b438056..0754d99 100644
> --- a/gcc/file-find.h
> +++ b/gcc/file-find.h
> @@ -40,6 +40,7 @@ struct path_prefix
>  extern void find_file_set_debug (bool);
>  extern char *find_a_file (struct path_prefix *, const char *, int);
>  extern void add_prefix (struct path_prefix *, const char *);
> +extern void add_prefix_begin (struct path_prefix *, const char *);
>  extern void prefix_from_env (const char *, struct path_prefix *);
>  extern void prefix_from_string (const char *, struct path_prefix *);
>
> diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
> index aebaa92..b5199e6 100644
> --- a/gcc/gcc-ar.c
> +++ b/gcc/gcc-ar.c
> @@ -132,9 +132,52 @@ main (int ac, char **av)
>    const char **nargv;
>    bool is_ar = !strcmp (PERSONALITY, "ar");
>    int exit_code = FATAL_EXIT_CODE;
> +  int i;
>
>    setup_prefixes (av[0]);
>
> +  /* Not using getopt for now.  */
> +  for (i = 0; i < ac; i++)
> +      if (!strncmp (av[i], "-B", 2))
> +       {
> +         const char *arg = av[i] + 2;
> +         const char *end;
> +         size_t len;
> +
> +         memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
> +         ac--;
> +         if (*arg == 0)
> +           {
> +             arg = av[i + 1];
> +             if (!arg)
> +               {
> +                 fprintf (stderr, "Usage: gcc-ar [-B prefix] ar arguments ...\n");
> +                 exit (EXIT_FAILURE);
> +               }
> +             memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
> +             ac--;
> +             i++;
> +           }
> +         /* else it's a joined argument  */
> +
> +         len = strlen (arg);
> +         if (len > 0)
> +                 len--;
> +         end = arg + len;
> +
> +         /* Always add a dir separator for the prefix list.  */
> +         if (end > arg && !IS_DIR_SEPARATOR (*end))
> +           {
> +             static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
> +             arg = concat (arg, dir_separator_str, NULL);
> +           }
> +
> +         add_prefix_begin (&path, arg);
> +         add_prefix_begin (&target_path, arg);
> +         break;
> +       }
> +
> +
>    /* Find the GCC LTO plugin */
>    plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK);
>    if (!plugin)
> --
> 2.0.4
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm
  2014-08-31 14:52 Updated slim LTO patchkit Andi Kleen
@ 2014-08-31 14:52 ` Andi Kleen
  2014-09-01 11:34   ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Andi Kleen @ 2014-08-31 14:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

To use gcc-{ar,ranlib} for boot strap we need to add a -B option
to the tool. Since ar has weird and unusual argument conventions
implement the code by hand instead of using any libraries.

v2: Fix typo
v3: Improve comments. Use strlen. Use DIR_SEPARATOR. Add prefixes at
begin.

gcc/:

2014-08-31  Andi Kleen  <ak@linux.intel.com>

	* file-find.c (add_prefix_begin): Add.
	(do_add_prefix): Rename from add_prefix with first argument.
	(add_prefix): Add new wrapper.
	* file-find.h (add_prefix_begin): Add.
	* gcc-ar.c (main): Support -B option.
---
 gcc/file-find.c | 23 ++++++++++++++++++++---
 gcc/file-find.h |  1 +
 gcc/gcc-ar.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/gcc/file-find.c b/gcc/file-find.c
index 87d486d..be608b2 100644
--- a/gcc/file-find.c
+++ b/gcc/file-find.c
@@ -105,15 +105,16 @@ find_a_file (struct path_prefix *pprefix, const char *name, int mode)
   return 0;
 }
 
-/* Add an entry for PREFIX to prefix list PPREFIX.  */
+/* Add an entry for PREFIX to prefix list PREFIX.
+   Add at beginning if FIRST is true.  */
 
 void
-add_prefix (struct path_prefix *pprefix, const char *prefix)
+do_add_prefix (struct path_prefix *pprefix, const char *prefix, bool first)
 {
   struct prefix_list *pl, **prev;
   int len;
 
-  if (pprefix->plist)
+  if (pprefix->plist && !first)
     {
       for (pl = pprefix->plist; pl->next; pl = pl->next)
 	;
@@ -138,6 +139,22 @@ add_prefix (struct path_prefix *pprefix, const char *prefix)
   *prev = pl;
 }
 
+/* Add an entry for PREFIX at the end of prefix list PREFIX.  */
+
+void
+add_prefix (struct path_prefix *pprefix, const char *prefix)
+{
+  do_add_prefix (pprefix, prefix, false);
+}
+
+/* Add an entry for PREFIX at the begin of prefix list PREFIX.  */
+
+void
+add_prefix_begin (struct path_prefix *pprefix, const char *prefix)
+{
+  do_add_prefix (pprefix, prefix, true);
+}
+
 /* Take the value of the environment variable ENV, break it into a path, and
    add of the entries to PPREFIX.  */
 
diff --git a/gcc/file-find.h b/gcc/file-find.h
index b438056..0754d99 100644
--- a/gcc/file-find.h
+++ b/gcc/file-find.h
@@ -40,6 +40,7 @@ struct path_prefix
 extern void find_file_set_debug (bool);
 extern char *find_a_file (struct path_prefix *, const char *, int);
 extern void add_prefix (struct path_prefix *, const char *);
+extern void add_prefix_begin (struct path_prefix *, const char *);
 extern void prefix_from_env (const char *, struct path_prefix *);
 extern void prefix_from_string (const char *, struct path_prefix *);
 
diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
index aebaa92..b5199e6 100644
--- a/gcc/gcc-ar.c
+++ b/gcc/gcc-ar.c
@@ -132,9 +132,52 @@ main (int ac, char **av)
   const char **nargv;
   bool is_ar = !strcmp (PERSONALITY, "ar");
   int exit_code = FATAL_EXIT_CODE;
+  int i;
 
   setup_prefixes (av[0]);
 
+  /* Not using getopt for now.  */
+  for (i = 0; i < ac; i++)
+      if (!strncmp (av[i], "-B", 2))
+	{
+	  const char *arg = av[i] + 2;
+	  const char *end;
+	  size_t len;
+
+	  memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	  ac--;
+	  if (*arg == 0)
+	    {
+	      arg = av[i + 1];
+	      if (!arg)
+		{
+		  fprintf (stderr, "Usage: gcc-ar [-B prefix] ar arguments ...\n");
+		  exit (EXIT_FAILURE);
+		}
+	      memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	      ac--;
+	      i++;
+	    }
+	  /* else it's a joined argument  */
+
+	  len = strlen (arg);
+	  if (len > 0)
+		  len--;
+	  end = arg + len;
+
+	  /* Always add a dir separator for the prefix list.  */
+	  if (end > arg && !IS_DIR_SEPARATOR (*end))
+	    {
+	      static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
+	      arg = concat (arg, dir_separator_str, NULL);
+	    }
+
+	  add_prefix_begin (&path, arg);
+	  add_prefix_begin (&target_path, arg);
+	  break;
+	}
+
+
   /* Find the GCC LTO plugin */
   plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK);
   if (!plugin)
-- 
2.0.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm
@ 2014-08-09  4:07 Andi Kleen
  0 siblings, 0 replies; 7+ messages in thread
From: Andi Kleen @ 2014-08-09  4:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

To use gcc-{ar,ranlib} for boot strap we need to add a -B option
to the tool. Since ar has weird and unusual argument conventions
implement the code by hand instead of using any libraries.

v2: Fix typo

gcc/:

2014-08-04  Andi Kleen  <ak@linux.intel.com>

	* gcc-ar.c (main): Support -B option.
---
 gcc/gcc-ar.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
index aebaa92..70bf222 100644
--- a/gcc/gcc-ar.c
+++ b/gcc/gcc-ar.c
@@ -132,9 +132,50 @@ main (int ac, char **av)
   const char **nargv;
   bool is_ar = !strcmp (PERSONALITY, "ar");
   int exit_code = FATAL_EXIT_CODE;
+  int i;
 
   setup_prefixes (av[0]);
 
+  /* Not using getopt for now.  */
+  for (i = 0; i < ac; i++)
+      if (!strncmp (av[i], "-B", 2))
+	{
+	  const char *arg = av[i] + 2;
+	  const char *end;
+
+	  memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	  ac--;
+	  if (*arg == 0)
+	    {
+	      arg = av[i + 1];
+	      if (!arg)
+		{
+		  fprintf (stderr, "Usage: gcc-ar [-B prefix] ar arguments ...\n");
+		  exit (EXIT_FAILURE);
+		}
+	      memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+	      ac--;
+	      i++;
+	    }
+
+	  for (end = arg; *end; end++)
+	    ;
+	  end--;
+	  if (end > arg && *end != '/')
+	    {
+	      char *newarg = (char *)xmalloc (strlen(arg) + 2);
+
+	      strcpy (newarg, arg);
+	      strcat (newarg, "/");
+	      arg = newarg;
+	    }
+
+	  add_prefix (&path, arg);
+	  add_prefix (&target_path, arg);
+	  break;
+	}
+
+
   /* Find the GCC LTO plugin */
   plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK);
   if (!plugin)
-- 
2.0.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-09-01 16:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-04 14:30 Implement slim LTO bootstrap Andi Kleen
2014-08-04 14:30 ` [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm Andi Kleen
2014-08-04 14:30   ` [PATCH 2/2] Support slim LTO bootstrap Andi Kleen
2014-08-09  4:07 [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm Andi Kleen
2014-08-31 14:52 Updated slim LTO patchkit Andi Kleen
2014-08-31 14:52 ` [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm Andi Kleen
2014-09-01 11:34   ` Richard Biener
2014-09-01 16:33     ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).