Skip to content

Commit

Permalink
Windows LTO: bfd: Search plugin dir for dependencies
Browse files Browse the repository at this point in the history
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: android/ndk#313
Bug: android/ndk#632
Change-Id: I0af8716bdc90e2d88954e7790a67da0d47b88c96
  • Loading branch information
rprichard committed Jan 30, 2018
1 parent 6fa214b commit 28b5161
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions binutils-2.27/ld/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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)
{
Expand Down

0 comments on commit 28b5161

Please sign in to comment.