commit a1acf449032c28dd029183afd5ed6241212c727f
Author: Pavel Chupin <pavel.v.chupin@intel.com>
Date:   Tue Dec 25 14:51:24 2012 +0400

    Fix mingw gold build with plugins enabled
    
    Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>

diff --git a/gold/Makefile.am b/gold/Makefile.am
index df8dcb5..0c13c10 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -37,7 +37,7 @@ AM_CPPFLAGS = \
 LIBIBERTY = ../libiberty/libiberty.a
 
 if PLUGINS
-LIBDL = -ldl
+LIBDL = @lt_cv_dlopen_libs@
 endif
 
 if THREADS
diff --git a/gold/aclocal.m4 b/gold/aclocal.m4
index 8321894..9f95f1e 100644
--- a/gold/aclocal.m4
+++ b/gold/aclocal.m4
@@ -989,4 +989,9 @@ m4_include([../config/override.m4])
 m4_include([../config/po.m4])
 m4_include([../config/progtest.m4])
 m4_include([../config/zlib.m4])
+m4_include([../libtool.m4])
+m4_include([../ltoptions.m4])
+m4_include([../ltsugar.m4])
+m4_include([../ltversion.m4])
+m4_include([../lt~obsolete.m4])
 m4_include([../bfd/warning.m4])
diff --git a/gold/configure.ac b/gold/configure.ac
index 9d23835..ae4cc5a 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -290,6 +290,10 @@ AC_PROG_LN_S
 
 AC_GNU_SOURCE
 
+# required when plugins enabled
+LT_INIT([dlopen])
+AC_SUBST(lt_cv_dlopen_libs)
+
 ZW_GNU_GETTEXT_SISTER_DIR
 AM_PO_SUBDIRS
 
@@ -517,6 +521,9 @@ AC_LANG_PUSH(C++)
 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_HEADERS(byteswap.h)
+
+AC_CHECK_HEADERS(windows.h dlfcn.h)
+
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
diff --git a/gold/plugin.cc b/gold/plugin.cc
index c39e11e..93a8ba8 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -29,9 +29,45 @@
 #include <vector>
 
 #ifdef ENABLE_PLUGINS
+#ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
+#elif defined (HAVE_WINDOWS_H)
+#include <windows.h>
+#else
+#error Unknown how to handle dynamic-load-libraries.
 #endif
 
+#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
+
+#define RTLD_NOW 0      /* Dummy value.  */
+static void *
+dlopen (const char *file, int mode ATTRIBUTE_UNUSED)
+{
+  return LoadLibrary (file);
+}
+
+static void *
+dlsym (void *handle, const char *name)
+{
+  return reinterpret_cast<void *>(GetProcAddress (static_cast<HMODULE>(handle), name));
+}
+
+static int ATTRIBUTE_UNUSED
+dlclose (void *handle)
+{
+  FreeLibrary (static_cast<HMODULE>(handle));
+  return 0;
+}
+
+static const char *
+dlerror (void)
+{
+  return "Unable to load DLL.";
+}
+
+#endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */
+#endif /* ENABLE_PLUGINS */
+
 #include "parameters.h"
 #include "errors.h"
 #include "fileread.h"
