Improve Windows dlfcn shims.

We can use GetLastError/FormatMessage to get a less useless error
message from dlerror.

Use LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR to search the loaded library's
directory to satisfy dependencies.

Test: toolchain/gcc/build.py --toolchain arm-linux-androideabi \
          --host windows64
Bug: https://github.com/android-ndk/ndk/issues/313

Change-Id: Ia54e75b2ccbb6a4860e1d3e6250468ea053a4ce5
diff --git a/binutils-2.25/gold/plugin.cc b/binutils-2.25/gold/plugin.cc
index 40b3017..0bc71a6 100644
--- a/binutils-2.25/gold/plugin.cc
+++ b/binutils-2.25/gold/plugin.cc
@@ -43,7 +43,11 @@
 static void *
 dlopen(const char *file, int mode ATTRIBUTE_UNUSED)
 {
-  return LoadLibrary(file);
+  // Use LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR to search the loaded library's
+  // directory to satisfy dependencies.
+  return LoadLibraryEx(file, NULL,
+                       LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
+                           LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
 }
 
 static void *
@@ -56,7 +60,12 @@
 static const char *
 dlerror(void)
 {
-  return "unable to load dll";
+  DWORD error = GetLastError();
+  static char error_buf[512];
+  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
+                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_buf,
+                sizeof(error_buf), NULL);
+  return error_buf;
 }
 
 #endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */