Enable -fuse-linker-plugin by default when possible

Jan Hubicka hubicka@ucw.cz
Mon Nov 29 02:28:00 GMT 2010


Hi,
this patch makes us to enable -fuse-linker-plugin by default when LTO is
enabled and (plugin)ld support plugins. This was discussed at the GCC Summit
BOF as change we want to make to avoid user confussion.
(plugin enabled LTO behaves a lot saner by not requiring -fwhole-program for
good optimizations and by not silently ignoring LTO objects in archives)

The decision whether to build linker plugin is made by toplevel configure,
while logic about plugin ld is in gcc configure.  So I pass decision of
toplevel configure as --with-plugin=yes into gcc configure and added logic
autodetecting presence of --plugin-opt command line option or testing whether
we build with in-tree gold or resonably recent GNU ld.

The patch triggers following failures in testsuite:
./gcc/testsuite/gcc5/gcc.sum:FAIL: gcc.c-torture/execute/builtins/memops-asm.c compilation,  -O2 -flto -flto-partition=none 
./gcc/testsuite/gcc5/gcc.sum:FAIL: gcc.c-torture/execute/builtins/memops-asm.c compilation,  -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 


The memops-asm testcase don't work with LTO and linker plugin as it play funny
games with runtime and linker plugin makes resolution before the optimization
they test for takes place.  The bcp testcase is optimized too much (it tests
that buildtin_constant_p returns expected values on symbols we resolve via
resolution file).  I didn't investigated the -chk testcases yet, but I expect
this to be similar issue.

Shall we disable those for -flto testing or add -fno-use-linker-plugin extra
option?

I any case I will handle the testcases by independent patch that can go in before
this change.

Bootstrapped/regtested x86_64-linux with and without plugin enabled ld, OK?

Honza

	* configure: Regenerate.
	* Makefile.in: Regenerate.
	* configure.ac: Pass extra_gcc_configure_flags containing
	--with-lto-plugin=yes when linker plugin is enabled.
	* Makefile.def (gcc host module): Add extra_configure_flags
	and soft dependency on lto-plugin
	(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: configure
===================================================================
*** configure	(revision 167220)
--- configure	(working copy)
*************** CFLAGS_FOR_TARGET
*** 640,645 ****
--- 640,646 ----
  DEBUG_PREFIX_CFLAGS_FOR_TARGET
  SYSROOT_CFLAGS_FOR_TARGET
  stage1_languages
+ extra_gcc_configure_flags
  extra_host_libiberty_configure_flags
  clooginc
  clooglibs
*************** if test -d ${srcdir}/gcc; then
*** 6201,6206 ****
--- 6202,6208 ----
  
    # If LTO is enabled, add the LTO front end.
    extra_host_libiberty_configure_flags=
+   extra_gcc_configure_flags=
    if test "$enable_lto" = "yes" ; then
      case ,${enable_languages}, in
        *,lto,*) ;;
*************** if test -d ${srcdir}/gcc; then
*** 6209,6218 ****
--- 6211,6222 ----
      if test "${build_lto_plugin}" = "yes" ; then
        configdirs="$configdirs lto-plugin"
        extra_host_libiberty_configure_flags=--enable-shared
+       extra_gcc_configure_flags="--with-lto-plugin=yes"
      fi
    fi
  
  
+ 
    missing_languages=`echo ",$enable_languages," | sed -e s/,all,/,/ -e s/,c,/,/ `
    potential_languages=,c,
  
Index: Makefile.in
===================================================================
*** Makefile.in	(revision 167220)
--- Makefile.in	(working copy)
*************** configure-gcc:
*** 15105,15111 ****
  	libsrcdir="$$s/gcc"; \
  	$(SHELL) $${libsrcdir}/configure \
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
! 	  --target=${target_alias} $${srcdiroption}  \
  	  || exit 1
  @endif gcc
  
--- 15105,15111 ----
  	libsrcdir="$$s/gcc"; \
  	$(SHELL) $${libsrcdir}/configure \
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
! 	  --target=${target_alias} $${srcdiroption} @extra_gcc_configure_flags@ \
  	  || exit 1
  @endif gcc
  
*************** configure-stage1-gcc:
*** 15139,15145 ****
  	$(SHELL) $${libsrcdir}/configure \
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
! 	  $(STAGE1_CONFIGURE_FLAGS)
  @endif gcc-bootstrap
  
  .PHONY: configure-stage2-gcc maybe-configure-stage2-gcc
--- 15139,15146 ----
  	$(SHELL) $${libsrcdir}/configure \
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
! 	  $(STAGE1_CONFIGURE_FLAGS) \
! 	  @extra_gcc_configure_flags@
  @endif gcc-bootstrap
  
  .PHONY: configure-stage2-gcc maybe-configure-stage2-gcc
*************** configure-stage2-gcc:
*** 15172,15178 ****
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGE2_CONFIGURE_FLAGS)
  @endif gcc-bootstrap
  
  .PHONY: configure-stage3-gcc maybe-configure-stage3-gcc
--- 15173,15180 ----
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGE2_CONFIGURE_FLAGS) \
! 	  @extra_gcc_configure_flags@
  @endif gcc-bootstrap
  
  .PHONY: configure-stage3-gcc maybe-configure-stage3-gcc
*************** configure-stage3-gcc:
*** 15205,15211 ****
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGE3_CONFIGURE_FLAGS)
  @endif gcc-bootstrap
  
  .PHONY: configure-stage4-gcc maybe-configure-stage4-gcc
--- 15207,15214 ----
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGE3_CONFIGURE_FLAGS) \
! 	  @extra_gcc_configure_flags@
  @endif gcc-bootstrap
  
  .PHONY: configure-stage4-gcc maybe-configure-stage4-gcc
*************** configure-stage4-gcc:
*** 15238,15244 ****
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGE4_CONFIGURE_FLAGS)
  @endif gcc-bootstrap
  
  .PHONY: configure-stageprofile-gcc maybe-configure-stageprofile-gcc
--- 15241,15248 ----
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGE4_CONFIGURE_FLAGS) \
! 	  @extra_gcc_configure_flags@
  @endif gcc-bootstrap
  
  .PHONY: configure-stageprofile-gcc maybe-configure-stageprofile-gcc
*************** configure-stageprofile-gcc:
*** 15271,15277 ****
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGEprofile_CONFIGURE_FLAGS)
  @endif gcc-bootstrap
  
  .PHONY: configure-stagefeedback-gcc maybe-configure-stagefeedback-gcc
--- 15275,15282 ----
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGEprofile_CONFIGURE_FLAGS) \
! 	  @extra_gcc_configure_flags@
  @endif gcc-bootstrap
  
  .PHONY: configure-stagefeedback-gcc maybe-configure-stagefeedback-gcc
*************** configure-stagefeedback-gcc:
*** 15304,15310 ****
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGEfeedback_CONFIGURE_FLAGS)
  @endif gcc-bootstrap
  
  
--- 15309,15316 ----
  	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
  	  --target=${target_alias} $${srcdiroption} \
  	  --with-build-libsubdir=$(HOST_SUBDIR) \
! 	  $(STAGEfeedback_CONFIGURE_FLAGS) \
! 	  @extra_gcc_configure_flags@
  @endif gcc-bootstrap
  
  
*************** all-stage4-gcc: maybe-all-stage4-libiber
*** 60437,60442 ****
--- 60443,60456 ----
  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
*************** all-stageprofile-libcpp: maybe-all-stage
*** 60505,60518 ****
  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-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
  configure-mpfr: maybe-all-gmp
  
  configure-stage1-mpfr: maybe-all-stage1-gmp
--- 60519,60532 ----
  all-stagefeedback-libcpp: maybe-all-stagefeedback-intl
  all-fixincludes: maybe-all-libiberty
  all-gnattools: maybe-all-target-libada
! all-lto-plugin: maybe-all-libiberty
  
! 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 167220)
--- gcc/doc/invoke.texi	(working copy)
*************** types in separate translation units to b
*** 7582,7604 ****
  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:
  
  @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
  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}
  will be extracted and linked as usual, but they will not participate
  in the LTO optimization process.
  
--- 7582,7602 ----
  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 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, 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 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.
  
*************** files in LTO mode (via @option{-flto}).
*** 7662,7674 ****
  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.
  
! Disabled by default.
  
  @item -fcprop-registers
  @opindex fcprop-registers
--- 7660,7680 ----
  Disabled by default.
  
  @item -fuse-linker-plugin
! 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.
  
! 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 167220)
--- gcc/configure	(working copy)
*************** enable_static
*** 900,905 ****
--- 900,906 ----
  with_pic
  enable_fast_install
  enable_libtool_lock
+ with_lto_plugin
  with_plugin_ld
  enable_gnu_indirect_function
  enable_comdat
*************** Optional Packages:
*** 1653,1658 ****
--- 1654,1660 ----
    --with-pic              try to use only PIC/non-PIC objects [default=use
                            both]
    --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+   --with-lto-plugin  enable support for lto plugin if supported by the linker
    --with-plugin-ld=[ARG]  specify the plugin linker
    --with-long-double-128  Use 128-bit long double by default.
    --with-gc={page,zone}   choose the garbage collection mechanism to use
*************** else
*** 17286,17292 ****
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
! #line 17289 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
--- 17288,17294 ----
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
! #line 17291 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
*************** else
*** 17392,17398 ****
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
! #line 17395 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
--- 17394,17400 ----
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
! #line 17397 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
*************** fi
*** 20840,20845 ****
--- 20842,20856 ----
  fi
  fi
  
+ 
+ # Check whether --with-lto-plugin was given.
+ if test "${with_lto_plugin+set}" = set; then :
+   withval=$with_lto_plugin; lto_plugin="$with_lto_plugin"
+ else
+   lto_plugin=no
+ fi
+ 
+ 
  ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld
  PLUGIN_LD=`basename $gcc_cv_ld`
  
*************** $as_echo "#define HAVE_LD_DEMANGLE 1" >>
*** 22866,22871 ****
--- 22877,22905 ----
  $as_echo "$gcc_cv_ld_demangle" >&6; }
  fi
  
+ if test x"$lto_plugin" = xyes; 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 167220)
--- gcc/config.in	(working copy)
***************
*** 1142,1147 ****
--- 1142,1151 ----
  #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 167220)
--- gcc/configure.ac	(working copy)
*************** else
*** 1915,1920 ****
--- 1915,1925 ----
          AC_PATH_PROG(gcc_cv_ld, $LD_FOR_TARGET)
  fi])
  
+ AC_ARG_WITH(lto-plugin,
+ [  --with-lto-plugin  enable support for lto plugin if supported by the linker],
+ lto_plugin="$with_lto_plugin",
+ lto_plugin=no)
+ 
  ORIGINAL_PLUGIN_LD_FOR_TARGET=$gcc_cv_ld
  PLUGIN_LD=`basename $gcc_cv_ld`
  AC_ARG_WITH(plugin-ld,
*************** if test x"$demangler_in_ld" = xyes; then
*** 3127,3132 ****
--- 3132,3157 ----
    AC_MSG_RESULT($gcc_cv_ld_demangle)
  fi
  
+ if test x"$lto_plugin" = xyes; 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: configure.ac
===================================================================
*** configure.ac	(revision 167220)
--- configure.ac	(working copy)
*************** if test -d ${srcdir}/gcc; then
*** 1783,1788 ****
--- 1783,1789 ----
  
    # If LTO is enabled, add the LTO front end.
    extra_host_libiberty_configure_flags=
+   extra_gcc_configure_flags=
    if test "$enable_lto" = "yes" ; then
      case ,${enable_languages}, in
        *,lto,*) ;;
*************** if test -d ${srcdir}/gcc; then
*** 1791,1799 ****
--- 1792,1802 ----
      if test "${build_lto_plugin}" = "yes" ; then
        configdirs="$configdirs lto-plugin"
        extra_host_libiberty_configure_flags=--enable-shared
+       extra_gcc_configure_flags="--with-lto-plugin=yes"
      fi
    fi
    AC_SUBST(extra_host_libiberty_configure_flags)
+   AC_SUBST(extra_gcc_configure_flags)
  
    missing_languages=`echo ",$enable_languages," | sed -e s/,all,/,/ -e s/,c,/,/ `
    potential_languages=,c,
Index: Makefile.def
===================================================================
*** Makefile.def	(revision 167220)
--- Makefile.def	(working copy)
*************** host_modules= { module= fixincludes;
*** 57,62 ****
--- 57,63 ----
  host_modules= { module= flex; no_check_cross= true; };
  host_modules= { module= gas; bootstrap=true; };
  host_modules= { module= gcc; bootstrap=true; 
+ 		extra_configure_flags='@extra_gcc_configure_flags@';
  		extra_make_flags="$(EXTRA_GCC_FLAGS)"; };
  host_modules= { module= gawk; };
  host_modules= { module= gettext; };
*************** dependencies = { module=all-gcc; on=all-
*** 344,349 ****
--- 345,351 ----
  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; };
*************** dependencies = { module=all-fixincludes;
*** 360,366 ****
  
  dependencies = { module=all-gnattools; on=all-target-libada; };
  
! dependencies = { module=all-lto-plugin; on=all-gcc; };
  
  dependencies = { module=configure-mpfr; on=all-gmp; };
  dependencies = { module=configure-mpc; on=all-mpfr; };
--- 362,368 ----
  
  dependencies = { module=all-gnattools; on=all-target-libada; };
  
! dependencies = { module=all-lto-plugin; on=all-libiberty; };
  
  dependencies = { module=configure-mpfr; on=all-gmp; };
  dependencies = { module=configure-mpc; on=all-mpfr; };



More information about the Gcc-patches mailing list