finegrainify namespacification
[oota-llvm.git] / lib / Support / DynamicLinker.cpp
index 05a63f3d76216145fed229e40813edc6aabdc524..801f93b5ba38f8467252096d73de994fe4448323 100644 (file)
@@ -22,8 +22,9 @@
 #include "Support/DynamicLinker.h"
 #include "Config/dlfcn.h"
 #include <cassert>
+using namespace llvm;
 
-bool LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
+bool llvm::LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
 #if defined (HAVE_DLOPEN)
   if (dlopen (filename, RTLD_NOW | RTLD_GLOBAL) == 0) {
     if (ErrorMessage) *ErrorMessage = dlerror ();
@@ -35,15 +36,20 @@ bool LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
 #endif
 }
 
-void *GetAddressOfSymbol (const char *symbolName) {
+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
 #else
   assert (0 && "Dynamic symbol lookup not implemented for this platform");
 #endif
 }
 
 // soft, cushiony C++ interface.
-void *GetAddressOfSymbol (const std::string &symbolName) {
+void *llvm::GetAddressOfSymbol (const std::string &symbolName) {
   return GetAddressOfSymbol (symbolName.c_str ());
 }