From 28b516158867c1e9e10efb9f79b94a90f493777a Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 29 Jan 2018 18:06:05 -0800 Subject: [PATCH] Windows LTO: bfd: Search plugin dir for dependencies We need this change to find LLVMgold.dll's libwinpthread-1.dll dependency. The same modification was already applied to the Android gold linker: https://android-review.googlesource.com/c/toolchain/binutils/+/438069. Test: toolchain/gcc/build.py --toolchain aarch64-linux-android \ --host windows64 Test: ./build.py --arch=arm --host win64 Bug: https://github.com/android-ndk/ndk/issues/313 Bug: https://github.com/android-ndk/ndk/issues/632 Change-Id: I0af8716bdc90e2d88954e7790a67da0d47b88c96 --- binutils-2.27/ld/plugin.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/binutils-2.27/ld/plugin.c b/binutils-2.27/ld/plugin.c index 4c161d17..adc8b52c 100644 --- a/binutils-2.27/ld/plugin.c +++ b/binutils-2.27/ld/plugin.c @@ -184,7 +184,11 @@ static const bfd_target * plugin_object_p (bfd *); 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 * @@ -200,9 +204,20 @@ dlclose (void *handle) return 0; } +static const char * +dlerror (void) +{ + 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) */ -#ifndef HAVE_DLFCN_H +#if !defined (HAVE_DLFCN_H) && !defined (HAVE_WINDOWS_H) static const char * dlerror (void) {