This is the mail archive of the gcc@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]

[PATCH] Enable linker plugin for windows [was Re: Discussion about merging Go frontend]


On 30/10/2010 11:44, Dave Korn wrote:
> On 29/10/2010 02:31, Ian Lance Taylor wrote:
> 
>> This implements an object file reader/writer which does everything
>> required by LTO and gccgo.  The ELF code works.  I have not tested the
>> Mach-O and COFF code at all beyond compiling it; I hope that somebody
>> else can test those targets and fix them.
>>
>> With this patch, libelf is no longer needed.
> 
>   Almost, but not quite!  The attached patch switches the lto-plugin over to
> use the new objfile reader as well.

>   Bootstrapped and tested all languages except java and ada on
> x86_64-unknown-linux-gnu, no regressions.  There are still a couple of bugs to
> iron out of the COFF-specific part of the objfile reader which I'll have fixed
> later today.
> 
>   OK for trunk (once the objfile changes have gone in)?

  As you'll see elsethread, I fixed the COFF problems.  This is the remaining
chunk of patch required to make the lto-plugin work on cygming targets.

gcc/ChangeLog:

	* gcc.c (PLUGIN_PASSTHROUGH_SPEC): New macro factored out from
	LINK_COMMAND_SPEC.
	(LINK_COMMAND_SPEC): Use it.
	(static_spec_functions[]): Add pass-through-libs entry.
	(pass_through_libs_spec_func): Add related spec function.
	* config/i386/cygming.h (PLUGIN_PASSTHROUGH_SPEC): Define.
	* doc/tm.texi.in (PLUGIN_PASSTHROUGH_SPEC): Document.
	(LINK_COMMAND_SPEC): Mention it.
	* doc/tm.texi: Regenerate.
	* doc/invoke.texi (pass-through-libs): Mention new spec function.

  Taking this for a bootstrap and test cycle now (on top of the objfile
changes).  Assuming no regressions, and one new PASS (the sole LTO test that
exercises -fuse-linker-plugin), and once all the other patches have gone in: OK?

    cheers,
      DaveK

Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi	(revision 166059)
+++ gcc/doc/tm.texi	(working copy)
@@ -406,6 +406,15 @@
 By default this is @code{%G %L %G}.
 @end defmac

+@defmac PLUGIN_PASSTHROUGH_SPEC
+This macro is used as part of @code{LINK_COMMAND_SPEC} when the LTO plugin
+is in use.  It allows the system's standard libraries to be sent to the
+plugin as @option{-pass-through} plugin options, which causes them to be
+added at the end of the link when it may be necessary to resolve new
+undefined references generated as LTO expands builtins from the IR.  The
+default definition should suit ELF platforms.
+@end defmac
+
 @defmac LINK_COMMAND_SPEC
 A C string constant giving the complete command line need to execute the
 linker.  When you do this, you will need to update your port each time a
@@ -413,7 +422,7 @@
 define this macro only if you need to completely redefine the command
 line for invoking the linker and there is no other way to accomplish
 the effect you need.  Overriding this macro may be avoidable by overriding
-@code{LINK_GCC_C_SEQUENCE_SPEC} instead.
+@code{LINK_GCC_C_SEQUENCE_SPEC} and/or @code{PLUGIN_PASSTHROUGH_SPEC} instead.
 @end defmac

 @defmac LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
Index: gcc/doc/tm.texi.in
===================================================================
--- gcc/doc/tm.texi.in	(revision 166059)
+++ gcc/doc/tm.texi.in	(working copy)
@@ -406,6 +406,15 @@
 By default this is @code{%G %L %G}.
 @end defmac

+@defmac PLUGIN_PASSTHROUGH_SPEC
+This macro is used as part of @code{LINK_COMMAND_SPEC} when the LTO plugin
+is in use.  It allows the system's standard libraries to be sent to the
+plugin as @option{-pass-through} plugin options, which causes them to be
+added at the end of the link when it may be necessary to resolve new
+undefined references generated as LTO expands builtins from the IR.  The
+default definition should suit ELF platforms.
+@end defmac
+
 @defmac LINK_COMMAND_SPEC
 A C string constant giving the complete command line need to execute the
 linker.  When you do this, you will need to update your port each time a
@@ -413,7 +422,7 @@
 define this macro only if you need to completely redefine the command
 line for invoking the linker and there is no other way to accomplish
 the effect you need.  Overriding this macro may be avoidable by overriding
-@code{LINK_GCC_C_SEQUENCE_SPEC} instead.
+@code{LINK_GCC_C_SEQUENCE_SPEC} and/or @code{PLUGIN_PASSTHROUGH_SPEC} instead.
 @end defmac

 @defmac LINK_ELIMINATE_DUPLICATE_LDIRECTORIES
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 166059)
+++ gcc/doc/invoke.texi	(working copy)
@@ -9683,6 +9683,17 @@
 %:remove-outfile(-lm)
 @end smallexample

+@item @code{pass-through-libs}
+The @code{pass-through-libs} spec function takes any number of arguments.  It
+finds any @option{-l} options and any non-options (which it assumes are the
+names of linker input files) and returns a result containing all the found
+arguments each prepended by @option{-plugin-opt=-pass-through=} and joined by
+spaces.  This list is intended to be passed to the LTO linker plugin.
+
+@smallexample
+%:pass-through-libs(%G %L %G)
+@end smallexample
+
 @item @code{print-asm-header}
 The @code{print-asm-header} function takes no arguments and simply
 prints a banner like:
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 166059)
+++ gcc/gcc.c	(working copy)
@@ -287,6 +287,7 @@
 static const char *compare_debug_dump_opt_spec_function (int, const char **);
 static const char *compare_debug_self_opt_spec_function (int, const char **);
 static const char *compare_debug_auxbase_opt_spec_function (int, const char **);
+static const char *pass_through_libs_spec_func (int, const char **);
 
 /* The Specs Language

@@ -531,6 +532,14 @@
 #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
 #endif

+/* config.h can define PLUGIN_PASSTHROUGH_SPEC to control which
+   libraries are passed through to the final link by the lto-plugin.  */
+#ifndef PLUGIN_PASSTHROUGH_SPEC
+#define PLUGIN_PASSTHROUGH_SPEC " \
+  %{static|static-libgcc:-plugin-opt=-pass-through=%(lto_libgcc)} \
+  %{static:-plugin-opt=-pass-through=-lc} "
+#endif
+
 /* mudflap specs */
 #ifndef MFWRAP_SPEC
 /* XXX: valid only for GNU ld */
@@ -658,10 +667,8 @@
     %{fuse-linker-plugin: \
     -plugin %(linker_plugin_file) \
     -plugin-opt=%(lto_wrapper) \
-    -plugin-opt=-fresolution=%u.res \
-    %{static|static-libgcc:-plugin-opt=-pass-through=%(lto_libgcc)}	\
-    %{static:-plugin-opt=-pass-through=-lc}	\
-    } \
+    -plugin-opt=-fresolution=%u.res " \
+    PLUGIN_PASSTHROUGH_SPEC " } \
     %{flto:%<fcompare-debug*} %{fwhopr*:%<fcompare-debug*} \
     %{flto} %{fwhopr*} %l " LINK_PIE_SPEC \
    "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\
@@ -1244,6 +1251,7 @@
   { "compare-debug-dump-opt",	compare_debug_dump_opt_spec_function },
   { "compare-debug-self-opt",	compare_debug_self_opt_spec_function },
   { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function },
+  { "pass-through-libs",	pass_through_libs_spec_func },
 #ifdef EXTRA_SPEC_FUNCTIONS
   EXTRA_SPEC_FUNCTIONS
 #endif
@@ -8216,3 +8224,33 @@

   return name;
 }
+
+/* %:pass-through-libs spec function.  Finds all -l options and input
+   file names in the lib spec passed to it, and makes a list of them
+   prepended with the plugin option to cause them to be passed through
+   to the final link after all the new object files have been added.  */
+
+const char *
+pass_through_libs_spec_func (int argc, const char **argv)
+{
+  char *prepended = xstrdup (" ");
+  int n;
+  /* Shlemiel the painter's algorithm.  Innately horrible, but at least
+     we know that there will never be more than a handful of strings to
+     concat, and it's only once per run, so it's not worth optimising.  */
+  for (n = 0; n < argc; n++)
+    {
+    char *old = prepended;
+      /* Anything that isn't an option is a full path to an output
+         file; pass it through if it ends in '.a'.  Among options,
+	 pass only -l.  */
+      if (argv[n][0] == '-'
+		? argv[n][1] == 'l'
+		: !strcmp (".a", argv[n] + strlen (argv[n]) - 2))
+	prepended = concat (prepended, "-plugin-opt=-pass-through=",
+		argv[n], " ", NULL);
+      if (prepended != old)
+	free (old);
+    }
+  return prepended;
+}
Index: gcc/config/i386/cygming.h
===================================================================
--- gcc/config/i386/cygming.h	(revision 166059)
+++ gcc/config/i386/cygming.h	(working copy)
@@ -142,6 +142,8 @@
 #define SUBTARGET_EXTRA_SPECS						\
   { "mingw_include_path", DEFAULT_TARGET_MACHINE }

+#define PLUGIN_PASSTHROUGH_SPEC " %:pass-through-libs(%o %G %L %G) "
+
 #undef MATH_LIBRARY
 #define MATH_LIBRARY ""


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