[llvm-commits] CVS: llvm/lib/Support/DynamicLinker.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Fri Oct 10 11:56:09 PDT 2003


Changes in directory llvm/lib/Support:

DynamicLinker.cpp added (r1.1)

---
Log message:

Add my abstracted dynamic linker support files.


---
Diffs of the changes:  (+42 -0)

Index: llvm/lib/Support/DynamicLinker.cpp
diff -c /dev/null llvm/lib/Support/DynamicLinker.cpp:1.1
*** /dev/null	Fri Oct 10 11:55:52 2003
--- llvm/lib/Support/DynamicLinker.cpp	Fri Oct 10 11:55:42 2003
***************
*** 0 ****
--- 1,42 ----
+ //===-- DynamicLinker.cpp - Implement DynamicLinker interface -------------===//
+ //
+ // Lightweight interface to dynamic library linking and loading, and dynamic
+ // symbol lookup functionality, in whatever form the operating system
+ // provides it.
+ //
+ // Possible future extensions include support for the HPUX shl_load()
+ // interface, the Mac OS X NSLinkModule() interface, and the Windows
+ // LoadLibrary() interface.
+ //
+ // Note that we assume that if dlopen() is available, then dlsym() is too.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include "Support/DynamicLinker.h"
+ #include "Config/dlfcn.h"
+ #include <cassert>
+ 
+ bool LinkDynamicObject (const char *filename, std::string *ErrorMessage) {
+ #if defined (HAVE_DLOPEN)
+   if (dlopen (filename, RTLD_NOW | RTLD_GLOBAL) == 0) {
+     if (ErrorMessage) *ErrorMessage = dlerror ();
+     return true;
+   }
+   return false;
+ #else
+   assert (0 && "Dynamic object linking not implemented for this platform");
+ #endif
+ }
+ 
+ void *GetAddressOfSymbol (const char *symbolName) {
+ #if defined (HAVE_DLOPEN)
+   return dlsym (RTLD_DEFAULT, symbolName);
+ #else
+   assert (0 && "Dynamic symbol lookup not implemented for this platform");
+ #endif
+ }
+ 
+ // soft, cushiony C++ interface.
+ void *GetAddressOfSymbol (const std::string &symbolName) {
+   return GetAddressOfSymbol (symbolName.c_str ());
+ }





More information about the llvm-commits mailing list