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]

Enable -fuse-linker-plugin by default when possible, take 2


Hi,
here is updated patch with the test -f ../lto-plugin/Makefile trick and extra
dependency on cc1plugin.
There are still the failures:
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-alloca-1.C  -O2 -flto -flto-partition=none  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-alloca-1.C  -O2 -flto  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-global-1.C  -O2 -flto -flto-partition=none  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-global-1.C  -O2 -flto  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-inline-1.C  -O2 -flto -flto-partition=none  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-inline-1.C  -O2 -flto  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-inline-2.C  -O2 -flto -flto-partition=none  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-inline-2.C  -O2 -flto  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-vararg-1.C  -O2 -flto -flto-partition=none  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-vararg-1.C  -O2 -flto  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-vararg-2.C  -O2 -flto -flto-partition=none  (test for excess errors)
./gcc/testsuite/g++/g++.sum:FAIL: g++.dg/torture/stackalign/eh-vararg-2.C  -O2 -flto  (test for excess errors)
./gcc/testsuite/gcc5/gcc.sum:FAIL: gcc.c-torture/execute/builtins/memops-asm.c execution,  -O2 -flto 
./gcc/testsuite/gcc5/gcc.sum:FAIL: gcc.c-torture/execute/builtins/snprintf-chk.c execution,  -O2 -flto 
./gcc/testsuite/gcc5/gcc.sum:FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -O2 -flto 
./gcc/testsuite/gcc5/gcc.sum:FAIL: gcc.c-torture/execute/builtins/strncpy-chk.c execution,  -O2 -flto 
./gcc/testsuite/gcc5/gcc.sum:FAIL: gcc.c-torture/execute/builtins/vsnprintf-chk.c execution,  -O2 -flto 
./gcc/testsuite/gcc2/gcc.sum:FAIL: gcc.c-torture/execute/bcp-1.c execution,  -O2 -flto 
./gcc/testsuite/gcc2/gcc.sum:FAIL: gcc.c-torture/execute/eeprof-1.c execution,  -O2 -flto 

(stackalign is new, these are undefined local symbols, similar to the known libstdc++ LTO issues.
Perhaps it is becuase I updated tree and switched from gold to gnu ld).
I will deal with all of these.

Bootstrapped/regtested x86_64-linux, OK (after fixing the testcases?)

Honza

	* Makefile.in: Regenerate.
	* Makefile.def (gcc host module) and soft dependency on lto-plugin
	and configure dependency on lto-plugin configure.
	(lto-plugin module): Remove dependency on GCC; add dependency on
	liniberty.

	* doc/invoke.texi: (-flto, -fuse-linker-plugin): Update defaults
	and no longer claim that gold is required for linker plugin.
	* configure: Regenerate.
	* gcc.c (PLUGIN_COND): New macro.
	(LINK_COMMAND_SPEC): Use it.
	(main): Default to plugin enabled with HAVE_LTO_PLUGIN is set.
	* config.in (HAVE_LTO_PLUGIN): New.
	* configure.ac (--with-lto-plugin): New parameter; autodetect
	HAVE_LTO_PLUGIN.
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 167242)
+++ Makefile.in	(working copy)
@@ -60260,6 +60260,14 @@ configure-stage3-gcc: maybe-configure-st
 configure-stage4-gcc: maybe-configure-stage4-intl
 configure-stageprofile-gcc: maybe-configure-stageprofile-intl
 configure-stagefeedback-gcc: maybe-configure-stagefeedback-intl
+configure-gcc: maybe-configure-lto-plugin
+
+configure-stage1-gcc: maybe-configure-stage1-lto-plugin
+configure-stage2-gcc: maybe-configure-stage2-lto-plugin
+configure-stage3-gcc: maybe-configure-stage3-lto-plugin
+configure-stage4-gcc: maybe-configure-stage4-lto-plugin
+configure-stageprofile-gcc: maybe-configure-stageprofile-lto-plugin
+configure-stagefeedback-gcc: maybe-configure-stagefeedback-lto-plugin
 configure-gcc: maybe-all-binutils
 
 configure-stage1-gcc: maybe-all-stage1-binutils
@@ -60437,6 +60445,14 @@ all-stage4-gcc: maybe-all-stage4-libiber
 all-stageprofile-gcc: maybe-all-stageprofile-libiberty
 all-stagefeedback-gcc: maybe-all-stagefeedback-libiberty
 all-gcc: maybe-all-fixincludes
+all-gcc: maybe-all-lto-plugin
+
+all-stage1-gcc: maybe-all-stage1-lto-plugin
+all-stage2-gcc: maybe-all-stage2-lto-plugin
+all-stage3-gcc: maybe-all-stage3-lto-plugin
+all-stage4-gcc: maybe-all-stage4-lto-plugin
+all-stageprofile-gcc: maybe-all-stageprofile-lto-plugin
+all-stagefeedback-gcc: maybe-all-stagefeedback-lto-plugin
 info-gcc: maybe-all-build-libiberty
 
 info-stage1-gcc: maybe-all-build-libiberty
@@ -60505,14 +60521,14 @@ all-stageprofile-libcpp: maybe-all-stage
 all-stagefeedback-libcpp: maybe-all-stagefeedback-intl
 all-fixincludes: maybe-all-libiberty
 all-gnattools: maybe-all-target-libada
-all-lto-plugin: maybe-all-gcc
+all-lto-plugin: maybe-all-libiberty
 
-all-stage1-lto-plugin: maybe-all-stage1-gcc
-all-stage2-lto-plugin: maybe-all-stage2-gcc
-all-stage3-lto-plugin: maybe-all-stage3-gcc
-all-stage4-lto-plugin: maybe-all-stage4-gcc
-all-stageprofile-lto-plugin: maybe-all-stageprofile-gcc
-all-stagefeedback-lto-plugin: maybe-all-stagefeedback-gcc
+all-stage1-lto-plugin: maybe-all-stage1-libiberty
+all-stage2-lto-plugin: maybe-all-stage2-libiberty
+all-stage3-lto-plugin: maybe-all-stage3-libiberty
+all-stage4-lto-plugin: maybe-all-stage4-libiberty
+all-stageprofile-lto-plugin: maybe-all-stageprofile-libiberty
+all-stagefeedback-lto-plugin: maybe-all-stagefeedback-libiberty
 configure-mpfr: maybe-all-gmp
 
 configure-stage1-mpfr: maybe-all-stage1-gmp
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 167242)
+++ gcc/doc/invoke.texi	(working copy)
@@ -7582,23 +7582,21 @@ types in separate translation units to b
 behavior according to ISO C99 6.2.7), a non-fatal diagnostic may be
 issued.  The behavior is still undefined at runtime.
 
-If object files containing GIMPLE bytecode are stored in a library
-archive, say @file{libfoo.a}, it is possible to extract and use them
-in an LTO link if you are using @command{gold} as the linker (which,
-in turn requires GCC to be configured with @option{--enable-gold}).
-To enable this feature, use the flag @option{-fuse-linker-plugin} at
-link-time:
+If object files containing GIMPLE bytecode are stored in a library archive, say
+@file{libfoo.a}, it is possible to extract and use them in an LTO link if you
+are using linker with the linker plugin support.  To enable this feature, use
+the flag @option{-fuse-linker-plugin} at link-time:
 
 @smallexample
 gcc -o myprog -O2 -flto -fuse-linker-plugin a.o b.o -lfoo
 @end smallexample
 
-With the linker plugin enabled, @command{gold} will extract the needed
+With the linker plugin enabled, the linnker will extract the needed
 GIMPLE files from @file{libfoo.a} and pass them on to the running GCC
 to make them part of the aggregated GIMPLE image to be optimized.
 
-If you are not using @command{gold} and/or do not specify
-@option{-fuse-linker-plugin} then the objects inside @file{libfoo.a}
+If you are not using a linker with linker plugin support and/or do not 
+enable linker plugin then the objects inside @file{libfoo.a}
 will be extracted and linked as usual, but they will not participate
 in the LTO optimization process.
 
@@ -7662,13 +7660,21 @@ files in LTO mode (via @option{-flto}).
 Disabled by default.
 
 @item -fuse-linker-plugin
-Enables the extraction of objects with GIMPLE bytecode information
-from library archives.  This option relies on features available only
-in @command{gold}, so to use this you must configure GCC with
-@option{--enable-gold}.  See @option{-flto} for a description on the
-effect of this flag and how to use it.
+Enabled the use of linker plugin during link time optimization.  This option
+relies on the linker plugin support in linker that is available in @code{gold}
+or recent GNU ld.
+
+This command linke option enable the extraction of objects with GIMPLE
+bytecode information from library archives as well as improves the quality of
+optimization by making it possible for the link time optimizer to use the
+resolution information.  This information specify what symbols are bound by
+non-LTO object files or can be used during dynamic linking. Resulting code
+quality improvements on binaries (and shared libaries that do use hidden
+visibilit)y is similar to @code{-fwhole-program}.  See @option{-flto} for a
+description on the effect of this flag and how to use it.
 
-Disabled by default.
+Enabled by default when LTO support in GCC is enabled and GCC was compiled
+with linker supporting plugins (GNU ld or @code{gold}).
 
 @item -fcprop-registers
 @opindex fcprop-registers
Index: gcc/configure
===================================================================
--- gcc/configure	(revision 167242)
+++ gcc/configure	(working copy)
@@ -22866,6 +22866,29 @@ $as_echo "#define HAVE_LD_DEMANGLE 1" >>
 $as_echo "$gcc_cv_ld_demangle" >&6; }
 fi
 
+if test -f ../lto-plugin/Makefile ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker plugin support" >&5
+$as_echo_n "checking linker plugin support... " >&6; }
+  gcc_cv_lto_plugin=no
+  if test $in_tree_ld = yes -a x"$ORIGINAL_PLUGIN_LD_FOR_TARGET=" = x"$gcc_cv_ld"; then
+    if test x"$ld_is_gold" = xyes; then
+      gcc_cv_lto_plugin=yes
+    elif test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 21 -o "$gcc_cv_gld_major_version" -gt 2; then \
+      gcc_cv_lto_plugin=yes
+    fi
+  # Check if the linker supports --plugin-opt option
+  elif $ORIGINAL_PLUGIN_LD_FOR_TARGET --help 2>/dev/null | grep plugin-opt > /dev/null; then
+    gcc_cv_lto_plugin=yes
+  fi
+  if test x"$gcc_cv_lto_plugin" = xyes; then
+
+$as_echo "#define HAVE_LTO_PLUGIN 1" >>confdefs.h
+
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_lto_plugin" >&5
+$as_echo "$gcc_cv_lto_plugin" >&6; }
+fi
+
 case "$target" in
   # All TARGET_ABI_OSF targets.
   alpha*-*-osf* | alpha*-*-linux* | alpha*-*-*bsd*)
Index: gcc/gcc.c
===================================================================
*** gcc/gcc.c	(revision 167220)
--- gcc/gcc.c	(working copy)
*************** proper position among the other output f
*** 640,645 ****
--- 640,652 ----
  # endif
  #endif
  
+ /* Conditional to test whether plugin is used or not.  */
+ #ifdef HAVE_LTO_PLUGIN
+ #define PLUGIN_COND "!fno-use-linker-plugin"
+ #else
+ #define PLUGIN_COND "fuse-linker-plugin"
+ #endif
+ 
  
  /* -u* was put back because both BSD and SysV seem to support it.  */
  /* %{static:} simply prevents an error message if the target machine
*************** proper position among the other output f
*** 653,659 ****
  #define LINK_COMMAND_SPEC "\
  %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
      %(linker) \
!     %{fuse-linker-plugin: \
      -plugin %(linker_plugin_file) \
      -plugin-opt=%(lto_wrapper) \
      -plugin-opt=-fresolution=%u.res \
--- 660,666 ----
  #define LINK_COMMAND_SPEC "\
  %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
      %(linker) \
!     %{"PLUGIN_COND": \
      -plugin %(linker_plugin_file) \
      -plugin-opt=%(lto_wrapper) \
      -plugin-opt=-fresolution=%u.res \
*************** warranty; not even for MERCHANTABILITY o
*** 6786,6792 ****
--- 6793,6803 ----
    if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
      {
        int tmp = execution_count;
+ #ifdef HAVE_LTO_PLUGIN
+       const char *fno_use_linker_plugin = "fno-use-linker-plugin";
+ #else
        const char *fuse_linker_plugin = "fuse-linker-plugin";
+ #endif
  
        /* We'll use ld if we can't find collect2.  */
        if (! strcmp (linker_name_spec, "collect2"))
*************** warranty; not even for MERCHANTABILITY o
*** 6796,6803 ****
--- 6807,6819 ----
  	    linker_name_spec = "ld";
  	}
  
+ #ifdef HAVE_LTO_PLUGIN
+       if (!switch_matches (fno_use_linker_plugin,
+ 			   fno_use_linker_plugin + strlen (fno_use_linker_plugin), 0))
+ #else
        if (switch_matches (fuse_linker_plugin,
  			  fuse_linker_plugin + strlen (fuse_linker_plugin), 0))
+ #endif
  	{
  	  linker_plugin_file_spec = find_a_file (&exec_prefixes,
  						 LTOPLUGINSONAME, R_OK,
Index: gcc/config.in
===================================================================
--- gcc/config.in	(revision 167242)
+++ gcc/config.in	(working copy)
@@ -1142,6 +1142,10 @@
 #undef HAVE_LD_DEMANGLE
 #endif
 
+/* Define if your linker supports plugin. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_LTO_PLUGIN
+#endif
 
 /* Define if your linker supports --eh-frame-hdr option. */
 #undef HAVE_LD_EH_FRAME_HDR
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 167242)
+++ gcc/configure.ac	(working copy)
@@ -3127,6 +3127,26 @@ if test x"$demangler_in_ld" = xyes; then
   AC_MSG_RESULT($gcc_cv_ld_demangle)
 fi
 
+if test -f ../lto-plugin/Makefile ; then
+  AC_MSG_CHECKING(linker plugin support)
+  gcc_cv_lto_plugin=no
+  if test $in_tree_ld = yes -a x"$ORIGINAL_PLUGIN_LD_FOR_TARGET=" = x"$gcc_cv_ld"; then
+    if test x"$ld_is_gold" = xyes; then
+      gcc_cv_lto_plugin=yes
+    elif test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 21 -o "$gcc_cv_gld_major_version" -gt 2; then \
+      gcc_cv_lto_plugin=yes
+    fi
+  # Check if the linker supports --plugin-opt option
+  elif $ORIGINAL_PLUGIN_LD_FOR_TARGET --help 2>/dev/null | grep plugin-opt > /dev/null; then
+    gcc_cv_lto_plugin=yes
+  fi
+  if test x"$gcc_cv_lto_plugin" = xyes; then
+    AC_DEFINE(HAVE_LTO_PLUGIN, 1,
+  [Define if your linker supports plugin.])
+  fi
+  AC_MSG_RESULT($gcc_cv_lto_plugin)
+fi
+
 case "$target" in
   # All TARGET_ABI_OSF targets.
   alpha*-*-osf* | alpha*-*-linux* | alpha*-*-*bsd*)
Index: Makefile.def
===================================================================
--- Makefile.def	(revision 167242)
+++ Makefile.def	(working copy)
@@ -321,6 +321,7 @@ dependencies = { module=all-build-fixinc
 
 // Host modules specific to gcc.
 dependencies = { module=configure-gcc; on=configure-intl; };
+dependencies = { module=configure-gcc; on=configure-lto-plugin; };
 dependencies = { module=configure-gcc; on=all-binutils; };
 dependencies = { module=configure-gcc; on=all-gas; };
 dependencies = { module=configure-gcc; on=all-ld; };
@@ -344,6 +345,7 @@ dependencies = { module=all-gcc; on=all-
 dependencies = { module=all-gcc; on=all-libdecnumber; hard=true; };
 dependencies = { module=all-gcc; on=all-libiberty; };
 dependencies = { module=all-gcc; on=all-fixincludes; };
+dependencies = { module=all-gcc; on=all-lto-plugin; };
 dependencies = { module=info-gcc; on=all-build-libiberty; };
 dependencies = { module=dvi-gcc; on=all-build-libiberty; };
 dependencies = { module=pdf-gcc; on=all-build-libiberty; };
@@ -360,7 +362,7 @@ dependencies = { module=all-fixincludes;
 
 dependencies = { module=all-gnattools; on=all-target-libada; };
 
-dependencies = { module=all-lto-plugin; on=all-gcc; };
+dependencies = { module=all-lto-plugin; on=all-libiberty; };
 
 dependencies = { module=configure-mpfr; on=all-gmp; };
 dependencies = { module=configure-mpc; on=all-mpfr; };


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