+++ /dev/null
-diff -ur gcc-source/config/gcc-plugin.m4 gcc-source/config/gcc-plugin.m4
---- gcc-source/config/gcc-plugin.m4 2014-10-27 13:21:42.000000000 -0400
-+++ gcc-source/config/gcc-plugin.m4 2017-12-07 19:19:35.565953504 -0500
-@@ -19,8 +19,21 @@
- enable_plugin=yes; default_plugin=yes)
-
- pluginlibs=
-+ enable_plugin=yes
-
- case "${host}" in
-+ *-*-mingw*)
-+ # Since plugin support under MinGW is not as straightforward as on
-+ # other platforms (e.g., we have to link import library, etc), we
-+ # only enable it if explicitly requested.
-+ if test x"$default_plugin" = x"yes"; then
-+ enable_plugin=no
-+ elif test x"$enable_plugin" = x"yes"; then
-+ # Use make's target variable to derive import library name.
-+ pluginlibs='-Wl,--export-all-symbols -Wl,--out-implib=[$]@.a'
-+ plugin_check=no
-+ fi
-+ ;;
- *-*-darwin*)
- if test x$build = x$host; then
- export_sym_check="nm${exeext} -g"
-diff -ur gcc-source/gcc/c/Make-lang.in gcc-source/gcc/c/Make-lang.in
---- gcc-source/gcc/c/Make-lang.in 2017-01-01 07:07:43.000000000 -0500
-+++ gcc-source/gcc/c/Make-lang.in 2017-12-07 19:19:35.566114785 -0500
-@@ -125,7 +125,14 @@
-
- c.install-common:
- c.install-man:
--c.install-plugin:
-+
-+c.install-plugin: installdirs
-+# Install import library.
-+ifeq ($(plugin_implib),yes)
-+ $(mkinstalldirs) $(DESTDIR)$(plugin_resourcesdir)
-+ $(INSTALL_DATA) cc1$(exeext).a $(DESTDIR)/$(plugin_resourcesdir)/cc1$(exeext).a
-+endif
-+
- c.uninstall:
-
- #\f
-diff -ur gcc-source/gcc/configure gcc-source/gcc/configure
---- gcc-source/gcc/configure 2017-02-13 03:54:02.000000000 -0500
-+++ gcc-source/gcc/configure 2017-12-07 19:27:50.236774212 -0500
-@@ -29441,9 +29441,22 @@
- fi
-
-
-- pluginlibs=
-+ pluginlibs='-Wl,--export-all-symbols -Wl,--out-implib=[$]@.a'
-+ enable_plugin=yes
-
- case "${host}" in
-+ *-*-mingw*)
-+ # Since plugin support under MinGW is not as straightforward as on
-+ # other platforms (e.g., we have to link import library, etc), we
-+ # only enable it if explicitly requested.
-+ if test x"$default_plugin" = x"yes"; then
-+ enable_plugin=no
-+ elif test x"$enable_plugin" = x"yes"; then
-+ # Use make's target variable to derive import library name.
-+ pluginlibs='-Wl,--export-all-symbols -Wl,--out-implib=$@.a'
-+ plugin_check=no
-+ fi
-+ ;;
- *-*-darwin*)
- if test x$build = x$host; then
- export_sym_check="nm${exeext} -g"
-@@ -29602,6 +29615,9 @@
- LDFLAGS="$saved_LDFLAGS"
- CFLAGS="$saved_CFLAGS"
-
-+ pluginlibs='-Wl,--export-all-symbols -Wl,--out-implib=$@.a'
-+ enable_plugin=yes
-+
- # If plugin support had been requested but not available, fail.
- if test x"$enable_plugin" = x"no" ; then
- if test x"$default_plugin" != x"yes"; then
-diff -ur gcc-source/gcc/cp/Make-lang.in gcc-source/gcc/cp/Make-lang.in
---- gcc-source/gcc/cp/Make-lang.in 2017-01-01 07:07:43.000000000 -0500
-+++ gcc-source/gcc/cp/Make-lang.in 2017-12-07 19:19:35.568049954 -0500
-@@ -230,6 +230,11 @@
- $(mkinstalldirs) $(DESTDIR)$$dir; \
- $(INSTALL_DATA) $$path $(DESTDIR)$$dest; \
- done
-+# Install import library.
-+ifeq ($(plugin_implib),yes)
-+ $(mkinstalldirs) $(DESTDIR)$(plugin_resourcesdir)
-+ $(INSTALL_DATA) cc1plus$(exeext).a $(DESTDIR)/$(plugin_resourcesdir)/cc1plus$(exeext).a
-+endif
-
- c++.uninstall:
- -rm -rf $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext)
-diff -ur gcc-source/gcc/doc/plugins.texi gcc-source/gcc/doc/plugins.texi
---- gcc-source/gcc/doc/plugins.texi 2017-01-01 07:07:43.000000000 -0500
-+++ gcc-source/gcc/doc/plugins.texi 2017-12-07 19:19:35.568231015 -0500
-@@ -34,14 +34,17 @@
- @section Loading Plugins
-
- Plugins are supported on platforms that support @option{-ldl
---rdynamic}. They are loaded by the compiler using @code{dlopen}
--and invoked at pre-determined locations in the compilation
--process.
-+-rdynamic} as well as Windows/MinGW. They are loaded by the compiler
-+using @code{dlopen} or equivalent and invoked at pre-determined
-+locations in the compilation process.
-
- Plugins are loaded with
-
--@option{-fplugin=/path/to/@var{name}.so} @option{-fplugin-arg-@var{name}-@var{key1}[=@var{value1}]}
-+@option{-fplugin=/path/to/@var{name}.@var{ext}} @option{-fplugin-arg-@var{name}-@var{key1}[=@var{value1}]}
-
-+Where @var{name} is the plugin name and @var{ext} is the platform-specific
-+dynamic library extension. It should be @code{dll} on Windows/MinGW,
-+@code{dylib} on Darwin/Mac OS X, and @code{so} on all other platforms.
- The plugin arguments are parsed by GCC and passed to respective
- plugins as key-value pairs. Multiple plugins can be invoked by
- specifying multiple @option{-fplugin} arguments.
-@@ -49,7 +52,7 @@
- A plugin can be simply given by its short name (no dots or
- slashes). When simply passing @option{-fplugin=@var{name}}, the plugin is
- loaded from the @file{plugin} directory, so @option{-fplugin=@var{name}} is
--the same as @option{-fplugin=`gcc -print-file-name=plugin`/@var{name}.so},
-+the same as @option{-fplugin=`gcc -print-file-name=plugin`/@var{name}.@var{ext}},
- using backquote shell syntax to query the @file{plugin} directory.
-
- @node Plugin API
-@@ -508,6 +511,48 @@
- plugin.so}, using backquote shell syntax to query the @file{plugin}
- directory.
-
-+Plugin support on Windows/MinGW has a number of limitations and
-+additional requirements. When building a plugin on Windows we have to
-+link an import library for the corresponding backend executable, for
-+example, @file{cc1.exe}, @file{cc1plus.exe}, etc., in order to gain
-+access to the symbols provided by GCC. This means that on Windows a
-+plugin is language-specific, for example, for C, C++, etc. If you wish
-+to use your plugin with multiple languages, then you will need to
-+build multiple plugin libraries and either instruct your users on how
-+to load the correct version or provide a compiler wrapper that does
-+this automatically.
-+
-+Additionally, on Windows the plugin library has to export the
-+@code{plugin_is_GPL_compatible} and @code{plugin_init} symbols. If you
-+do not wish to modify the source code of your plugin, then you can use
-+the @option{-Wl,--export-all-symbols} option or provide a suitable DEF
-+file. Alternatively, you can export just these two symbols by decorating
-+them with @code{__declspec(dllexport)}, for example:
-+
-+@smallexample
-+#ifdef _WIN32
-+__declspec(dllexport)
-+#endif
-+int plugin_is_GPL_compatible;
-+
-+#ifdef _WIN32
-+__declspec(dllexport)
-+#endif
-+int plugin_init (plugin_name_args *, plugin_gcc_version *)
-+@end smallexample
-+
-+The import libraries are installed into the @code{plugin} directory
-+and their names are derived by appending the @code{.a} extension to
-+the backend executable names, for example, @file{cc1.exe.a},
-+@file{cc1plus.exe.a}, etc. The following command line shows how to
-+build the single source file plugin on Windows to be used with the C++
-+compiler:
-+
-+@smallexample
-+g++ -I`gcc -print-file-name=plugin`/include -shared -Wl,--export-all-symbols \
-+-o plugin.dll plugin.c `gcc -print-file-name=plugin`/cc1plus.exe.a
-+@end smallexample
-+
- When a plugin needs to use @command{gengtype}, be sure that both
- @file{gengtype} and @file{gtype.state} have the same version as the
- GCC for which the plugin is built.
-diff -ur gcc-source/gcc/Makefile.in gcc-source/gcc/Makefile.in
---- gcc-source/gcc/Makefile.in 2017-04-18 14:10:27.000000000 -0400
-+++ gcc-source/gcc/Makefile.in 2017-12-07 19:19:35.568550849 -0500
-@@ -57,6 +57,7 @@
- build=@build@
- host=@host@
- host_noncanonical=@host_noncanonical@
-+host_os=@host_os@
- target=@target@
- target_noncanonical:=@target_noncanonical@
-
-@@ -393,6 +394,11 @@
-
- enable_plugin = @enable_plugin@
-
-+# On MinGW plugin installation involves installing import libraries.
-+ifeq ($(enable_plugin),yes)
-+ plugin_implib := $(if $(strip $(filter mingw%,$(host_os))),yes,no)
-+endif
-+
- enable_host_shared = @enable_host_shared@
-
- enable_as_accelerator = @enable_as_accelerator@
-@@ -2769,11 +2775,15 @@
- $(filter-out $(BUILD_LIBDEPS), $^) $(BUILD_LIBS)
-
- # Generated source files for gengtype. Prepend inclusion of
--# bconfig.h because AIX requires _LARGE_FILES to be defined before
-+# config.h/bconfig.h because AIX requires _LARGE_FILES to be defined before
- # any system header is included.
- gengtype-lex.c : gengtype-lex.l
- -$(FLEX) $(FLEXFLAGS) -o$@ $< && { \
-- echo '#include "bconfig.h"' > $@.tmp; \
-+ echo '#ifdef HOST_GENERATOR_FILE' > $@.tmp; \
-+ echo '#include "config.h"' >> $@.tmp; \
-+ echo '#else' >> $@.tmp; \
-+ echo '#include "bconfig.h"' >> $@.tmp; \
-+ echo '#endif' >> $@.tmp; \
- cat $@ >> $@.tmp; \
- mv $@.tmp $@; \
- }
-diff -ur gcc-source/gcc/plugin.c gcc-source/gcc/plugin.c
---- gcc-source/gcc/plugin.c 2017-03-21 07:50:18.000000000 -0400
-+++ gcc-source/gcc/plugin.c 2017-12-07 19:19:35.568758095 -0500
-@@ -34,6 +34,16 @@
- #include "plugin-version.h"
- #endif
-
-+#ifdef __MINGW32__
-+#ifndef WIN32_LEAN_AND_MEAN
-+#define WIN32_LEAN_AND_MEAN
-+#endif
-+#ifndef NOMINMAX
-+#define NOMINMAX
-+#endif
-+#include <windows.h>
-+#endif
-+
- #define GCC_PLUGIN_STRINGIFY0(X) #X
- #define GCC_PLUGIN_STRINGIFY1(X) GCC_PLUGIN_STRINGIFY0 (X)
-
-@@ -144,7 +154,7 @@
- /* First get the base name part of the full-path name, i.e. NAME.so. */
- char *base_name = xstrdup (lbasename (full_name));
-
-- /* Then get rid of '.so' part of the name. */
-+ /* Then get rid of the extension in the name, e.g., .so. */
- strip_off_ending (base_name, strlen (base_name));
-
- return base_name;
-@@ -175,12 +185,27 @@
- if (name_is_short)
- {
- base_name = CONST_CAST (char*, plugin_name);
-- /* FIXME: the ".so" suffix is currently builtin, since plugins
-- only work on ELF host systems like e.g. Linux or Solaris.
-- When plugins shall be available on non ELF systems such as
-- Windows or MacOS, this code has to be greatly improved. */
-+
-+#if defined(__MINGW32__)
-+ static const char plugin_ext[] = ".dll";
-+#elif defined(__APPLE__)
-+ /* Mac OS has two types of libraries: dynamic libraries (.dylib) and
-+ plugins (.bundle). Both can be used with dlopen()/dlsym() but the
-+ former cannot be linked at build time (i.e., with the -lfoo linker
-+ option). A GCC plugin is therefore probably a Mac OS plugin but their
-+ use seems to be quite rare and the .bundle extension is more of a
-+ recommendation rather than the rule. This raises the questions of how
-+ well they are supported by tools (e.g., libtool). So to avoid
-+ complications let's use the .dylib extension for now. In the future,
-+ if this proves to be an issue, we can always check for both
-+ extensions. */
-+ static const char plugin_ext[] = ".dylib";
-+#else
-+ static const char plugin_ext[] = ".so";
-+#endif
-+
- plugin_name = concat (default_plugin_dir_name (), "/",
-- plugin_name, ".so", NULL);
-+ plugin_name, plugin_ext, NULL);
- if (access (plugin_name, R_OK))
- fatal_error
- (input_location,
-@@ -573,6 +598,85 @@
- }
-
- #ifdef ENABLE_PLUGIN
-+
-+/* Try to initialize PLUGIN. Return true if successful. */
-+
-+#ifdef __MINGW32__
-+
-+// Return a message string for last error or NULL if unknown. Must be freed
-+// with LocalFree().
-+static inline char *
-+win32_error_msg ()
-+{
-+ char *msg;
-+ return FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
-+ FORMAT_MESSAGE_FROM_SYSTEM |
-+ FORMAT_MESSAGE_IGNORE_INSERTS |
-+ FORMAT_MESSAGE_MAX_WIDTH_MASK,
-+ 0,
-+ GetLastError (),
-+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
-+ (char*)&msg,
-+ 0,
-+ 0)
-+ ? msg
-+ : NULL;
-+}
-+
-+static bool
-+try_init_one_plugin (struct plugin_name_args *plugin)
-+{
-+ HMODULE dl_handle;
-+ plugin_init_func plugin_init;
-+
-+ dl_handle = LoadLibrary (plugin->full_name);
-+ if (!dl_handle)
-+ {
-+ char *err = win32_error_msg ();
-+ error ("cannot load plugin %s\n%s", plugin->full_name, err);
-+ LocalFree (err);
-+ return false;
-+ }
-+
-+ /* Check the plugin license. Unlike the name suggests, GetProcAddress()
-+ can be used for both functions and variables. */
-+ if (GetProcAddress (dl_handle, str_license) == NULL)
-+ {
-+ char *err = win32_error_msg ();
-+ fatal_error (input_location,
-+ "plugin %s is not licensed under a GPL-compatible license\n"
-+ "%s", plugin->full_name, err);
-+ }
-+
-+ /* Unlike dlsym(), GetProcAddress() returns a pointer to a function so we
-+ can cast directly without union tricks. */
-+ plugin_init = (plugin_init_func)
-+ GetProcAddress (dl_handle, str_plugin_init_func_name);
-+
-+ if (plugin_init == NULL)
-+ {
-+ char *err = win32_error_msg ();
-+ FreeLibrary (dl_handle);
-+ error ("cannot find %s in plugin %s\n%s", str_plugin_init_func_name,
-+ plugin->full_name, err);
-+ LocalFree (err);
-+ return false;
-+ }
-+
-+ /* Call the plugin-provided initialization routine with the arguments. */
-+ if ((*plugin_init) (plugin, &gcc_version))
-+ {
-+ FreeLibrary (dl_handle);
-+ error ("fail to initialize plugin %s", plugin->full_name);
-+ return false;
-+ }
-+ /* Leak dl_handle on purpose to ensure the plugin is loaded for the
-+ entire run of the compiler. */
-+ return true;
-+}
-+
-+#else // POSIX-like with dlopen()/dlsym().
-+
- /* We need a union to cast dlsym return value to a function pointer
- as ISO C forbids assignment between function pointer and 'void *'.
- Use explicit union instead of __extension__(<union_cast>) for
-@@ -581,8 +685,6 @@
- #define PTR_UNION_AS_VOID_PTR(NAME) (NAME._q)
- #define PTR_UNION_AS_CAST_PTR(NAME) (NAME._nq)
-
--/* Try to initialize PLUGIN. Return true if successful. */
--
- static bool
- try_init_one_plugin (struct plugin_name_args *plugin)
- {
-@@ -631,7 +733,7 @@
-
- return true;
- }
--
-+#endif
-
- /* Routine to dlopen and initialize one plugin. This function is passed to
- (and called by) the hash table traverse routine. Return 1 for the
-diff -ur gcc-source/gcc/system.h gcc-source/gcc/system.h
---- gcc-source/gcc/system.h 2017-03-27 13:53:35.000000000 -0400
-+++ gcc-source/gcc/system.h 2017-12-07 19:19:35.568942044 -0500
-@@ -345,12 +345,8 @@
- # endif
- #endif
-
--#ifdef HAVE_FCNTL_H
--# include <fcntl.h>
--#else
--# ifdef HAVE_SYS_FILE_H
--# include <sys/file.h>
--# endif
-+#ifdef HAVE_SYS_FILE_H
-+# include <sys/file.h>
- #endif
-
- #ifndef SEEK_SET
-@@ -392,10 +388,6 @@
- /* This macro rounds x down to the y boundary. */
- #define ROUND_DOWN(x,y) ((x) & ~((y) - 1))
-
--#ifdef HAVE_SYS_WAIT_H
--#include <sys/wait.h>
--#endif
--
- #ifndef WIFSIGNALED
- #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
- #endif
-@@ -423,10 +415,6 @@
- # define SIGCHLD SIGCLD
- #endif
-
--#ifdef HAVE_SYS_MMAN_H
--# include <sys/mman.h>
--#endif
--
- #ifndef MAP_FAILED
- # define MAP_FAILED ((void *)-1)
- #endif
-@@ -435,14 +423,6 @@
- # define MAP_ANONYMOUS MAP_ANON
- #endif
-
--#ifdef HAVE_SYS_RESOURCE_H
--# include <sys/resource.h>
--#endif
--
--#ifdef HAVE_SYS_TIMES_H
--# include <sys/times.h>
--#endif
--
- /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
- are defined to 0 then we must provide the relevant declaration
- here. These checks will be in the undefined state while configure
-@@ -677,11 +657,6 @@
- # endif
- #endif
-
--#if defined (ENABLE_PLUGIN) && defined (HAVE_DLFCN_H)
--/* If plugin support is enabled, we could use libdl. */
--#include <dlfcn.h>
--#endif
--
- /* Do not introduce a gmp.h dependency on the build system. */
- #ifndef GENERATOR_FILE
- #include <gmp.h>
-Only in gcc-source/: gmp
-diff -ur gcc-source/libcc1/configure gcc-source/libcc1/configure
---- gcc-source/libcc1/configure 2017-01-17 04:38:48.000000000 -0500
-+++ gcc-source/libcc1/configure 2017-12-07 19:19:35.569948636 -0500
-@@ -14552,8 +14552,21 @@
-
-
- pluginlibs=
-+ enable_plugin=yes
-
- case "${host}" in
-+ *-*-mingw*)
-+ # Since plugin support under MinGW is not as straightforward as on
-+ # other platforms (e.g., we have to link import library, etc), we
-+ # only enable it if explicitly requested.
-+ if test x"$default_plugin" = x"yes"; then
-+ enable_plugin=no
-+ elif test x"$enable_plugin" = x"yes"; then
-+ # Use make's target variable to derive import library name.
-+ pluginlibs='-Wl,--export-all-symbols -Wl,--out-implib=$@.a'
-+ plugin_check=no
-+ fi
-+ ;;
- *-*-darwin*)
- if test x$build = x$host; then
- export_sym_check="nm${exeext} -g"
-Only in gcc-source/: mpc
-Only in gcc-source/: mpfr