aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-05-27 20:53:10 +0000
committerChris Lattner <sabre@nondot.org>2004-05-27 20:53:10 +0000
commit0a576b00b693ccc6a1ef61f42abdef9d5e757018 (patch)
tree034d45997c8565a651038a1fdc78bbd682fe1d1a /lib/Support
parentf0f3c06a90de9cb4687e40014975ecebb6bc6ecc (diff)
downloadexternal_llvm-0a576b00b693ccc6a1ef61f42abdef9d5e757018.zip
external_llvm-0a576b00b693ccc6a1ef61f42abdef9d5e757018.tar.gz
external_llvm-0a576b00b693ccc6a1ef61f42abdef9d5e757018.tar.bz2
Add DynamicLinker support for systems that provide windows.h
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13851 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/DynamicLinker.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/Support/DynamicLinker.cpp b/lib/Support/DynamicLinker.cpp
index 801f93b..cf00bea 100644
--- a/lib/Support/DynamicLinker.cpp
+++ b/lib/Support/DynamicLinker.cpp
@@ -21,6 +21,7 @@
#include "Support/DynamicLinker.h"
#include "Config/dlfcn.h"
+#include "Config/windows.h"
#include <cassert>
using namespace llvm;
@@ -31,6 +32,16 @@ bool llvm::LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
return true;
}
return false;
+#elif defined(HAVE_WINDOWS_H)
+ if (LoadLibrary(filename))
+ return false;
+ if (ErrorMessage) {
+ char Buffer[100];
+ // FIXME: This should use FormatMessage
+ sprintf(Buffer, "Windows error code %d\n", GetLastError());
+ *ErrorMessage = Buffer;
+ }
+ return true;
#else
assert (0 && "Dynamic object linking not implemented for this platform");
#endif
@@ -38,18 +49,22 @@ bool llvm::LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
void *llvm::GetAddressOfSymbol (const char *symbolName) {
#if defined (HAVE_DLOPEN)
-#ifdef RTLD_DEFAULT
- return dlsym (RTLD_DEFAULT, symbolName);
-#else
- static void* CurHandle = dlopen(0, RTLD_LAZY);
- return dlsym(CurHandle, symbolName);
-#endif
+# ifdef RTLD_DEFAULT
+ return dlsym (RTLD_DEFAULT, symbolName);
+# else
+ static void* CurHandle = dlopen(0, RTLD_LAZY);
+ return dlsym(CurHandle, symbolName);
+# endif
+#elif defined(HAVE_WINDOWS_H)
+ static HMODULE ModHandle = NULL;
+ if (ModHandle == 0) ModHandle = GetModuleHandle(NULL);
+ return (void*)GetProcAddress(ModHandle, symbolName);
#else
assert (0 && "Dynamic symbol lookup not implemented for this platform");
#endif
}
// soft, cushiony C++ interface.
-void *llvm::GetAddressOfSymbol (const std::string &symbolName) {
- return GetAddressOfSymbol (symbolName.c_str ());
+void *llvm::GetAddressOfSymbol(const std::string &symbolName) {
+ return GetAddressOfSymbol(symbolName.c_str());
}