Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Improve Windows dlfcn shims.
Browse files Browse the repository at this point in the history
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: android/ndk#313

This change is forward-port of c/438069
  - https://android-review.googlesource.com/#/c/438069
to binutils-2_27-branch.

Change-Id: I66840280cdd7b4176a1ad02f022457bd0336d101
  • Loading branch information
DanAlbert authored and Rahul Chaudhry committed Aug 17, 2017
1 parent 85fafaf commit 89301aa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gold/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -56,7 +60,12 @@ dlsym(void *handle, const char *name)
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) */
Expand Down

0 comments on commit 89301aa

Please sign in to comment.