This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] Add support for running execute.exp with -flto


This patch fixes a couple of minor things in the driver so that we can
use -flto from the testsuite.

To run a single file through LTO and link it using lto1:

$ gcc -flto file.c

To combine two files using LTO:

$ gcc -flto f1.c f2.c

To generate fat object files and link them with LTO afterwards:

$ gcc -c -flto f1.c
$ gcc -c -flto f2.c
$ gcc -o f f1.o f2.o

Notice that -flto is not needed in the final link command.  This is, I
think, the end-user model we want to use.  I had first thought that we
may want to name the LTO object files with a .lto extension, but Kenny
rightfully opposed that idea, as it is too pervasive and forces people
to change their build processes too much.

With this patch, we can now go through all of execute.exp.  Not
surprisingly, very many tests fail.  There is a PASS rate of about
15%, so I expect that there will be several simple bugs that will be
common across many tests.

I've marked the hacked -O2 flag in the specs string so that we
remember to remove it once we get rid of the -O2 limitation.

Tested on x86_64.

2007-10-19  Diego Novillo  <dnovillo@google.com>

	* gcc.c (cc1_options): Force -O2 if -flto is given.
	* collect2.c (maybe_run_lto_and_relink): Tidy formatting.
	Add -O2 when calling gcc to do an LTO link.
	(scan_prog_file): Send the error output of 'nm' to HOST_BIT_BUCKET.

testsuite/ChangeLog:

	* lib/c-torture.exp (TORTURE_OPTIONS): Add -flto for -O2 compiles.

Index: gcc.c
===================================================================
--- gcc.c	(revision 129463)
+++ gcc.c	(working copy)
@@ -818,6 +818,7 @@ static const char *cpp_options =
 static const char *cpp_debug_options = "%{d*}";

 /* NB: This is shared amongst all front-ends.  */
+/* FIXME lto: -O2 is needed as a temporary workaround.  Remove.  */
 static const char *cc1_options =
 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
@@ -830,7 +831,8 @@ static const char *cc1_options =
  %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
  %{fsyntax-only:-o %j} %{-param*}\
  %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}\
- %{coverage:-fprofile-arcs -ftest-coverage}";
+ %{coverage:-fprofile-arcs -ftest-coverage}\
+ %{flto:-O2}";

 static const char *asm_options =
 "%{--target-help:%:print-asm-header()} "
Index: testsuite/lib/c-torture.exp
===================================================================
--- testsuite/lib/c-torture.exp	(revision 129463)
+++ testsuite/lib/c-torture.exp	(working copy)
@@ -33,7 +33,7 @@ if ![info exists TORTURE_OPTIONS] {
     set TORTURE_OPTIONS [list \
 	{ -O0 } \
 	{ -O1 } \
-	{ -O2 } \
+	{ -O2 -flto } \
 	{ -O3 -fomit-frame-pointer } \
 	{ -O3 -fomit-frame-pointer -funroll-loops } \
 	{ -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
Index: collect2.c
===================================================================
--- collect2.c	(revision 129463)
+++ collect2.c	(working copy)
@@ -791,32 +791,36 @@ add_lto_object (struct lto_object_list *
   list->last = cell;
 }

-/* Perform a link-time recompilation and relink if any of the object files
-   contain LTO info.  The linker command line LTO_LD_ARGV represents the linker
-   command that would produce a final executable without the use of LTO.
-   OBJECT_LST is a vector of object file names appearing in LTO_LD_ARGV that
-   are to be considerd for link-time recompilation, where OBJECT is a pointer
-   to the last valid element.  (This awkward convention avoids an impedance
-   mismatch with the usage of similarly-named variables in main().)  The
-   elements of OBJECT_LST must be identical, i.e., pointer equal, to the
+/* Perform a link-time recompilation and relink if any of the object
+   files contain LTO info.  The linker command line LTO_LD_ARGV
+   represents the linker command that would produce a final executable
+   without the use of LTO. OBJECT_LST is a vector of object file names
+   appearing in LTO_LD_ARGV that are to be considerd for link-time
+   recompilation, where OBJECT is a pointer to the last valid element.
+   (This awkward convention avoids an impedance mismatch with the
+   usage of similarly-named variables in main().)  The elements of
+   OBJECT_LST must be identical, i.e., pointer equal, to the
    corresponding arguments in LTO_LD_ARGV.

-   Upon entry, at least one linker run has been performed without the
use of any
-   LTO info that might be present.  Any recompilations necessary for template
-   instantiations have been performed, and initializer/finalizer
tables have been
-   created if needed and included in the linker command line LTO_LD_ARGV.
-   If any of the object files contain LTO info, we run the LTO back end on all
-   such files, and perform the final link with the LTO back end
output substituted
-   for the LTO-optimized files.  In some cases, a final link with all link-time
-   generated code has already been performed, so there is no need to
relink if no
-   LTO info is found.  In other cases, our caller has not produced the final
-   executable, and is relying on us to perform the required link
whether LTO info
-   is present or not.  In that case, the FORCE argument should be
true.  Note that
-   the linker command line argument LTO_LD_ARGV passed into this
function may be
-   modified in place.  */
+   Upon entry, at least one linker run has been performed without the
+   use of any LTO info that might be present.  Any recompilations
+   necessary for template instantiations have been performed, and
+   initializer/finalizer tables have been created if needed and
+   included in the linker command line LTO_LD_ARGV. If any of the
+   object files contain LTO info, we run the LTO back end on all such
+   files, and perform the final link with the LTO back end output
+   substituted for the LTO-optimized files.  In some cases, a final
+   link with all link-time generated code has already been performed,
+   so there is no need to relink if no LTO info is found.  In other
+   cases, our caller has not produced the final executable, and is
+   relying on us to perform the required link whether LTO info is
+   present or not.  In that case, the FORCE argument should be true.
+   Note that the linker command line argument LTO_LD_ARGV passed into
+   this function may be modified in place.  */

 static void
-maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst,
const char ** object, bool force)
+maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst,
+			  const char **object, bool force)
 {
   const char **object_file = (const char **)object_lst;

@@ -866,16 +870,20 @@ maybe_run_lto_and_relink (char **lto_ld_
         }
       obstack_free (&temporary_obstack, temporary_firstobj);

-      /* Increment the argument count by the number of initial
arguments added below.  */
-      num_lto_c_args += 7;
+      /* Increment the argument count by the number of initial
+	 arguments added below.  */
+      num_lto_c_args += 8;

-      lto_c_ptr = (const char **) (lto_c_argv = xcalloc (sizeof (char
*), num_lto_c_args));
+      lto_c_argv = xcalloc (sizeof (char *), num_lto_c_args);
+      lto_c_ptr = (const char **) lto_c_argv;

       *lto_c_ptr++ = c_file_name;
       *lto_c_ptr++ = "-combine";
       *lto_c_ptr++ = "-x";
       *lto_c_ptr++ = "lto";
       *lto_c_ptr++ = "-c";
+      /* FIXME lto.  Temporary workaround.  Remove before merging.  */
+      *lto_c_ptr++ = "-O2";
       *lto_c_ptr++ = "-o";
       *lto_c_ptr++ = lto_o_file;

@@ -911,10 +919,9 @@ maybe_run_lto_and_relink (char **lto_ld_
         }
       obstack_free (&temporary_obstack, temporary_firstobj);

-      /* After running the LTO back end, we will relink, substituting the LTO
-         output for the object files that we submitted to the LTO.  Here, we
-         modify the linker command line for the relink.  */
-
+      /* After running the LTO back end, we will relink, substituting
+	 the LTO output for the object files that we submitted to the
+	 LTO. Here, we modify the linker command line for the relink.  */
       first = true;

       p = (const char **)lto_ld_argv;
@@ -1449,8 +1456,10 @@ main (int argc, char **argv)
 	    }
 	}
       else if ((p = strrchr (arg, '.')) != (char *) 0
-	       && (strcmp (p, ".o") == 0 || strcmp (p, ".a") == 0
-		   || strcmp (p, ".so") == 0 || strcmp (p, ".lo") == 0
+	       && (strcmp (p, ".o") == 0
+		   || strcmp (p, ".a") == 0
+		   || strcmp (p, ".so") == 0
+		   || strcmp (p, ".lo") == 0
 		   || strcmp (p, ".obj") == 0))
 	{
 	  if (first_file)
@@ -2390,7 +2399,8 @@ scan_prog_file (const char *prog_name, e
   if (pex == NULL)
     fatal_perror ("pex_init failed");

-  errmsg = pex_run (pex, 0, nm_file_name, real_nm_argv, NULL, NULL, &err);
+  errmsg = pex_run (pex, 0, nm_file_name, real_nm_argv, NULL, HOST_BIT_BUCKET,
+		    &err);
   if (errmsg != NULL)
     {
       if (err != 0)
@@ -2432,14 +2442,14 @@ scan_prog_file (const char *prog_name, e
         {
           /* Look for the LTO info marker symbol, and add filename to
              the LTO objects list if found.  */
-
           for (p = buf; (ch = *p) != '\0' && ch != '\n'; p++)
-            if (ch == ' ' && (strncmp (p+1, "gnu_lto_v1", 10) == 0)
&& ISSPACE(p[11]))
+            if (ch == ' '
+		&& (strncmp (p+1, "gnu_lto_v1", 10) == 0)
+		&& ISSPACE(p[11]))
               {
                 add_lto_object (&lto_objects, prog_name);

                 /* No need to look any further.  Clean up and return.  */
-
                 if (debug)
                   fprintf (stderr, "\n");

@@ -2456,7 +2466,6 @@ scan_prog_file (const char *prog_name, e
         {
           /* If it contains a constructor or destructor name, add the name
              to the appropriate list.  */
-
           for (p = buf; (ch = *p) != '\0' && ch != '\n' && ch != '_'; p++)
             if (ch == ' ' && p[1] == 'U' && p[2] == ' ')
               break;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]