summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/DynamicLinker.cpp
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2003-10-10 16:55:42 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2003-10-10 16:55:42 +0000
commite2a812447639d3a5ca012834e804ce5320be3ea2 (patch)
treed2976836a656d6208e7a14f5ca3bfa8dca2be285 /llvm/lib/Support/DynamicLinker.cpp
parent8ad183194b8ab69357929187e0aca6079b9714e7 (diff)
downloadbcm5719-llvm-e2a812447639d3a5ca012834e804ce5320be3ea2.tar.gz
bcm5719-llvm-e2a812447639d3a5ca012834e804ce5320be3ea2.zip
Add my abstracted dynamic linker support files.
llvm-svn: 9008
Diffstat (limited to 'llvm/lib/Support/DynamicLinker.cpp')
-rw-r--r--llvm/lib/Support/DynamicLinker.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/lib/Support/DynamicLinker.cpp b/llvm/lib/Support/DynamicLinker.cpp
new file mode 100644
index 00000000000..7c52d3bb5b1
--- /dev/null
+++ b/llvm/lib/Support/DynamicLinker.cpp
@@ -0,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 ());
+}
OpenPOWER on IntegriCloud